| 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 "returning customer". |
| 15 |
* |
| 16 |
* @since 1.4.0 |
| 17 |
*/ |
| 18 |
class VikBookingConditionalRuleReturningCustomer 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('VBO_CONDTEXT_RULE_RETCUST'); |
| 29 |
$this->ruleDescr = JText::translate('VBO_CONDTEXT_RULE_RETCUST_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 |
?> |
| 41 |
<div class="vbo-param-container"> |
| 42 |
<div class="vbo-param-label"><?php echo JText::translate('VBO_CONDTEXT_RULE_RETCUST'); ?></div> |
| 43 |
<div class="vbo-param-setting"> |
| 44 |
<?php echo $this->vbo_app->printYesNoButtons($this->inputName('returning'), JText::translate('VBYES'), JText::translate('VBNO'), (int)$this->getParam('returning', 0), 1, 0); ?> |
| 45 |
</div> |
| 46 |
</div> |
| 47 |
<?php |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Tells whether the rule is compliant. |
| 52 |
* |
| 53 |
* @return bool True on success, false otherwise. |
| 54 |
*/ |
| 55 |
public function isCompliant() |
| 56 |
{ |
| 57 |
$returning = (bool)$this->getParam('returning', 0); |
| 58 |
if (!$returning) { |
| 59 |
return true; |
| 60 |
} |
| 61 |
|
| 62 |
$book_id = $this->getPropVal('booking', 'id', ''); |
| 63 |
if (empty($book_id)) { |
| 64 |
return true; |
| 65 |
} |
| 66 |
|
| 67 |
$cpin = VikBooking::getCPinIstance(); |
| 68 |
$customer = $cpin->getCustomerFromBooking($book_id); |
| 69 |
if (!is_array($customer) || !count($customer)) { |
| 70 |
// customer not found |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
$dbo = JFactory::getDbo(); |
| 75 |
$q = "SELECT `co`.`idcustomer`, `co`.`idorder`, `o`.`id` FROM `#__vikbooking_customers_orders` AS `co` LEFT JOIN `#__vikbooking_orders` AS `o` ON `co`.`idorder`=`o`.`id` WHERE `co`.`idcustomer`=" . $customer['id'] . " AND `o`.`status`='confirmed';"; |
| 76 |
$dbo->setQuery($q); |
| 77 |
$dbo->execute(); |
| 78 |
|
| 79 |
// we need at least two confirmed orders |
| 80 |
return ($dbo->getNumRows() > 1); |
| 81 |
} |
| 82 |
|
| 83 |
} |
| 84 |
|