Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Day
100.00% covered (success)
100.00%
30 / 30
100.00% covered (success)
100.00%
3 / 3
11
100.00% covered (success)
100.00%
1 / 1
 writeTemporaryScopeList
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
5
 readByCalendar
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
4
 __destruct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace BO\Zmsdb;
4
5use BO\Zmsentities\Day as Entity;
6
7/**
8 *
9 */
10class Day extends Base
11{
12    protected $tempScopeListExists = false;
13
14    public function writeTemporaryScopeList(\BO\Zmsentities\Calendar $calendar, $slotsRequiredForce = null)
15    {
16        $this->getReader()->exec(Query\Day::QUERY_CREATE_TEMPORARY_SCOPELIST);
17        $monthList = $calendar->getMonthList();
18        $slotsRequired = $slotsRequiredForce;
19        foreach ($monthList as $month) {
20            $dateTime = $month->getFirstDay();
21            foreach ($calendar->scopes as $scope) {
22                if (!$slotsRequiredForce) {
23                    $slotsRequired = $calendar->scopes->getRequiredSlotsByScope($scope);
24                }
25                $this->getReader()->perform(Query\Day::QUERY_INSERT_TEMPORARY_SCOPELIST, [
26                    'scopeID' => $scope->id,
27                    'year' => $dateTime->format('Y'),
28                    'month' => $dateTime->format('m'),
29                    'slotsRequired' => $slotsRequired > 1 ? round($slotsRequired, 0) : 1,
30                ]);
31            }
32        }
33        $this->tempScopeListExists = true;
34    }
35
36    public function readByCalendar(\BO\Zmsentities\Calendar $calendar, $slotsRequiredForce = null)
37    {
38        // We use a temporary table, so we can use create and insert on a readonly connection
39        $this->writeTemporaryScopeList($calendar, $slotsRequiredForce);
40        //var_dump($this->getReader()->fetchAll('SELECT * FROM calendarscope'));
41        $dayList = new \BO\Zmsentities\Collection\DayList();
42        $dayData = $this->getReader()->fetchAll(
43            Query\Day::QUERY_DAYLIST_JOIN,
44            [
45                'forceRequiredSlots' =>
46                    ($slotsRequiredForce === null || $slotsRequiredForce < 1) ? 1 : round($slotsRequiredForce),
47            ]
48        );
49        foreach ($dayData as $day) {
50            $day = new \BO\Zmsentities\Day($day);
51            $dayList[$day->getDayHash()] = $day;
52        }
53        return $dayList;
54    }
55
56    /**
57     * Remove temporary scope list at destruct to allow other functions to use it
58     */
59    public function __destruct()
60    {
61        if ($this->tempScopeListExists) {
62            $this->getReader()->exec(Query\Day::QUERY_DROP_TEMPORARY_SCOPELIST);
63        }
64    }
65}