Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Link | |
100.00% |
25 / 25 |
|
100.00% |
3 / 3 |
11 | |
100.00% |
1 / 1 |
| readByDepartmentId | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
8 | |||
| writeEntity | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| deleteEntity | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdb; |
| 4 | |
| 5 | use BO\Zmsdb\Application as App; |
| 6 | use BO\Zmsentities\Link as Entity; |
| 7 | use BO\Zmsentities\Collection\LinkList as Collection; |
| 8 | |
| 9 | class Link extends Base |
| 10 | { |
| 11 | /** |
| 12 | * Fetch status from db |
| 13 | * |
| 14 | * @return \BO\Zmsentities\Collection\LinkList |
| 15 | */ |
| 16 | public function readByDepartmentId($departmentId, $disableCache = false) |
| 17 | { |
| 18 | $cacheKey = "linksReadByDepartmentId-$departmentId"; |
| 19 | |
| 20 | if (!$disableCache && App::$cache && App::$cache->has($cacheKey)) { |
| 21 | return App::$cache->get($cacheKey); |
| 22 | } |
| 23 | |
| 24 | $linkList = new Collection(); |
| 25 | $query = new Query\Link(Query\Base::SELECT); |
| 26 | $query |
| 27 | ->addEntityMapping() |
| 28 | ->addConditionDepartmentId($departmentId); |
| 29 | $result = $this->fetchList($query, new Entity()); |
| 30 | if (count($result)) { |
| 31 | foreach ($result as $entity) { |
| 32 | if ($entity instanceof Entity) { |
| 33 | $linkList->addEntity($entity); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | if (App::$cache) { |
| 39 | App::$cache->set($cacheKey, $linkList); |
| 40 | } |
| 41 | |
| 42 | return $linkList; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * write a link |
| 47 | * |
| 48 | * @param |
| 49 | * entity, |
| 50 | * organisationId |
| 51 | * |
| 52 | * @return Entity |
| 53 | */ |
| 54 | public function writeEntity(Entity $entity, $departmentId) |
| 55 | { |
| 56 | $query = new Query\Link(Query\Base::INSERT); |
| 57 | $values = $query->reverseEntityMapping($entity, $departmentId); |
| 58 | $query->addValues($values); |
| 59 | |
| 60 | if (App::$cache) { |
| 61 | App::$cache->delete("linksReadByDepartmentId-$departmentId"); |
| 62 | } |
| 63 | |
| 64 | return $this->writeItem($query); |
| 65 | } |
| 66 | |
| 67 | public function deleteEntity($itemId) |
| 68 | { |
| 69 | $query = new Query\Link(Query\Base::DELETE); |
| 70 | $query->addConditionLinkId($itemId); |
| 71 | return ($this->deleteItem($query)); |
| 72 | } |
| 73 | } |