Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
ClusterHelper
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
6 / 6
11
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getEntity
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getScopeList
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getProcessList
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
 getNextProcess
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
1 / 1
3
 isClusterEnabled
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 *
5 * @package Zmsappointment
6 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
7 *
8 */
9
10namespace BO\Zmsadmin\Helper;
11
12use BO\Zmsentities\Workstation;
13use BO\Zmsentities\Collection\ProcessList;
14
15class ClusterHelper
16{
17    protected static $cluster = null;
18
19    protected static $workstation = null;
20
21    public function __construct(Workstation $workstation)
22    {
23        static::$workstation = $workstation;
24        static::$cluster = \App::$http->readGetResult('/scope/' . $workstation->scope['id'] . '/cluster/')->getEntity();
25    }
26
27    public static function getEntity()
28    {
29        return static::$cluster;
30    }
31
32    public static function getScopeList()
33    {
34        return static::$workstation->getScopeList(static::$cluster);
35    }
36
37    /** @psalm-api */
38    public static function getProcessList($selectedDate)
39    {
40        if (static::isClusterEnabled()) {
41            $processList = \App::$http
42                ->readGetResult(
43                    '/cluster/' . static::$cluster->id . '/process/' . $selectedDate . '/',
44                    ['gql' => GraphDefaults::getProcess()]
45                );
46        } else {
47            $processList = \App::$http
48                ->readGetResult(
49                    '/scope/' . static::$workstation->scope['id'] . '/process/' . $selectedDate . '/',
50                    ['gql' => GraphDefaults::getProcess()]
51                );
52        }
53        return ($processList) ? $processList->getCollection() : new ProcessList();
54    }
55
56    public static function getNextProcess(array $excludedIds)
57    {
58        $exclude = is_array($excludedIds) ? ExcludeIds::toQuery($excludedIds) : (string) $excludedIds;
59        if (static::isClusterEnabled()) {
60            $nextProcess =  \App::$http->readGetResult(
61                '/cluster/' . static::$cluster['id'] . '/queue/next/',
62                [
63                    'exclude' => $exclude,
64                    'allowClusterWideCall' => \App::$allowClusterWideCall
65                ]
66            )?->getEntity();
67        } else {
68            $nextProcess = \App::$http->readGetResult(
69                '/scope/' . static::$workstation->scope['id'] . '/queue/next/',
70                ['exclude' => $exclude]
71            )?->getEntity();
72        }
73
74        return $nextProcess;
75    }
76
77    public static function isClusterEnabled(): bool
78    {
79        return (static::$workstation->queue['clusterEnabled'] && static::$cluster);
80    }
81}