Lines
100.00%
21 / 21
Methods
100.00%
6 / 6
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| getRequestedQueueStatus | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 4 | ||
| getEntity | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | ||
| getSingleScope | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 2 | ||
| createInstance | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| getCollections | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | ||
| 15 | class Calldisplay | |
| 16 | { | |
| 17 | protected $entity; | |
| 18 | protected $isEntityResolved = false; | |
| 19 | ||
| 20 | const array DEFAULT_STATUS = ['called']; | |
| 21 | const array WAITING_STATUS = ['confirmed', 'queued', 'called', 'pending']; | |
| 22 | ||
| 23 | ||
| 24 | public function __construct($request) | |
| 25 | { | |
| 26 | $this->entity = static::createInstance($request); | |
| 27 | } | |
| 28 | ||
| 29 | public static function getRequestedQueueStatus(\Psr\Http\Message\RequestInterface $request) | |
| 30 | { | |
| 31 | /** @var Validator $validator */ | |
| 32 | $validator = $request->getAttribute('validator'); | |
| 33 | $queue = $validator->getParameter('queue')->isArray()->getValue(); | |
| 34 | $status = (is_array($queue) && isset($queue['status'])) ? $queue['status'] : null; | |
| 35 | return is_string($status) ? explode(',', $status) : static::DEFAULT_STATUS; | |
| 36 | } | |
| 37 | ||
| 38 | public function getEntity(bool $resolveEntity = true) | |
| 39 | { | |
| 40 | if (!$this->isEntityResolved && $resolveEntity) { | |
| 41 | $callDisplay = \App::$http->readPostResult('/calldisplay/', $this->entity); | |
| 42 | $this->entity = $callDisplay ? $callDisplay->getEntity() : new \BO\Zmsentities\Calldisplay(); | |
| 43 | $this->isEntityResolved = true; | |
| 44 | } | |
| 45 | ||
| 46 | return $this->entity; | |
| 47 | } | |
| 48 | ||
| 49 | public function getSingleScope() | |
| 50 | { | |
| 51 | $scope = null; | |
| 52 | if (1 == $this->getEntity(false)->getScopeList()->count()) { | |
| 53 | $scopeId = $this->getEntity(false)->getScopeList()->getFirst()->getId(); | |
| 54 | $scope = \App::$http | |
| 55 | ->readGetResult('/scope/' . $scopeId . '/', ['keepLessData' => ['status']]) | |
| 56 | ->getEntity(); | |
| 57 | } | |
| 58 | return $scope; | |
| 59 | } | |
| 60 | ||
| 61 | protected static function createInstance($request) | |
| 62 | { | |
| 63 | $calldisplay = new Entity(); | |
| 64 | ||
| 65 | return $calldisplay->withResolvedCollections(static::getCollections($request)); | |
| 66 | } | |
| 67 | ||
| 68 | protected static function getCollections($request) | |
| 69 | { | |
| 70 | $validator = $request->getAttribute('validator'); | |
| 71 | ||
| 72 | return $validator->getParameter('collections')->isArray()->getValue(); | |
| 73 | } | |
| 74 | } |