Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AvailabilityHistory
100.00% covered (success)
100.00%
38 / 38
100.00% covered (success)
100.00%
3 / 3
8
100.00% covered (success)
100.00%
1 / 1
 getDefaults
100.00% covered (success)
100.00%
29 / 29
100.00% covered (success)
100.00%
1 / 1
2
 encodeWeekdayMask
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 decodeWeekdayMask
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Zmsentities;
6
7class AvailabilityHistory extends Schema\Entity
8{
9    public const string PRIMARY = 'id';
10
11    public static $schema = 'availabilityhistory.json';
12
13    public const string ACTION_CREATED = 'created';
14    public const string ACTION_UPDATED = 'updated';
15    public const string ACTION_DELETED = 'deleted';
16    public const string ACTION_DLDB_SLOT_UPDATE = 'dldb_slot_update';
17
18    /** @var list<string> */
19    public const array ACTIONS = [
20        self::ACTION_CREATED,
21        self::ACTION_UPDATED,
22        self::ACTION_DELETED,
23        self::ACTION_DLDB_SLOT_UPDATE,
24    ];
25
26    /** @var array<string, int> */
27    public const array WEEKDAY_BITS = [
28        'sunday' => 1,
29        'monday' => 2,
30        'tuesday' => 4,
31        'wednesday' => 8,
32        'thursday' => 16,
33        'friday' => 32,
34        'saturday' => 64,
35    ];
36
37    #[\Override]
38    public function getDefaults(): array
39    {
40        $weekday = [];
41        foreach (array_keys(self::WEEKDAY_BITS) as $name) {
42            $weekday[$name] = 0;
43        }
44
45        return [
46            'id' => null,
47            'scopeId' => 0,
48            'availabilityId' => null,
49            'action' => self::ACTION_CREATED,
50            'weekday' => $weekday,
51            'startDate' => '',
52            'endDate' => '',
53            'everyXWeeks' => 0,
54            'everyOtherWeek' => 0,
55            'startTime' => '00:00:00',
56            'appointmentStartTime' => '00:00:00',
57            'endTime' => '00:00:00',
58            'appointmentEndTime' => '00:00:00',
59            'timeSlot' => '00:00:00',
60            'workstationCount' => 0,
61            'appointmentWorkstationCount' => 0,
62            'comment' => null,
63            'internetReduction' => 0,
64            'multipleSlotsAllowed' => 0,
65            'openFromDays' => 0,
66            'openUntilDays' => 0,
67            'version' => 1,
68            'changedAt' => '',
69            'changedBy' => '',
70        ];
71    }
72
73    public static function encodeWeekdayMask(Availability $availability): int
74    {
75        $mask = 0;
76        foreach (self::WEEKDAY_BITS as $weekday => $bit) {
77            if (!empty($availability->weekday[$weekday])) {
78                $mask |= $bit;
79            }
80        }
81
82        return $mask;
83    }
84
85    /** @return array<string, int> */
86    public static function decodeWeekdayMask(int $mask): array
87    {
88        $weekday = [];
89        foreach (self::WEEKDAY_BITS as $name => $bit) {
90            $weekday[$name] = ($mask & $bit) ? $bit : 0;
91        }
92
93        return $weekday;
94    }
95}