This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /*************************************************************************************/ |
||
3 | /* This file is part of the Thelia package. */ |
||
4 | /* */ |
||
5 | /* Copyright (c) OpenStudio */ |
||
6 | /* email : [email protected] */ |
||
7 | /* web : http://www.thelia.net */ |
||
8 | /* */ |
||
9 | /* For the full copyright and license information, please view the LICENSE.txt */ |
||
10 | /* file that was distributed with this source code. */ |
||
11 | /*************************************************************************************/ |
||
12 | /*************************************************************************************/ |
||
13 | |||
14 | namespace Dealer\Service; |
||
15 | |||
16 | use Dealer\Event\DealerEvents; |
||
17 | use Dealer\Event\DealerSchedulesEvent; |
||
18 | use Dealer\Model\DealerShedules; |
||
19 | use Dealer\Model\DealerShedulesQuery; |
||
20 | use Dealer\Model\Map\DealerShedulesTableMap; |
||
21 | use Dealer\Service\Base\AbstractBaseService; |
||
22 | use Dealer\Service\Base\BaseServiceInterface; |
||
23 | use Propel\Runtime\ActiveQuery\Criteria; |
||
24 | use Symfony\Component\EventDispatcher\Event; |
||
25 | |||
26 | /** |
||
27 | * Class SchedulesService |
||
28 | * @package Dealer\Service |
||
29 | */ |
||
30 | class SchedulesService extends AbstractBaseService implements BaseServiceInterface |
||
31 | { |
||
32 | const MAX_DAYS_SEARCH = 30; |
||
33 | |||
34 | const EVENT_CREATE = DealerEvents::DEALER_SCHEDULES_CREATE; |
||
35 | const EVENT_CREATE_BEFORE = DealerEvents::DEALER_SCHEDULES_CREATE_BEFORE; |
||
36 | const EVENT_CREATE_AFTER = DealerEvents::DEALER_SCHEDULES_CREATE_AFTER; |
||
37 | const EVENT_DELETE = DealerEvents::DEALER_SCHEDULES_DELETE; |
||
38 | const EVENT_DELETE_BEFORE = DealerEvents::DEALER_SCHEDULES_DELETE_BEFORE; |
||
39 | const EVENT_DELETE_AFTER = DealerEvents::DEALER_SCHEDULES_DELETE_AFTER; |
||
40 | const EVENT_UPDATE = DealerEvents::DEALER_SCHEDULES_UPDATE; |
||
41 | const EVENT_UPDATE_BEFORE = DealerEvents::DEALER_SCHEDULES_UPDATE_BEFORE; |
||
42 | const EVENT_UPDATE_AFTER = DealerEvents::DEALER_SCHEDULES_UPDATE_AFTER; |
||
43 | |||
44 | protected function createProcess(Event $event) |
||
45 | { |
||
46 | $event->getDealerSchedules()->save(); |
||
47 | } |
||
48 | |||
49 | protected function updateProcess(Event $event) |
||
50 | { |
||
51 | $event->getDealerSchedules()->save(); |
||
52 | } |
||
53 | |||
54 | protected function deleteProcess(Event $event) |
||
55 | { |
||
56 | $event->getDealerSchedules()->delete(); |
||
57 | } |
||
58 | |||
59 | public function createFromArray($data, $locale = null) |
||
60 | { |
||
61 | $dealer_schedules = $this->hydrateObjectArray($data, $locale); |
||
62 | |||
63 | $event = new DealerSchedulesEvent(); |
||
64 | $event->setDealerSchedules($dealer_schedules); |
||
65 | |||
66 | $this->create($event); |
||
67 | |||
68 | return $event->getDealerSchedules(); |
||
69 | } |
||
70 | |||
71 | public function cloneFromArray($data) |
||
72 | { |
||
73 | $dealer_schedules = $this->hydrateObjectArray($data); |
||
74 | $clone = $dealer_schedules->copy(); |
||
75 | |||
76 | $event = new DealerSchedulesEvent(); |
||
77 | $event->setDealerSchedules($clone); |
||
78 | |||
79 | $this->create($event); |
||
80 | |||
81 | return $event->getDealerSchedules(); |
||
82 | } |
||
83 | |||
84 | public function updateFromArray($data, $locale = null) |
||
85 | { |
||
86 | $dealer_schedules = $this->hydrateObjectArray($data, $locale); |
||
87 | |||
88 | $event = new DealerSchedulesEvent(); |
||
89 | $event->setDealerSchedules($dealer_schedules); |
||
90 | |||
91 | $this->update($event); |
||
92 | |||
93 | return $event->getDealerSchedules(); |
||
94 | } |
||
95 | |||
96 | public function deleteFromId($id) |
||
97 | { |
||
98 | $dealer = DealerShedulesQuery::create()->findOneById($id); |
||
99 | |||
100 | if ($dealer) { |
||
101 | $event = new DealerSchedulesEvent(); |
||
102 | $event->setDealerSchedules($dealer); |
||
103 | |||
104 | $this->delete($event); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | protected function hydrateObjectArray($data, $locale = null) |
||
0 ignored issues
–
show
|
|||
109 | { |
||
110 | $model = new DealerShedules(); |
||
111 | |||
112 | if (isset($data['id'])) { |
||
113 | $dealer = DealerShedulesQuery::create()->findOneById($data['id']); |
||
114 | if ($dealer) { |
||
115 | $model = $dealer; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | // Require Field |
||
120 | if (array_key_exists('day', $data) && $data['day'] !== array()) { |
||
121 | $model->setDay($data['day']); |
||
122 | } |
||
123 | if (isset($data['begin'])) { |
||
124 | $model->setBegin($data['begin']); |
||
125 | } |
||
126 | if (isset($data['end'])) { |
||
127 | $model->setEnd($data['end']); |
||
128 | } |
||
129 | if (isset($data['period_begin'])) { |
||
130 | $model->setPeriodBegin($data['period_begin']); |
||
131 | } |
||
132 | if (isset($data['period_end'])) { |
||
133 | $model->setPeriodEnd($data['period_end']); |
||
134 | } |
||
135 | if (isset($data['dealer_id'])) { |
||
136 | $model->setDealerId($data['dealer_id']); |
||
137 | } |
||
138 | if (isset($data['closed'])) { |
||
139 | $model->setClosed($data['closed']); |
||
140 | } |
||
141 | |||
142 | |||
143 | return $model; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @param $idDealer |
||
148 | * @param $dateStart |
||
149 | * @param $numberMaxDays |
||
150 | * @param bool $hardOnly |
||
151 | * @return array |
||
152 | * @throws \Propel\Runtime\Exception\PropelException |
||
153 | */ |
||
154 | public function getOpenDays($idDealer, $dateStart, $numberMaxDays, $hardOnly = false) |
||
155 | { |
||
156 | $days = []; |
||
157 | $i = 0; |
||
158 | |||
159 | while ($i < self::MAX_DAYS_SEARCH && count($days) < $numberMaxDays) { |
||
160 | |||
161 | |||
162 | if (null !== $day = $this->findOpenDay($idDealer, $dateStart)) { |
||
163 | $day['hardHours'] = $this->findHardHours($idDealer, $day['num_day'], $day['date'], $hardOnly); |
||
164 | $day['hours'] = $this->findOpenHours($idDealer, $day['num_day'], $day['date'], $day['hardHours']); |
||
165 | $days[] = $day; |
||
166 | } |
||
167 | $dateStart->add(new \DateInterval('P1D')); |
||
168 | $i++; |
||
169 | } |
||
170 | return $days; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * @param $idDealer |
||
175 | * @param $dateDay |
||
176 | * @return array|null |
||
177 | * @throws \Propel\Runtime\Exception\PropelException |
||
178 | */ |
||
179 | public function findOpenDay($idDealer, $dateDay) |
||
180 | { |
||
181 | $numDay = $dateDay->format('N') - 1; |
||
182 | |||
183 | DealerShedulesTableMap::clearInstancePool(); |
||
184 | |||
185 | // Recherche des ouverture classique pour un jour donné |
||
186 | $shedules = DealerShedulesQuery::create() |
||
187 | ->filterByDealerId($idDealer) |
||
188 | ->filterByDay($numDay) |
||
189 | ->filterByPeriodNull() |
||
190 | ->filterByClosed(0) |
||
191 | ->find(); |
||
192 | |||
193 | $days = $shedules->getData(); |
||
194 | |||
195 | if (count($days) > 0) { |
||
196 | DealerShedulesTableMap::clearInstancePool(); |
||
197 | // Recherche des fermetures exeptionnelles pour un jour donné et une date donnée |
||
198 | $shedulesClosed = DealerShedulesQuery::create() |
||
199 | ->filterByDealerId($idDealer) |
||
200 | ->filterByDay($numDay) |
||
201 | ->filterByClosed(1) |
||
202 | ->filterByPeriodBegin($dateDay, Criteria::LESS_EQUAL) |
||
203 | ->filterByPeriodEnd($dateDay, Criteria::GREATER_EQUAL) |
||
204 | ->find(); |
||
205 | |||
206 | $daysclosed = $shedulesClosed->getData(); |
||
207 | |||
208 | if (count($daysclosed) == 0) { |
||
209 | return [ |
||
210 | 'date' => $dateDay->format('Y-m-d'), |
||
211 | 'day' => $dateDay->format('l'), |
||
212 | 'num_day' => $dateDay->format('N') - 1 |
||
213 | ]; |
||
214 | } |
||
215 | |||
216 | //on calcule le nombre d'heure dispo par rapport au nombre d'heure prevu |
||
217 | $cptHourClassic = 0; |
||
218 | $cptHourExep = 0; |
||
219 | /** @var DealerShedules $shedule */ |
||
220 | foreach ($shedules as $shedule) { |
||
221 | $tot = date_diff($shedule->getEnd(), $shedule->getBegin()); |
||
222 | |||
223 | $cptHourClassic += $tot->format('%h'); |
||
224 | } |
||
225 | /** @var DealerShedules $daysclose */ |
||
226 | foreach ($daysclosed as $daysclose) { |
||
227 | $tot = date_diff($daysclose->getEnd(), $daysclose->getBegin()); |
||
228 | |||
229 | $cptHourExep += $tot->format('%h'); |
||
230 | } |
||
231 | if ($cptHourExep < $cptHourClassic) { |
||
232 | return [ |
||
233 | 'date' => $dateDay->format('Y-m-d'), |
||
234 | 'day' => $dateDay->format('l'), |
||
235 | 'num_day' => $dateDay->format('N') - 1 |
||
236 | ]; |
||
237 | } |
||
238 | return null; |
||
239 | } |
||
240 | |||
241 | DealerShedulesTableMap::clearInstancePool(); |
||
242 | // Recherche des ouvertures exeptionnelles pour un jour donné et une date donnée |
||
243 | $shedulesOpen = DealerShedulesQuery::create() |
||
244 | ->filterByDealerId($idDealer) |
||
245 | ->filterByDay($numDay) |
||
246 | ->filterByClosed(0) |
||
247 | ->filterByPeriodBegin($dateDay, Criteria::LESS_EQUAL) |
||
248 | ->filterByPeriodEnd($dateDay, Criteria::GREATER_EQUAL) |
||
249 | ->find(); |
||
250 | |||
251 | $daysOpen = $shedulesOpen->getData(); |
||
252 | |||
253 | if (0 != count($daysOpen)) { |
||
254 | //une ouverture a été trouvée on prend le jour en question |
||
255 | return [ |
||
256 | 'date' => $dateDay->format('Y-m-d'), |
||
257 | 'day' => $dateDay->format('l'), |
||
258 | 'num_day' => $dateDay->format('N') - 1 |
||
259 | ]; |
||
260 | } |
||
261 | return null; |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * @param $idDealer |
||
266 | * @param $numDay |
||
267 | * @param null $date |
||
268 | * @param bool $harOnly |
||
269 | * @return array |
||
270 | * @throws \Propel\Runtime\Exception\PropelException |
||
271 | */ |
||
272 | public function findHardHours($idDealer, $numDay, $date = null, $harOnly = false) |
||
273 | { |
||
274 | DealerShedulesTableMap::clearInstancePool(); |
||
275 | |||
276 | $shedulesHardDay = DealerShedulesQuery::create() |
||
277 | ->filterByDealerId($idDealer) |
||
278 | ->filterByDay($numDay) |
||
279 | ->filterByPeriodBegin(null) |
||
280 | ->filterByPeriodEnd(null) |
||
281 | ->find(); |
||
282 | |||
283 | $tabHardHours = []; |
||
284 | |||
285 | /** @var DealerShedules $range */ |
||
286 | foreach ($shedulesHardDay->getData() as $range) { |
||
287 | $h = $range->getBegin(); |
||
288 | while ($h <= $range->getEnd()) { |
||
289 | $tabHardHours[] = $h->format('H:i:s'); |
||
290 | $h->add(new \DateInterval('PT1H')); |
||
291 | } |
||
292 | } |
||
293 | |||
294 | if ($harOnly === false && $date !== null) { |
||
295 | DealerShedulesTableMap::clearInstancePool(); |
||
296 | $shedulesExpt = DealerShedulesQuery::create() |
||
297 | ->filterByDealerId($idDealer) |
||
298 | ->filterByDay($numDay) |
||
299 | ->filterByClosed(0) |
||
300 | ->filterByPeriodBegin($date, Criteria::LESS_EQUAL) |
||
301 | ->filterByPeriodEnd($date, Criteria::GREATER_EQUAL) |
||
302 | ->find(); |
||
303 | |||
304 | /** @var DealerShedules $sheduleExpt */ |
||
305 | foreach ($shedulesExpt as $sheduleExpt) { |
||
306 | $h = $sheduleExpt->getBegin(); |
||
307 | while ($h <= $sheduleExpt->getEnd()) { |
||
308 | $htemp = $h->format('H:i:s'); |
||
309 | if (!in_array($htemp, $tabHardHours)) { |
||
310 | $tabHardHours[] = $htemp; |
||
311 | } |
||
312 | $h->add(new \DateInterval('PT1H')); |
||
313 | } |
||
314 | } |
||
315 | } |
||
316 | |||
317 | return $tabHardHours; |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @param $idDealer |
||
322 | * @param $numDay |
||
323 | * @param $date |
||
324 | * @param null $delay |
||
0 ignored issues
–
show
There is no parameter named
$delay . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
325 | * @return array |
||
326 | * @throws \Propel\Runtime\Exception\PropelException |
||
327 | */ |
||
328 | public |
||
329 | function findOpenHours( |
||
330 | $idDealer, |
||
331 | $numDay, |
||
332 | $date, |
||
333 | $hardHours |
||
334 | ) { |
||
335 | DealerShedulesTableMap::clearInstancePool(); |
||
336 | |||
337 | $shedulesExpt = DealerShedulesQuery::create() |
||
338 | ->filterByDealerId($idDealer) |
||
339 | ->filterByDay($numDay) |
||
340 | ->filterByPeriodBegin($date, Criteria::LESS_EQUAL) |
||
341 | ->filterByPeriodEnd($date, Criteria::GREATER_EQUAL) |
||
342 | ->find(); |
||
343 | |||
344 | $excludeHours = []; |
||
345 | $exeptionOpenHour = []; |
||
346 | |||
347 | /** @var DealerShedules $sheduleExpt */ |
||
348 | foreach ($shedulesExpt as $sheduleExpt) { |
||
349 | |||
350 | $h = $sheduleExpt->getBegin(); |
||
351 | while ($h <= $sheduleExpt->getEnd()) { |
||
352 | if (!$sheduleExpt->getClosed()) { |
||
353 | $exeptionOpenHour[] = $h->format('H:i:s'); |
||
354 | } else { |
||
355 | $excludeHours[] = $h->format('H:i:s'); |
||
356 | } |
||
357 | $h->add(new \DateInterval('PT1H')); |
||
358 | } |
||
359 | } |
||
360 | |||
361 | $tabHours = []; |
||
362 | |||
363 | /** @var DealerShedules $range */ |
||
364 | foreach ($hardHours as $h) { |
||
365 | if (!in_array($h, $excludeHours)) { |
||
366 | $tabHours[] = $h; |
||
367 | } |
||
368 | } |
||
369 | |||
370 | foreach ($exeptionOpenHour as $openHour) { |
||
371 | if (!in_array($openHour, $tabHours)) { |
||
372 | $tabHours[] = $openHour; |
||
373 | } |
||
374 | } |
||
375 | |||
376 | sort($tabHours); |
||
377 | |||
378 | return $tabHours; |
||
379 | } |
||
380 | } |
||
381 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.