Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
74.44% covered (warning)
74.44%
67 / 90
69.57% covered (warning)
69.57%
48 / 69
CRAP
0.00% covered (danger)
0.00%
0 / 1
Termin
74.44% covered (warning)
74.44%
67 / 90
69.57% covered (warning)
69.57%
48 / 69
165.39
0.00% covered (danger)
0.00%
0 / 1
 id
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFromTemplate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFromTemplate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStartDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setStartDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStartTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setStartTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEndDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEndDate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEndTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEndTime
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDeadline
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDeadline
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getShouldPromote
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setShouldPromote
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getText
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setText
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDocumentation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setDocumentation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLabels
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 removeLabel
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 clearLabels
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSolvId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSolvId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLatitude
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLatitude
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLongitude
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLongitude
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLocation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLocation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getNewsletter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setNewsletter
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getParentTermin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setParentTermin
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getImageIds
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
3.14
 setImageIds
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 getOrganizerUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setOrganizerUser
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getParticipantsRegistration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setParticipantsRegistration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNumParticipants
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setNumParticipants
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMinParticipants
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setMinParticipants
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMaxParticipants
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setMaxParticipants
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getVolunteersRegistration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setVolunteersRegistration
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNumVolunteers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setNumVolunteers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMinVolunteers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setMinVolunteers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getMaxVolunteers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setMaxVolunteers
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 testOnlyGetField
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdFieldNameForSearch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getIdForSearch
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTitleForSearch
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCriteriaForFilter
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getCriteriaForQuery
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
 parseSearchDateRange
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getEntityNameForStorage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEntityIdForStorage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Olz\Entity\Termine;
4
5use Doctrine\Common\Collections\ArrayCollection;
6use Doctrine\Common\Collections\Collection;
7use Doctrine\Common\Collections\Criteria;
8use Doctrine\Common\Collections\Expr\Expression;
9use Doctrine\ORM\Mapping as ORM;
10use Olz\Common\Utils\DateUtils;
11use Olz\Common\Utils\WithUtilsCache;
12use Olz\Entity\Anmelden\Registration;
13use Olz\Entity\Common\DataStorageInterface;
14use Olz\Entity\Common\DataStorageTrait;
15use Olz\Entity\Common\OlzEntity;
16use Olz\Entity\Common\SearchableInterface;
17use Olz\Entity\Common\TestableInterface;
18use Olz\Entity\Users\User;
19use Olz\Repository\Termine\TerminRepository;
20
21#[ORM\Table(name: 'termine')]
22#[ORM\Index(name: 'start_date_index', columns: ['start_date'])]
23#[ORM\Entity(repositoryClass: TerminRepository::class)]
24class Termin extends OlzEntity implements DataStorageInterface, SearchableInterface, TestableInterface {
25    use DataStorageTrait;
26
27    #[ORM\Id]
28    #[ORM\Column(type: 'integer', nullable: false)]
29    #[ORM\GeneratedValue]
30    private int $id;
31
32    #[ORM\ManyToOne(targetEntity: TerminTemplate::class)]
33    #[ORM\JoinColumn(name: 'from_template_id', referencedColumnName: 'id')]
34    private ?TerminTemplate $from_template;
35
36    #[ORM\Column(type: 'date', nullable: false)]
37    private \DateTime $start_date;
38
39    #[ORM\Column(type: 'time', nullable: true)]
40    private ?\DateTime $start_time;
41
42    #[ORM\Column(type: 'date', nullable: true)]
43    private ?\DateTime $end_date;
44
45    #[ORM\Column(type: 'time', nullable: true)]
46    private ?\DateTime $end_time;
47
48    #[ORM\Column(type: 'datetime', nullable: true)]
49    private ?\DateTime $deadline;
50
51    #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => 0])]
52    private bool $should_promote;
53
54    #[ORM\ManyToOne(targetEntity: User::class)]
55    #[ORM\JoinColumn(name: 'organizer_user_id', referencedColumnName: 'id', nullable: true)]
56    protected ?User $organizer_user;
57
58    #[ORM\ManyToOne(targetEntity: Registration::class)]
59    #[ORM\JoinColumn(name: 'participants_registration_id', referencedColumnName: 'id')]
60    private ?Registration $participants_registration;
61
62    #[ORM\Column(type: 'integer', nullable: true)]
63    private ?int $num_participants;
64
65    #[ORM\Column(type: 'integer', nullable: true)]
66    private ?int $min_participants;
67
68    #[ORM\Column(type: 'integer', nullable: true)]
69    private ?int $max_participants;
70
71    #[ORM\ManyToOne(targetEntity: Registration::class)]
72    #[ORM\JoinColumn(name: 'volunteers_registration_id', referencedColumnName: 'id')]
73    private ?Registration $volunteers_registration;
74
75    #[ORM\Column(type: 'integer', nullable: true)]
76    private ?int $num_volunteers;
77
78    #[ORM\Column(type: 'integer', nullable: true)]
79    private ?int $min_volunteers;
80
81    #[ORM\Column(type: 'integer', nullable: true)]
82    private ?int $max_volunteers;
83
84    #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => 0])]
85    private bool $newsletter;
86
87    #[ORM\Column(type: 'text', nullable: true)]
88    private ?string $title;
89
90    #[ORM\Column(type: 'text', nullable: true)]
91    private ?string $text;
92
93    #[ORM\Column(type: 'text', nullable: true)]
94    private ?string $documentation;
95
96    /** @var Collection<int|string, TerminLabel>&iterable<TerminLabel> */
97    #[ORM\JoinTable(name: 'termin_label_map')]
98    #[ORM\JoinColumn(name: 'termin_id', referencedColumnName: 'id')]
99    #[ORM\InverseJoinColumn(name: 'label_id', referencedColumnName: 'id')]
100    #[ORM\ManyToMany(targetEntity: TerminLabel::class, inversedBy: 'termine')]
101    private Collection $labels;
102
103    #[ORM\ManyToOne(targetEntity: TerminLocation::class)]
104    #[ORM\JoinColumn(name: 'location_id', referencedColumnName: 'id', nullable: true)]
105    private ?TerminLocation $location;
106
107    #[ORM\Column(type: 'float', nullable: true)]
108    private ?float $latitude;
109
110    #[ORM\Column(type: 'float', nullable: true)]
111    private ?float $longitude;
112
113    #[ORM\ManyToOne(targetEntity: Termin::class)]
114    #[ORM\JoinColumn(name: 'parent_termin_id', referencedColumnName: 'id', nullable: true)]
115    private ?Termin $parent_termin;
116
117    #[ORM\Column(type: 'integer', nullable: true)]
118    private ?int $solv_uid;
119
120    #[ORM\Column(type: 'text', nullable: true)]
121    private ?string $image_ids;
122
123    // PRIMARY KEY (`id`),
124    // KEY `datum` (`datum`),
125    // KEY `on_off` (`on_off`),
126    // KEY `datum_end` (`datum_end`),
127    // KEY `datum_off` (`datum_off`)
128
129    public static function id(int $id): self {
130        $entity = new self();
131        $entity->setId($id);
132        return $entity;
133    }
134
135    public function __construct() {
136        $this->labels = new ArrayCollection();
137    }
138
139    public function getId(): ?int {
140        return $this->id ?? null;
141    }
142
143    public function setId(int $new_value): void {
144        $this->id = $new_value;
145    }
146
147    public function getFromTemplate(): ?TerminTemplate {
148        return $this->from_template;
149    }
150
151    public function setFromTemplate(?TerminTemplate $new_value): void {
152        $this->from_template = $new_value;
153    }
154
155    public function getStartDate(): \DateTime {
156        return $this->start_date;
157    }
158
159    public function setStartDate(\DateTime $new_value): void {
160        $this->start_date = $new_value;
161    }
162
163    public function getStartTime(): ?\DateTime {
164        return $this->start_time;
165    }
166
167    public function setStartTime(?\DateTime $new_value): void {
168        $this->start_time = $new_value;
169    }
170
171    public function getEndDate(): ?\DateTime {
172        return $this->end_date;
173    }
174
175    public function setEndDate(?\DateTime $new_value): void {
176        $this->end_date = $new_value;
177    }
178
179    public function getEndTime(): ?\DateTime {
180        return $this->end_time;
181    }
182
183    public function setEndTime(?\DateTime $new_value): void {
184        $this->end_time = $new_value;
185    }
186
187    public function getDeadline(): ?\DateTime {
188        return $this->deadline;
189    }
190
191    public function setDeadline(?\DateTime $new_value): void {
192        $this->deadline = $new_value;
193    }
194
195    public function getShouldPromote(): bool {
196        return $this->should_promote;
197    }
198
199    public function setShouldPromote(bool $new_value): void {
200        $this->should_promote = $new_value;
201    }
202
203    public function getTitle(): ?string {
204        return $this->title;
205    }
206
207    public function setTitle(?string $new_value): void {
208        $this->title = $new_value;
209    }
210
211    public function getText(): ?string {
212        return $this->text;
213    }
214
215    public function setText(?string $new_value): void {
216        $this->text = $new_value;
217    }
218
219    public function getDocumentation(): ?string {
220        return $this->documentation;
221    }
222
223    public function setDocumentation(?string $new_value): void {
224        $this->documentation = $new_value;
225    }
226
227    /** @return Collection<int|string, TerminLabel>&iterable<TerminLabel> */
228    public function getLabels(): Collection {
229        return $this->labels;
230    }
231
232    public function addLabel(TerminLabel $label): void {
233        $this->labels->add($label);
234    }
235
236    public function removeLabel(TerminLabel $label): void {
237        $this->labels->removeElement($label);
238    }
239
240    public function clearLabels(): void {
241        $this->labels->clear();
242    }
243
244    public function getSolvId(): ?int {
245        return $this->solv_uid;
246    }
247
248    public function setSolvId(?int $new_value): void {
249        $this->solv_uid = $new_value;
250    }
251
252    public function getLatitude(): ?float {
253        return $this->latitude;
254    }
255
256    public function setLatitude(?float $new_value): void {
257        $this->latitude = $new_value;
258    }
259
260    public function getLongitude(): ?float {
261        return $this->longitude;
262    }
263
264    public function setLongitude(?float $new_value): void {
265        $this->longitude = $new_value;
266    }
267
268    public function getLocation(): ?TerminLocation {
269        return $this->location;
270    }
271
272    public function setLocation(?TerminLocation $new_value): void {
273        $this->location = $new_value;
274    }
275
276    public function getNewsletter(): bool {
277        return $this->newsletter;
278    }
279
280    public function setNewsletter(bool $new_value): void {
281        $this->newsletter = $new_value;
282    }
283
284    public function getParentTermin(): ?Termin {
285        return $this->parent_termin;
286    }
287
288    public function setParentTermin(?Termin $new_value): void {
289        $this->parent_termin = $new_value;
290    }
291
292    /** @return array<string> */
293    public function getImageIds(): array {
294        if ($this->image_ids == null) {
295            return [];
296        }
297        $array = json_decode($this->image_ids, true);
298        return is_array($array) ? $array : [];
299    }
300
301    /** @param array<string> $new_value */
302    public function setImageIds(array $new_value): void {
303        $enc_value = json_encode($new_value);
304        if (!$enc_value) {
305            return;
306        }
307        $this->image_ids = $enc_value;
308    }
309
310    public function getOrganizerUser(): ?User {
311        return $this->organizer_user;
312    }
313
314    public function setOrganizerUser(?User $new_value): void {
315        $this->organizer_user = $new_value;
316    }
317
318    public function getParticipantsRegistration(): ?Registration {
319        return $this->participants_registration;
320    }
321
322    public function setParticipantsRegistration(?Registration $new_value): void {
323        $this->participants_registration = $new_value;
324    }
325
326    public function getNumParticipants(): ?int {
327        return $this->num_participants;
328    }
329
330    public function setNumParticipants(?int $new_value): void {
331        $this->num_participants = $new_value;
332    }
333
334    public function getMinParticipants(): ?int {
335        return $this->min_participants;
336    }
337
338    public function setMinParticipants(?int $new_value): void {
339        $this->min_participants = $new_value;
340    }
341
342    public function getMaxParticipants(): ?int {
343        return $this->max_participants;
344    }
345
346    public function setMaxParticipants(?int $new_value): void {
347        $this->max_participants = $new_value;
348    }
349
350    public function getVolunteersRegistration(): ?Registration {
351        return $this->volunteers_registration;
352    }
353
354    public function setVolunteersRegistration(?Registration $new_value): void {
355        $this->volunteers_registration = $new_value;
356    }
357
358    public function getNumVolunteers(): ?int {
359        return $this->num_volunteers;
360    }
361
362    public function setNumVolunteers(?int $new_value): void {
363        $this->num_volunteers = $new_value;
364    }
365
366    public function getMinVolunteers(): ?int {
367        return $this->min_volunteers;
368    }
369
370    public function setMinVolunteers(?int $new_value): void {
371        $this->min_volunteers = $new_value;
372    }
373
374    public function getMaxVolunteers(): ?int {
375        return $this->max_volunteers;
376    }
377
378    public function setMaxVolunteers(?int $new_value): void {
379        $this->max_volunteers = $new_value;
380    }
381
382    // ---
383
384    public function testOnlyGetField(string $field_name): mixed {
385        return $this->{$field_name};
386    }
387
388    public static function getIdFieldNameForSearch(): string {
389        return 'id';
390    }
391
392    public function getIdForSearch(): int {
393        return $this->getId() ?? 0;
394    }
395
396    public function getTitleForSearch(): string {
397        $pretty_date = $this->getStartDate()->format('Y-m-d');
398        return "{$pretty_date}: {$this->getTitle()}";
399    }
400
401    public static function getCriteriaForFilter(string $key, string $value): Expression {
402        throw new \Exception("No such Termin filter: {$key}");
403    }
404
405    public static function getCriteriaForQuery(string $query): Expression {
406        $range = self::parseSearchDateRange($query);
407        if (!$range) {
408            return Criteria::expr()->contains('title', $query);
409        }
410        return Criteria::expr()->orX(
411            Criteria::expr()->andX(
412                Criteria::expr()->gte('start_date', $range['start']),
413                Criteria::expr()->lt('start_date', $range['end']),
414            ),
415            Criteria::expr()->contains('title', $query),
416        );
417    }
418
419    /**
420     * Entities are not services, so `DateUtils` can never be injected into
421     * `Termin`. It is therefore read from the global `WithUtilsCache`, and
422     * this fails loudly if no service has warmed that cache yet.
423     *
424     * @return ?array{start:\DateTime, end:\DateTime}
425     */
426    private static function parseSearchDateRange(string $query): ?array {
427        $date_utils = WithUtilsCache::get('dateUtils');
428        if (!$date_utils instanceof DateUtils) {
429            throw new \RuntimeException('Termin::getCriteriaForQuery() requires a warmed WithUtilsCache.');
430        }
431        return $date_utils->parseDateTimeRange($query);
432    }
433
434    public static function getEntityNameForStorage(): string {
435        return 'termine';
436    }
437
438    public function getEntityIdForStorage(): string {
439        return "{$this->getId()}";
440    }
441}