ILIAS  release_8 Revision v8.24
class.ilECSServerSettings.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
26{
27 public const ALL_SERVER = 0;
28 public const ACTIVE_SERVER = 1;
29 public const INACTIVE_SERVER = 2;
30
32
33 // Injected
35
36 // Local
37 private array $servers;
38
39
43 protected function __construct()
44 {
45 global $DIC;
46
47 $this->db = $DIC->database();
48
49 $this->readServers();
50 }
51
57 public static function getInstance(): ilECSServerSettings
58 {
59 return self::$instance ?? (self::$instance = new ilECSServerSettings());
60 }
61
66 public function activeServerExists(): bool
67 {
68 return count($this->getServers(static::ACTIVE_SERVER)) ? true : false;
69 }
70
74 public function serverExists(): bool
75 {
76 return count($this->getServers(static::ALL_SERVER)) ? true : false;
77 }
78
84 public function getServers(int $server_type): array
85 {
86 switch ($server_type) {
87 case static::ALL_SERVER:
88 return $this->servers;
89 break;
90 case static::ACTIVE_SERVER:
91 return array_filter($this->servers, static fn (ilECSSetting $server) => $server->isEnabled());
92 break;
93 case static::INACTIVE_SERVER:
94 return array_filter($this->servers, static fn (ilECSSetting $server) => !$server->isEnabled());
95 break;
96 default:
97 throw new InvalidArgumentException();
98 }
99 }
100
104 private function readServers(): void
105 {
106 $query = 'SELECT server_id FROM ecs_server ' .
107 'ORDER BY title ';
108 $res = $this->db->query($query);
109
110 $this->servers = array();
111 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
112 $server_id = (int) $row->server_id;
113 $this->servers[$server_id] = ilECSSetting::getInstanceByServerId($server_id);
114 }
115 }
116}
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.
$server
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query