ILIAS  release_8 Revision v8.24
class.ilECSParticipantSettings.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
24{
25 private static ?array $instances = null;
26
27 private array $export = array();
28 private array $import = array();
29
30 private int $server_id;
31
33
37 private function __construct(int $a_server_id)
38 {
39 global $DIC;
40
41 $this->db = $DIC['ilDB'];
42 $this->server_id = $a_server_id;
43 $this->read();
44 }
45
49 public static function getInstanceByServerId(int $a_server_id): ilECSParticipantSettings
50 {
51 return self::$instances[$a_server_id] ?? (self::$instances[$a_server_id] = new ilECSParticipantSettings($a_server_id));
52 }
53
58 public function getAvailabeMids(): array
59 {
60 $query = 'SELECT mid FROM ecs_part_settings ' .
61 'WHERE sid = ' . $this->db->quote($this->server_id, 'integer');
62 $res = $this->db->query($query);
63
64 $mids = array();
65 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
66 $mids[] = (int) $row->mid;
67 }
68 return $mids;
69 }
70
71
72
76 public function lookupCmsMid(): int
77 {
78 $query = 'SELECT mid FROM ecs_part_settings ' .
79 'WHERE sid = ' . $this->db->quote($this->server_id, 'integer') . ' ' .
80 'AND import_type = ' . $this->db->quote(ilECSParticipantSetting::IMPORT_CMS);
81 $res = $this->db->query($query);
82 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
83 return (int) $row->mid;
84 }
85 return 0;
86 }
87
91 public function getServerId(): int
92 {
93 return $this->server_id;
94 }
95
99 private function read(): void
100 {
101 $query = 'SELECT * FROM ecs_part_settings ' .
102 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ';
103 $res = $this->db->query($query);
104 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
105 $this->export[$row->mid] = $row->export;
106 $this->import[$row->mid] = $row->import;
107 }
108 }
109
113 public function isImportAllowed(array $a_mids): bool
114 {
115 foreach ($a_mids as $mid) {
116 if ($this->import[$mid]) {
117 return true;
118 }
119 }
120 return false;
121 }
122
128 public function getEnabledParticipants(): array
129 {
130 $ret = array();
131 foreach ($this->export as $mid => $enabled) {
132 if ($enabled) {
133 $ret[] = $mid;
134 }
135 }
136 return $ret;
137 }
138
146 public function isEnabled($a_mid): bool
147 {
148 return $this->export[$a_mid] ? true : false;
149 }
150}
return true
isEnabled($a_mid)
is participant enabled
getAvailabeMids()
Get all available mids.
getEnabledParticipants()
get number of participants that are enabled
lookupCmsMid()
Lookup mid of current cms participant.
__construct(int $a_server_id)
Constructor (Singleton)
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
isImportAllowed(array $a_mids)
Check if import is allowed for specific mid.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
$query