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/src/report/loader.php +58 -6 1.6.4 → 1.8.16 View file →
@@ -95,9 +95,9 @@
95 95 * Trigger event to let other plugins register additional driver full paths.
96 96 *
97 97 * @since 1.16.0 (J) - 1.6.0 (WP)
98 98 */
99 - $list = JFactory::getApplication()->triggerEvent('onLoadPmsReports');
99 + $list = VBOFactory::getPlatform()->getDispatcher()->filter('onLoadPmsReports');
100 100 foreach ($list as $chunk) {
101 101 // merge default driver files with the returned ones
102 102 $report_files = array_merge($report_files, (array)$chunk);
103 103 }
@@ -123,11 +123,21 @@
123 123 unset($report_files[$k]);
124 124 continue;
125 125 }
126 126
127 + // instantiate the report object
128 + $reportInstance = new $classname;
129 +
130 + // ensure the report is compatible with the current environment
131 + if ($reportInstance->preflight() === false) {
132 + // exclude non-compatible report
133 + unset($report_files[$k]);
134 + continue;
135 + }
136 +
127 137 if ($report_file == 'revenue' && $this->global_reports) {
128 138 // make the "revenue" the first element of the list
129 - array_unshift($this->global_reports, new $classname);
139 + array_unshift($this->global_reports, $reportInstance);
130 140 } elseif (strpos($report_file, 'istat') !== false || strpos($report_file, 'polizia') !== false) {
131 141 // this is a country (italy) specific report so we push it to a separate array
132 142 $country_key = 'IT';
133 143 if (!isset($this->country_reports[$country_key])) {
@@ -132,9 +142,9 @@
132 142 $country_key = 'IT';
133 143 if (!isset($this->country_reports[$country_key])) {
134 144 $this->country_reports[$country_key] = [];
135 145 }
136 - $this->country_reports[$country_key][] = new $classname;
146 + $this->country_reports[$country_key][] = $reportInstance;
137 147 } elseif (substr($report_file, 2, 1) == '_') {
138 148 // this is probably a country specific report so we push it to a separate array (two-letter country code + underscore in file name)
139 149 $country_key = strtoupper(substr($report_file, 0, 2));
140 150 if (!isset($this->country_reports[$country_key])) {
@@ -139,12 +149,12 @@
139 149 $country_key = strtoupper(substr($report_file, 0, 2));
140 150 if (!isset($this->country_reports[$country_key])) {
141 151 $this->country_reports[$country_key] = [];
142 152 }
143 - $this->country_reports[$country_key][] = new $classname;
153 + $this->country_reports[$country_key][] = $reportInstance;
144 154 } else {
145 155 // push this object as a global report
146 - $this->global_reports[] = new $classname;
156 + $this->global_reports[] = $reportInstance;
147 157 }
148 158 }
149 159
150 160 // get countries information for the reports
@@ -153,12 +163,54 @@
153 163 // check whether some country specific reports truly belong to a country
154 164 foreach ($this->country_reports as $ckey => $cvalue) {
155 165 if (!isset($countries[$ckey])) {
156 166 // this country does not exist, so maybe the report file was given a short beginning name. Push it to the global reports array
157 - unset($countries[$ckey]);
167 + unset($this->country_reports[$ckey]);
158 168 $this->global_reports = array_merge($this->global_reports, $cvalue);
159 169 }
160 170 }
171 +
172 + /**
173 + * Apply sorting based on most advanced PMS reports supporting electronic transmission.
174 + *
175 + * @since 1.17.2 (J) - 1.7.2 (WP)
176 + */
177 + foreach ($this->country_reports as $ckey => &$creports) {
178 + // apply sorting by priority and then by name
179 + usort($creports, function($a, $b) use ($ckey) {
180 + // calculate the priority based on electronic transmission functions
181 + $a_reflection = new ReflectionMethod($a, 'getScopedActions');
182 + $a_priority = (int) ($a_reflection->getDeclaringClass()->getName() === get_class($a));
183 + $b_reflection = new ReflectionMethod($b, 'getScopedActions');
184 + $b_priority = (int) ($b_reflection->getDeclaringClass()->getName() === get_class($b));
185 +
186 + // technical priority
187 + $tech_priority = $b_priority - $a_priority;
188 +
189 + if ($tech_priority !== 0) {
190 + // the higher the priority is, the higher the position will be
191 + return $tech_priority;
192 + }
193 +
194 + // get report names
195 + $a_name = $a->getName();
196 + $b_name = $b->getName();
197 +
198 + if ($ckey === 'IT') {
199 + // static priority to Police related reports
200 + $police_priority = (int) stripos($b_name, 'poli') - (int) stripos($a_name, 'poli');
201 + if ($police_priority !== 0) {
202 + // sort by authority
203 + return $police_priority;
204 + }
205 + }
206 +
207 + // sort by report name
208 + return strcasecmp($a_name, $b_name);
209 + });
210 + }
211 + // unset last reference
212 + unset($creports);
161 213
162 214 // return the list of drivers
163 215 return [$this->global_reports, $this->country_reports];
164 216 }