PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / webhook / classes / statuschangepackageorder.php
vikappointments / site / helpers / libraries / webhook / classes Last commit date
afterdeletecoupon.php 1 month ago afterdeletecustomer.php 1 month ago afterdeleteemployee.php 1 month ago afterdeletepackorder.php 1 month ago afterdeletereservation.php 1 month ago afterdeleteservice.php 1 month ago aftersavecoupon.php 1 month ago aftersavecustomer.php 1 month ago aftersaveemployee.php 1 month ago aftersavepackorder.php 1 month ago aftersavereservation.php 1 month ago aftersaveservice.php 1 month ago index.html 1 month ago statuschangepackageorder.php 1 month ago statuschangereservation.php 1 month ago
statuschangepackageorder.php
151 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Web hook handler for packages status change.
16 *
17 * @since 1.7
18 */
19 class VAPWebHookStatusChangePackageorder extends VAPWebHook
20 {
21 /**
22 * @override
23 * Class constructor.
24 *
25 * @param string $hook The hook name.
26 * @param mixed $payload The payload to deliver.
27 */
28 public function __construct($hook, $payload)
29 {
30 if (is_array($payload))
31 {
32 // The payload is an array containing the properties of the saved
33 // order status, and an array of options. We need to use only the
34 // first argument of the list.
35 $payload = array_shift($payload);
36 }
37
38 // construct through parent
39 parent::__construct('onStatusChangePackageorder', $payload);
40 }
41
42 /**
43 * @override
44 * Returns a readable name of the hook.
45 *
46 * @return string
47 */
48 public function getName()
49 {
50 return JText::translate('VAP_WEBHOOK_STATUSCHANGE_PACKORDER');
51 }
52
53 /**
54 * @override
55 * Returns an associative array of supported parameters.
56 *
57 * @return array
58 */
59 public function getForm()
60 {
61 return array(
62 /**
63 * A list of statuses to observe. The web hook will be
64 * dispatched only in case the status changed is contained
65 * within this list. Leave empty to accept all the statuses.
66 *
67 * @var list
68 */
69 'statuses' => array(
70 'type' => 'select',
71 'label' => JText::translate('VAP_WEBHOOK_STATUSES_PARAM'),
72 'help' => JText::translate('VAP_WEBHOOK_STATUSES_PARAM_HELP'),
73 'default' => array(),
74 'multiple' => true,
75 'options' => JHtml::fetch('vaphtml.admin.statuscodes', 'packages'),
76 ),
77
78 /**
79 * Choose the loading mode of the records:
80 * - basic send only the specified data;
81 * - full send the whole table row;
82 * - extended send an extended version of the row.
83 *
84 * @var list
85 */
86 'load' => array(
87 'type' => 'select',
88 'label' => JText::translate('VAP_WEBHOOK_LOAD_PARAM'),
89 'help' => JText::translate('VAP_WEBHOOK_LOAD_PARAM_HELP'),
90 'default' => 'basic',
91 'options' => array(
92 'basic' => JText::translate('VAP_WEBHOOK_LOAD_PARAM_BASIC'),
93 'full' => JText::translate('VAP_WEBHOOK_LOAD_PARAM_FULL'),
94 'extended' => JText::translate('VAP_WEBHOOK_LOAD_PARAM_EXTENDED'),
95 ),
96 ),
97 );
98 }
99
100 /**
101 * @override
102 * Returns the registered payload.
103 *
104 * @param mixed $options Either an array or an object, which should contain
105 * the value of the specified parameters.
106 *
107 * @return mixed
108 */
109 public function getPayload($options = array())
110 {
111 $options = new JRegistry($options);
112 // fetch loading mode
113 $load = $options->get('load');
114 // get statuses
115 $statuses = (array) $options->get('statuses');
116
117 $payload = (array) $this->payload;
118
119 if ($statuses && !in_array($payload['status'], $statuses))
120 {
121 // this status is not observed
122 return false;
123 }
124
125 if (!empty($payload['id_order']))
126 {
127 if ($load == 'full')
128 {
129 // get all details of the package order table
130 $payload = JModelVAP::getInstance('packorder')->getItem($payload['id_order']);
131 }
132 else if ($load == 'extended')
133 {
134 // load the extended version of the order details
135 VAPLoader::import('libraries.order.factory');
136 $payload = VAPOrderFactory::getPackages($payload['id_order'], VikAppointments::getDefaultLanguage());
137 }
138 else
139 {
140 // strip unset properties
141 $payload = array_filter($payload, function($value)
142 {
143 return $value !== null;
144 });
145 }
146 }
147
148 return $payload;
149 }
150 }
151