Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
TermineUtils | |
0.00% |
0 / 43 |
|
0.00% |
0 / 2 |
132 | |
0.00% |
0 / 1 |
updateTerminFromSolvEvent | |
0.00% |
0 / 42 |
|
0.00% |
0 / 1 |
110 | |||
fromEnv | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Olz\Termine\Utils; |
4 | |
5 | use Olz\Entity\SolvEvent; |
6 | use Olz\Entity\Termine\Termin; |
7 | use Olz\Utils\WithUtilsTrait; |
8 | |
9 | class TermineUtils { |
10 | use WithUtilsTrait; |
11 | |
12 | public function updateTerminFromSolvEvent(Termin $termin, ?SolvEvent $solv_event_arg = null): void { |
13 | $solv_id = $termin->getSolvId(); |
14 | if (!$solv_id) { |
15 | $this->log()->warning("Update termin {$termin->getId()} from SOLV: no SOLV ID."); |
16 | return; |
17 | } |
18 | $solv_event = $solv_event_arg; |
19 | if ($solv_event_arg === null) { |
20 | $solv_event_repo = $this->entityManager()->getRepository(SolvEvent::class); |
21 | $solv_event = $solv_event_repo->findOneBy(['solv_uid' => $solv_id]); |
22 | } else { |
23 | if ($solv_id !== $solv_event_arg->getSolvUid()) { |
24 | $this->log()->warning("Update termin {$termin->getId()} from SOLV: SOLV ID mismatch ({$solv_id} vs. {$solv_event_arg->getSolvUid()})."); |
25 | return; |
26 | } |
27 | } |
28 | $this->generalUtils()->checkNotNull($solv_event, "No SolvEvent for termin update"); |
29 | |
30 | $duration_days = $solv_event->getDuration() - 1; |
31 | $duration = \DateInterval::createFromDateString("{$duration_days} days"); |
32 | if (!$duration) { |
33 | $this->log()->warning("Invalid date interval: {$duration_days} days"); |
34 | return; |
35 | } |
36 | $end_date = (clone $solv_event->getDate())->add($duration); |
37 | $deadline = $solv_event->getDeadline() |
38 | ? (clone $solv_event->getDeadline())->setTime(23, 59, 59) : null; |
39 | $link = $solv_event->getLink() ?: '-'; |
40 | $club = $solv_event->getClub() ?: '-'; |
41 | $map = $solv_event->getMap() ?: '-'; |
42 | $location = $solv_event->getLocation() ?: '-'; |
43 | $text = <<<ZZZZZZZZZZ |
44 | Link: {$link} |
45 | |
46 | Organisator: {$club} |
47 | |
48 | Karte: {$map} |
49 | |
50 | Ort: {$location} |
51 | ZZZZZZZZZZ; |
52 | |
53 | $termin->setStartDate($solv_event->getDate()); |
54 | $termin->setStartTime(null); |
55 | $termin->setEndDate($end_date); |
56 | $termin->setEndTime(null); |
57 | $termin->setDeadline($deadline); |
58 | $termin->setTitle($solv_event->getName()); |
59 | $termin->setText($text); |
60 | $termin->setNewsletter(false); // TODO: Enable Newsletter for SOLV Termine |
61 | $termin->setLocation(null); |
62 | $termin->setCoordinateX($solv_event->getCoordX()); |
63 | $termin->setCoordinateY($solv_event->getCoordY()); |
64 | $this->log()->info("Termin {$termin->getId()} updated from SOLV."); |
65 | } |
66 | |
67 | public static function fromEnv(): self { |
68 | return new self(); |
69 | } |
70 | } |