| 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 "request payment". |
| 15 |
* |
| 16 |
* @since 1.17.2 (J) - 1.7.2 (WP) |
| 17 |
*/ |
| 18 |
class VikBookingConditionalRuleRequestPayment 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_AMOUNT_PAYABLE_RQ'); |
| 29 |
$this->ruleDescr = sprintf('%s (%s)', JText::translate('VBO_AMOUNT_PAYABLE_RQ'), JText::translate('VBO_AMOUNT_PAYABLE')); |
| 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_AMOUNT_PAYABLE_RQ'); ?></div> |
| 43 |
<div class="vbo-param-setting"> |
| 44 |
<?php echo $this->vbo_app->printYesNoButtons($this->inputName('has_amount_payable'), JText::translate('VBYES'), JText::translate('VBNO'), (int)$this->getParam('has_amount_payable', 0), 1, 0); ?> |
| 45 |
<span class="vbo-param-setting-comment">Use the tag <strong onclick="vboCtrRequestPaymentAddContentEditor('{payment_requested_amount}');" style="cursor: pointer;">{payment_requested_amount}</strong> if you would like to display the actual <i>amount payable</i> in your text.</span> |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
|
| 49 |
<script type="text/javascript"> |
| 50 |
function vboCtrRequestPaymentAddContentEditor(str) { |
| 51 |
if (!str) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
try { |
| 56 |
// "msg" is the name of the WYSIWYG editor of the conditional text |
| 57 |
Joomla.editors.instances.msg.replaceSelection(str); |
| 58 |
} catch(e) { |
| 59 |
// do nothing |
| 60 |
} |
| 61 |
} |
| 62 |
</script> |
| 63 |
<?php |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Tells whether the rule is compliant. |
| 68 |
* |
| 69 |
* @return bool True on success, false otherwise. |
| 70 |
*/ |
| 71 |
public function isCompliant() |
| 72 |
{ |
| 73 |
$has_amount_payable = (bool)$this->getParam('has_amount_payable', 0); |
| 74 |
if (!$has_amount_payable) { |
| 75 |
return true; |
| 76 |
} |
| 77 |
|
| 78 |
return $this->getPropVal('booking', 'payable', 0) > 0; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Allows to manipulate the message of the conditional text with dynamic contents. |
| 83 |
* |
| 84 |
* @override |
| 85 |
* |
| 86 |
* @param string $msg the current conditional text message. |
| 87 |
* |
| 88 |
* @return string the manipulated conditional text message. |
| 89 |
*/ |
| 90 |
public function manipulateMessage($msg) |
| 91 |
{ |
| 92 |
// check if the special and internal tag was used |
| 93 |
if (strpos($msg, '{payment_requested_amount}') !== false) { |
| 94 |
// build the amount payable string |
| 95 |
$amout_payable_str = sprintf('%s %s', VikBooking::getCurrencySymb(), VikBooking::numberFormat($this->getPropVal('booking', 'payable', 0))); |
| 96 |
|
| 97 |
// exact placeholder tag found, so use the plain mark string |
| 98 |
$msg = str_replace('{payment_requested_amount}', $amout_payable_str, $msg); |
| 99 |
} |
| 100 |
|
| 101 |
// return the eventually manipulated message |
| 102 |
return $msg; |
| 103 |
} |
| 104 |
} |
| 105 |
|