Lines
100.00%
25 / 25
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 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\Zmsbackend\Link\Service; | |
| 4 | ||
| 5 | use BO\Zmsbackend\Application as App; | |
| 6 | use BO\Zmsentities\Link as Entity; | |
| 7 | use BO\Zmsentities\Collection\LinkList as Collection; | |
| 8 | ||
| 9 | class Link extends \BO\Zmsbackend\Base | |
| 10 | { | |
| 11 | /** | |
| 12 | * Fetch status from db | |
| 13 | * | |
| 14 | * @return \BO\Zmsentities\Collection\LinkList | |
| 15 | */ | |
| 16 | public function readByDepartmentId($departmentId, bool $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 \BO\Zmsbackend\Link\Repository\Link(\BO\Zmsbackend\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 \BO\Zmsentities\Ticketprinter $entity | |
| 49 | * @param int $organisationId | |
| 50 | * | |
| 51 | * @return Entity | |
| 52 | */ | |
| 53 | public function writeEntity(Entity $entity, $departmentId) | |
| 54 | { | |
| 55 | $query = new \BO\Zmsbackend\Link\Repository\Link(\BO\Zmsbackend\Query\Base::INSERT); | |
| 56 | $values = $query->reverseEntityMapping($entity, $departmentId); | |
| 57 | $query->addValues($values); | |
| 58 | ||
| 59 | if (App::$cache) { | |
| 60 | App::$cache->delete("linksReadByDepartmentId-$departmentId"); | |
| 61 | } | |
| 62 | ||
| 63 | return $this->writeItem($query); | |
| 64 | } | |
| 65 | ||
| 66 | public function deleteEntity($itemId): bool | |
| 67 | { | |
| 68 | $query = new \BO\Zmsbackend\Link\Repository\Link(\BO\Zmsbackend\Query\Base::DELETE); | |
| 69 | $query->addConditionLinkId($itemId); | |
| 70 | return ($this->deleteItem($query)); | |
| 71 | } | |
| 72 | } |