Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
20.59% covered (danger)
20.59%
7 / 34
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
Closure
20.59% covered (danger)
20.59%
7 / 34
0.00% covered (danger)
0.00%
0 / 5
40.05
0.00% covered (danger)
0.00%
0 / 1
 readByScopeId
70.00% covered (warning)
70.00%
7 / 10
0.00% covered (danger)
0.00%
0 / 1
4.43
 readByScopeIdAndDate
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 deleteEntity
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 createOne
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 1
2
 readEntity
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace BO\Zmsdb;
4
5use BO\Zmsentities\Closure as Entity;
6use BO\Zmsentities\Collection\ClosureList as Collection;
7use DateTime;
8
9class Closure extends Base
10{
11    public function readByScopeId($scopeId = 0)
12    {
13        $closureList = new Collection();
14        $query = new Query\Closure(Query\Base::SELECT);
15        $query->addEntityMapping()
16            ->addConditionScopeId($scopeId);
17        $result = $this->fetchList($query, new Entity());
18        if (count($result)) {
19            foreach ($result as $entity) {
20                if ($entity instanceof Entity) {
21                    $closureList->addEntity($entity);
22                }
23            }
24        }
25        return $closureList;
26    }
27
28    public function readByScopeIdAndDate($scopeId, DateTime $date)
29    {
30        $query = new Query\Closure(Query\Base::SELECT);
31        $query->addEntityMapping()
32            ->addConditionScopeId($scopeId)
33            ->addConditionDate($date);
34
35        return $this->fetchOne($query, new \BO\Zmsentities\Closure());
36    }
37
38    public function deleteEntity($itemId)
39    {
40        $query = new Query\Closure(Query\Base::DELETE);
41        $query->addConditionId($itemId);
42        return ($this->deleteItem($query));
43    }
44
45    public function createOne($scopeId, DateTime $date)
46    {
47        $query = new Query\Closure(Query\Base::INSERT);
48        $query->addValues(
49            array(
50                'StandortID' => $scopeId,
51                'year' => (int) $date->format('Y'),
52                'month' => (int) $date->format('m'),
53                'day' => (int) $date->format('d')
54            )
55        );
56        $this->writeItem($query);
57        $id = $this->getWriter()->lastInsertId();
58
59        return $this->readEntity($id);
60    }
61
62    public function readEntity($id)
63    {
64        $query = new Query\Closure(Query\Base::SELECT);
65        $query->addEntityMapping()
66            ->addConditionId($id);
67
68        return $this->fetchOne($query, new \BO\Zmsentities\Closure());
69    }
70}