| @@ -9,28 +9,51 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | defined('ABSPATH') or die('No script kiddies please!'); |
| 12 | 12 | |
| 13 | +/** | |
| 14 | + * Helper class to invoke the Channel Manager update requests. | |
| 15 | + */ | |
| 13 | 16 | class VboVcmInvoker |
| 14 | 17 | { |
| 15 | - public $oids; | |
| 16 | - public $orig_statuses; | |
| 17 | - public $sync_type; | |
| 18 | + /** | |
| 19 | + * @var array | |
| 20 | + */ | |
| 21 | + public $oids = []; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * @var array | |
| 25 | + */ | |
| 26 | + public $orig_statuses = []; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @var string | |
| 30 | + */ | |
| 31 | + public $sync_type = 'new'; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * @var array | |
| 35 | + */ | |
| 18 | 36 | public $orig_booking; |
| 19 | - private $error; | |
| 20 | - private $result; | |
| 21 | - | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * @var string | |
| 40 | + */ | |
| 41 | + private $error = ''; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @var bool | |
| 45 | + */ | |
| 46 | + private $result = false; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Class constructor will attempt to require a class from VCM. | |
| 50 | + */ | |
| 22 | 51 | public function __construct() |
| 23 | 52 | { |
| 24 | - $this->oids = array(); | |
| 25 | - $this->orig_statuses = array(); | |
| 26 | - $this->sync_type = 'new'; | |
| 27 | - $this->orig_booking = ''; | |
| 28 | 53 | if (!class_exists('synchVikBooking')) { |
| 29 | 54 | require_once(VCM_SITE_PATH . DIRECTORY_SEPARATOR . "helpers" . DIRECTORY_SEPARATOR . "synch.vikbooking.php"); |
| 30 | 55 | } |
| 31 | - $this->error = ''; | |
| 32 | - $this->result = false; | |
| 33 | 56 | } |
| 34 | 57 | |
| 35 | 58 | /** |
| 36 | 59 | * Sets the booking IDs for the sync |
| @@ -78,9 +101,9 @@ | ||
| 78 | 101 | return $this; |
| 79 | 102 | } |
| 80 | 103 | |
| 81 | 104 | if (is_scalar($orig_statuses)) { |
| 82 | - $orig_statuses = array($orig_statuses); | |
| 105 | + $orig_statuses = [$orig_statuses]; | |
| 83 | 106 | } |
| 84 | 107 | |
| 85 | 108 | if (!is_array($orig_statuses)) { |
| 86 | 109 | return $this; |
| @@ -100,9 +123,9 @@ | ||
| 100 | 123 | public function setOriginalBooking($obooking, $decode = false) |
| 101 | 124 | { |
| 102 | 125 | if (!empty($obooking)) { |
| 103 | 126 | $original_booking = $decode === true ? json_decode(urldecode($obooking), true) : $obooking; |
| 104 | - if (is_array($original_booking) && @count($original_booking) > 0) { | |
| 127 | + if (is_array($original_booking) && $original_booking) { | |
| 105 | 128 | $this->orig_booking = $original_booking; |
| 106 | 129 | } |
| 107 | 130 | } |
| 108 | 131 | return $this; |
| @@ -112,9 +135,9 @@ | ||
| 112 | 135 | * Launch the synchronization with VCM |
| 113 | 136 | */ |
| 114 | 137 | public function doSync() |
| 115 | 138 | { |
| 116 | - if (!is_array($this->oids) || !count($this->oids)) { | |
| 139 | + if (!is_array($this->oids) || !$this->oids) { | |
| 117 | 140 | $this->setError('oids is empty.'); |
| 118 | 141 | return $this->result; |
| 119 | 142 | } |
| 120 | 143 | |
| @@ -137,9 +160,8 @@ | ||
| 137 | 160 | */ |
| 138 | 161 | if (!empty($this->orig_statuses[$okey]) && method_exists($vcm, 'setBookingPreviousStatus')) { |
| 139 | 162 | $vcm->setBookingPreviousStatus($this->orig_statuses[$okey]); |
| 140 | 163 | } |
| 141 | - // | |
| 142 | 164 | |
| 143 | 165 | $rq_rs = $vcm->sendRequest(); |
| 144 | 166 | $this->result = $this->result || $rq_rs ? true : $this->result; |
| 145 | 167 | } |
| @@ -144,9 +166,9 @@ | ||
| 144 | 166 | $this->result = $this->result || $rq_rs ? true : $this->result; |
| 145 | 167 | } |
| 146 | 168 | } elseif ($this->sync_type == 'modify') { |
| 147 | 169 | // only one Booking ID per request as the original booking is transmitted in JSON format or as an array if called via PHP execution. |
| 148 | - if (is_array($this->orig_booking) && count($this->orig_booking)) { | |
| 170 | + if (is_array($this->orig_booking) && $this->orig_booking) { | |
| 149 | 171 | foreach ($this->oids as $okey => $oid) { |
| 150 | 172 | if (empty($oid)) { |
| 151 | 173 | continue; |
| 152 | 174 | } |
| @@ -165,15 +187,15 @@ | ||
| 165 | 187 | continue; |
| 166 | 188 | } |
| 167 | 189 | $vcm = new SynchVikBooking($oid); |
| 168 | 190 | $vcm->setSkipCheckAutoSync(); |
| 169 | - $vcm->setFromCancellation(array('id' => $oid)); | |
| 191 | + $vcm->setFromCancellation(['id' => $oid]); | |
| 170 | 192 | $rq_rs = $vcm->sendRequest(); |
| 171 | 193 | $this->result = $this->result || $rq_rs ? true : $this->result; |
| 172 | 194 | } |
| 173 | 195 | } |
| 174 | 196 | |
| 175 | - if ($this->result !== true && !(strlen($this->getError()) > 0)) { | |
| 197 | + if ($this->result !== true && !$this->getError()) { | |
| 176 | 198 | $this->setError('VCM returned errors'); |
| 177 | 199 | } |
| 178 | 200 | |
| 179 | 201 | return $this->result; |
| @@ -185,9 +207,9 @@ | ||
| 185 | 207 | * @param string $err_str |
| 186 | 208 | */ |
| 187 | 209 | private function setError($err_str) |
| 188 | 210 | { |
| 189 | - $this->error .= $err_str; | |
| 211 | + $this->error .= (string)$err_str; | |
| 190 | 212 | } |
| 191 | 213 | |
| 192 | 214 | /** |
| 193 | 215 | * Returns the class error variable |
| @@ -195,6 +217,5 @@ | ||
| 195 | 217 | public function getError() |
| 196 | 218 | { |
| 197 | 219 | return $this->error; |
| 198 | 220 | } |
| 199 | - | |
| 200 | 221 | } |