← All changes
|
admin/helpers/conditionalrules/payment_methods.php
+109
-0
1.6.1
→
1.8.16
View file →
| @@ -1,0 +1,109 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package VikBooking | |
| 4 | + * @subpackage com_vikbooking | |
| 5 | + * @author Alessio Gaggii - e4j - Extensionsforjoomla.com | |
| 6 | + * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved. | |
| 7 | + * @license GNU General Public License version 2 or later; see LICENSE | |
| 8 | + * @link https://vikwp.com | |
| 9 | + */ | |
| 10 | + | |
| 11 | +defined('ABSPATH') or die('No script kiddies please!'); | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * Class handler for conditional rule "payment_methods". | |
| 15 | + * | |
| 16 | + * @since 1.4.0 | |
| 17 | + */ | |
| 18 | +class VikBookingConditionalRulePaymentMethods extends VikBookingConditionalRule | |
| 19 | +{ | |
| 20 | + /** | |
| 21 | + * Class constructor will define the rule name, description and identifier. | |
| 22 | + */ | |
| 23 | + public function __construct() | |
| 24 | + { | |
| 25 | + // call parent constructor | |
| 26 | + parent::__construct(); | |
| 27 | + | |
| 28 | + $this->ruleName = JText::translate('VBMENUTENEIGHT'); | |
| 29 | + $this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_PAYM_DESCR'); | |
| 30 | + $this->ruleId = basename(__FILE__); | |
| 31 | + } | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Displays the rule parameters. | |
| 35 | + * | |
| 36 | + * @return void | |
| 37 | + */ | |
| 38 | + public function renderParams() | |
| 39 | + { | |
| 40 | + $this->vbo_app->loadSelect2(); | |
| 41 | + $payments = $this->loadPaymentMethods(); | |
| 42 | + $current_payments = $this->getParam('payments', array()); | |
| 43 | + ?> | |
| 44 | + <div class="vbo-param-container"> | |
| 45 | + <div class="vbo-param-label"><?php echo JText::translate('VBMENUTENEIGHT'); ?></div> | |
| 46 | + <div class="vbo-param-setting"> | |
| 47 | + <select name="<?php echo $this->inputName('payments', true); ?>" id="<?php echo $this->inputID('payments'); ?>" multiple="multiple"> | |
| 48 | + <?php | |
| 49 | + foreach ($payments as $pdata) { | |
| 50 | + ?> | |
| 51 | + <option value="<?php echo $pdata['id']; ?>"<?php echo is_array($current_payments) && in_array($pdata['id'], $current_payments) ? ' selected="selected"' : ''; ?>><?php echo $pdata['name']; ?></option> | |
| 52 | + <?php | |
| 53 | + } | |
| 54 | + ?> | |
| 55 | + </select> | |
| 56 | + </div> | |
| 57 | + </div> | |
| 58 | + | |
| 59 | + <script type="text/javascript"> | |
| 60 | + jQuery(function() { | |
| 61 | + jQuery('#<?php echo $this->inputID('payments'); ?>').select2(); | |
| 62 | + }); | |
| 63 | + </script> | |
| 64 | + <?php | |
| 65 | + } | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * Tells whether the rule is compliant. | |
| 69 | + * | |
| 70 | + * @return bool True on success, false otherwise. | |
| 71 | + */ | |
| 72 | + public function isCompliant() | |
| 73 | + { | |
| 74 | + $payment = $this->getPropVal('booking', 'idpayment'); | |
| 75 | + if (empty($payment)) { | |
| 76 | + return false; | |
| 77 | + } | |
| 78 | + $exppay = explode('=', $payment); | |
| 79 | + $payment_info = VikBooking::getPayment($exppay[0]); | |
| 80 | + if (!is_array($payment_info)) { | |
| 81 | + return false; | |
| 82 | + } | |
| 83 | + | |
| 84 | + $payments = $this->getParam('payments', array()); | |
| 85 | + | |
| 86 | + return in_array($payment_info['id'], $payments); | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Internal function for this rule only. | |
| 91 | + * | |
| 92 | + * @return array | |
| 93 | + */ | |
| 94 | + protected function loadPaymentMethods() | |
| 95 | + { | |
| 96 | + $payments = array(); | |
| 97 | + | |
| 98 | + $dbo = JFactory::getDbo(); | |
| 99 | + $q = "SELECT `id`, `name` FROM `#__vikbooking_gpayments` ORDER BY `name` ASC;"; | |
| 100 | + $dbo->setQuery($q); | |
| 101 | + $dbo->execute(); | |
| 102 | + if ($dbo->getNumRows()) { | |
| 103 | + $payments = $dbo->loadAssocList(); | |
| 104 | + } | |
| 105 | + | |
| 106 | + return $payments; | |
| 107 | + } | |
| 108 | + | |
| 109 | +} | |