ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSServerSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 public const ALL_SERVER = 0;
29 public const ACTIVE_SERVER = 1;
30 public const INACTIVE_SERVER = 2;
31
33
34 // Injected
36
37 // Local
38 private array $servers;
39
40
44 protected function __construct()
45 {
46 global $DIC;
47
48 $this->db = $DIC->database();
49
50 $this->readServers();
51 }
52
58 public static function getInstance(): ilECSServerSettings
59 {
60 return self::$instance ?? (self::$instance = new ilECSServerSettings());
61 }
62
67 public function activeServerExists(): bool
68 {
69 return count($this->getServers(static::ACTIVE_SERVER)) ? true : false;
70 }
71
75 public function serverExists(): bool
76 {
77 return count($this->getServers(static::ALL_SERVER)) ? true : false;
78 }
79
85 public function getServers(int $server_type): array
86 {
87 switch ($server_type) {
88 case static::ALL_SERVER:
89 return $this->servers;
90 break;
91 case static::ACTIVE_SERVER:
92 return array_filter($this->servers, static fn(ilECSSetting $server) => $server->isEnabled());
93 break;
94 case static::INACTIVE_SERVER:
95 return array_filter($this->servers, static fn(ilECSSetting $server) => !$server->isEnabled());
96 break;
97 default:
98 throw new InvalidArgumentException();
99 }
100 }
101
105 private function readServers(): void
106 {
107 $query = 'SELECT server_id FROM ecs_server ' .
108 'ORDER BY title ';
109 $res = $this->db->query($query);
110
111 $this->servers = array();
112 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
113 $server_id = (int) $row->server_id;
114 $this->servers[$server_id] = ilECSSetting::getInstanceByServerId($server_id);
115 }
116 }
117}
return true
Collection of ECS settings.
getServers(int $server_type)
Get servers The function must be called with ALL_SERVER, ACTIVE_SERVER or INACTIVE_SERVER.
static ilECSServerSettings $instance
serverExists()
Check if there is any server.
__construct()
Singleton contructor.
static getInstance()
Get singleton instance.
activeServerExists()
Check if there is any active server.
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26
$server
Definition: shib_login.php:28