PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
← All changes | admin/helpers/critical_dates.php +47 -48 1.7.2 → 1.8.16 View file →
@@ -12,9 +12,9 @@
12 12
13 13 /**
14 14 * Critical Dates handler class for Vik Booking.
15 15 *
16 - * @since 1.13.5
16 + * @since 1.13.5 (J) - 1.3.5 (WP)
17 17 */
18 18 class VikBookingCriticalDates
19 19 {
20 20 /**
@@ -29,11 +29,9 @@
29 29 *
30 30 * @see getInstance()
31 31 */
32 32 protected function __construct()
33 - {
34 -
35 - }
33 + {}
36 34
37 35 /**
38 36 * Returns the global Critical Dates object, either
39 37 * a new instance or the existing instance
@@ -56,9 +54,9 @@
56 54 * @param string $ymd the date string in Y-m-d format.
57 55 * @param int $idroom the ID of the room involved.
58 56 * @param int $subunit the index of the sub-unit (0 by default).
59 57 * @param string $key the key name of the note.
60 - * @param boolean $get whether to get the found record.
58 + * @param bool $get whether to get the found record.
61 59 *
62 60 * @return mixed True/array if festivity exists, false otherwise.
63 61 */
64 62 public function dayNoteExists($ymd, $idroom, $subunit = 0, $key = '', $get = false)
@@ -67,21 +65,21 @@
67 65 $idroom = intval($idroom);
68 66 $subunit = intval($subunit);
69 67
70 68 $dbo = JFactory::getDbo();
71 - $q = "SELECT * FROM `#__vikbooking_critical_dates` WHERE `dt`=" . $dbo->quote($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit};";
69 +
70 + $q = "SELECT * FROM `#__vikbooking_critical_dates` WHERE `dt`=" . $dbo->q($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit};";
72 71 $dbo->setQuery($q);
73 - $dbo->execute();
74 - if (!$dbo->getNumRows()) {
72 + $note = $dbo->loadAssoc();
73 + if (!$note) {
75 74 return false;
76 75 }
77 - $note = $dbo->loadAssoc();
78 -
76 +
79 77 $notes_info = json_decode($note['info']);
80 78 if (!$notes_info) {
81 79 return false;
82 80 }
83 -
81 +
84 82 // update this information in the array in case it needs to be returned
85 83 $note['info'] = $notes_info;
86 84
87 85 // seek for the requested note
@@ -89,8 +87,9 @@
89 87 if (empty($key) || (!empty($n->type) && $n->type == $key)) {
90 88 return $get ? $note : true;
91 89 }
92 90 }
91 +
93 92 return false;
94 93 }
95 94
96 95 /**
@@ -101,9 +100,9 @@
101 100 * @param string $ymd the date string in Y-m-d format.
102 101 * @param int $idroom the ID of the room involved.
103 102 * @param int $subunit the index of the sub-unit (0 by default).
104 103 *
105 - * @return boolean True if the new record is stored or updated, false otherwise.
104 + * @return bool True if the new record is stored or updated, false otherwise.
106 105 */
107 106 public function storeDayNote($note, $ymd, $idroom = 0, $subunit = 0)
108 107 {
109 108 // vars validation
@@ -108,17 +107,20 @@
108 107 {
109 108 // vars validation
110 109 $idroom = intval($idroom);
111 110 $subunit = intval($subunit);
112 - if (!is_array($note) || !count($note) || (empty($note['name']) && empty($note['descr']))) {
111 + if (!is_array($note) || (empty($note['name']) && empty($note['descr']))) {
113 112 return false;
114 113 }
114 +
115 115 if (!isset($note['type'])) {
116 116 $note['type'] = 'custom';
117 117 }
118 +
118 119 if (!isset($note['ts'])) {
119 120 $note['ts'] = time();
120 121 }
122 +
121 123 if (!empty($note['name'])) {
122 124 // make sure the "name" does not contain commas, which may be used by JS as separator in the readable notes data attribute
123 125 $note['name'] = trim(str_replace(',', '', $note['name']));
124 126 }
@@ -123,29 +125,29 @@
123 125 $note['name'] = trim(str_replace(',', '', $note['name']));
124 126 }
125 127
126 128 $dbo = JFactory::getDbo();
127 - $q = "SELECT * FROM `#__vikbooking_critical_dates` WHERE `dt`=" .$dbo->quote($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit}";
129 +
130 + $q = "SELECT * FROM `#__vikbooking_critical_dates` WHERE `dt`=" .$dbo->q($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit}";
128 131 $dbo->setQuery($q);
129 - $dbo->execute();
130 - if (!$dbo->getNumRows()) {
132 + $prevNote = $dbo->loadAssoc();
133 + if (!$prevNote) {
131 134 // create a new record
132 - $q = "INSERT INTO `#__vikbooking_critical_dates` (`dt`, `idroom`, `subunit`, `info`) VALUES (".$dbo->quote($ymd).", ".$dbo->quote($idroom).", ".$dbo->quote($subunit).", ".$dbo->quote(json_encode(array($note))).");";
135 + $q = "INSERT INTO `#__vikbooking_critical_dates` (`dt`, `idroom`, `subunit`, `info`) VALUES (".$dbo->q($ymd).", ".$dbo->q($idroom).", ".$dbo->q($subunit).", ".$dbo->q(json_encode(array($note))).");";
133 136 $dbo->setQuery($q);
134 137 $dbo->execute();
135 138
136 - return ((int)$dbo->insertid() > 0);
139 + return (bool) ((int) $dbo->insertid());
137 140 }
138 141
139 142 // update current record by pushing the note into the existing info array of objects
140 - $notes = $dbo->loadAssoc();
141 - $notes_arr = json_decode($notes['info']);
142 - array_push($notes_arr, (object)$note);
143 - $q = "UPDATE `#__vikbooking_critical_dates` SET `info`=".$dbo->quote(json_encode($notes_arr))." WHERE `id`={$notes['id']};";
143 + $notes_arr = json_decode($prevNote['info']);
144 + array_push($notes_arr, (object) $prevNote);
145 + $q = "UPDATE `#__vikbooking_critical_dates` SET `info`=".$dbo->q(json_encode($notes_arr))." WHERE `id`={$prevNote['id']};";
144 146 $dbo->setQuery($q);
145 147 $dbo->execute();
146 148
147 - return ((int)$dbo->getAffectedRows() > 0);
149 + return (bool) ((int) $dbo->getAffectedRows());
148 150 }
149 151
150 152 /**
151 153 * Deletes a specific note for the given date, room ID and subunit.
@@ -157,9 +159,9 @@
157 159 * @param int $idroom the room ID involved.
158 160 * @param int $subunit the subunit of the room ID.
159 161 * @param string $type the key name of the note ('custom' for manual entries).
160 162 *
161 - * @return boolean True if the fest is removed, false otherwise.
163 + * @return bool True if the fest is removed, false otherwise.
162 164 */
163 165 public function deleteDayNote($index, $ymd, $idroom = 0, $subunit = 0, $type = 'custom')
164 166 {
165 167 $record = $this->dayNoteExists($ymd, $idroom, $subunit, $type, true);
@@ -191,11 +193,11 @@
191 193 }
192 194
193 195 $dbo = JFactory::getDbo();
194 196 if ($drop_record) {
195 - $q = "DELETE FROM `#__vikbooking_critical_dates` WHERE `dt`=" . $dbo->quote($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit}";
197 + $q = "DELETE FROM `#__vikbooking_critical_dates` WHERE `dt`=" . $dbo->q($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit}";
196 198 } else {
197 - $q = "UPDATE `#__vikbooking_critical_dates` SET `info`=".$dbo->quote(json_encode($record['info']))." WHERE `dt`=" . $dbo->quote($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit}";
199 + $q = "UPDATE `#__vikbooking_critical_dates` SET `info`=".$dbo->q(json_encode($record['info']))." WHERE `dt`=" . $dbo->q($ymd) . " AND `idroom`={$idroom} AND `subunit`={$subunit}";
198 200 }
199 201 $dbo->setQuery($q);
200 202 $dbo->execute();
201 203
@@ -205,52 +207,49 @@
205 207 /**
206 208 * Loads the room day notes of any type and returns and associative
207 209 * array indexed by date with decoded notes information.
208 210 *
209 - * @param string $from_ymd the optional minimum date in Y-m-d (defaults to today).
210 - * @param string $to_ymd the optional maximum date in Y-m-d (defaults to none).
211 - * @param int $idroom the optional room id filter
212 - * @param int $subunit the optional room index filter
211 + * @param string $from_ymd Optional minimum date in Y-m-d (defaults to today).
212 + * @param string $to_ymd Optional maximum date in Y-m-d (defaults to none).
213 + * @param int $idroom Optional room id filter.
214 + * @param int $subunit Optional room index filter.
213 215 *
214 - * @return array the list of festivities found in Vik Booking.
216 + * @return array the list of festivities found in VikBooking.
215 217 */
216 218 public function loadRoomDayNotes($from_ymd = null, $to_ymd = null, $idroom = null, $subunit = null)
217 219 {
218 220 $dbo = JFactory::getDbo();
219 221
220 - $rdnotes = array();
222 + $rdnotes = [];
223 +
221 224 if (empty($from_ymd)) {
222 225 $from_ymd = date('Y-m-d');
223 226 }
224 227
225 - $clauses = array();
226 - array_push($clauses, "`dt`>=" . $dbo->quote($from_ymd));
228 + $clauses = [];
229 + array_push($clauses, "`dt` >= " . $dbo->q($from_ymd));
227 230
228 231 if (!empty($to_ymd)) {
229 - array_push($clauses, "`dt`<=" . $dbo->quote($to_ymd));
232 + array_push($clauses, "`dt` <= " . $dbo->q($to_ymd));
230 233 }
231 234 if ($idroom !== null && is_int($idroom)) {
232 - array_push($clauses, "`idroom`=" . (int)$idroom);
235 + array_push($clauses, "`idroom`=" . (int) $idroom);
233 236 }
234 237 if ($subunit !== null && is_int($subunit)) {
235 - array_push($clauses, "`subunit`=" . (int)$subunit);
238 + array_push($clauses, "`subunit`=" . (int) $subunit);
236 239 }
237 240
238 241 $q = "SELECT * FROM `#__vikbooking_critical_dates` WHERE " . implode(' AND ', $clauses) . " ORDER BY `dt` ASC;";
239 242 $dbo->setQuery($q);
240 - $dbo->execute();
241 - if ($dbo->getNumRows()) {
242 - $all_notes = $dbo->loadAssocList();
243 - // make sure to decode all notes infos
244 - foreach ($all_notes as $k => $v) {
245 - $v['info'] = json_decode($v['info']);
243 + $all_notes = $dbo->loadAssocList();
246 244
247 - $keyid = $v['dt'] . '_' . (int)$v['idroom'] . '_' . (int)$v['subunit'];
248 -
249 - $rdnotes[$keyid] = $v;
250 - }
245 + // make sure to decode all notes infos
246 + foreach ($all_notes as $k => $v) {
247 + $v['info'] = json_decode($v['info']);
248 + $keyid = $v['dt'] . '_' . ((int) $v['idroom']) . '_' . ((int) $v['subunit']);
249 + // set room-day note
250 + $rdnotes[$keyid] = $v;
251 251 }
252 252
253 253 return $rdnotes;
254 254 }
255 -
256 255 }