ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSParticipantSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 private static ?array $instances = null;
27
28 private array $export = array();
29 private array $import = array();
30
31 private int $server_id;
32
34
38 private function __construct(int $a_server_id)
39 {
40 global $DIC;
41
42 $this->db = $DIC['ilDB'];
43 $this->server_id = $a_server_id;
44 $this->read();
45 }
46
50 public static function getInstanceByServerId(int $a_server_id): ilECSParticipantSettings
51 {
52 return self::$instances[$a_server_id] ?? (self::$instances[$a_server_id] = new ilECSParticipantSettings($a_server_id));
53 }
54
59 public function getAvailabeMids(): array
60 {
61 $query = 'SELECT mid FROM ecs_part_settings ' .
62 'WHERE sid = ' . $this->db->quote($this->server_id, 'integer');
63 $res = $this->db->query($query);
64
65 $mids = array();
66 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
67 $mids[] = (int) $row->mid;
68 }
69 return $mids;
70 }
71
72
73
77 public function lookupCmsMid(): int
78 {
79 $query = 'SELECT mid FROM ecs_part_settings ' .
80 'WHERE sid = ' . $this->db->quote($this->server_id, 'integer') . ' ' .
81 'AND import_type = ' . $this->db->quote(ilECSParticipantSetting::IMPORT_CMS);
82 $res = $this->db->query($query);
83 if ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
84 return (int) $row->mid;
85 }
86 return 0;
87 }
88
92 public function getServerId(): int
93 {
94 return $this->server_id;
95 }
96
100 private function read(): void
101 {
102 $query = 'SELECT * FROM ecs_part_settings ' .
103 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ';
104 $res = $this->db->query($query);
105 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
106 $this->export[$row->mid] = $row->export;
107 $this->import[$row->mid] = $row->import;
108 }
109 }
110
114 public function isImportAllowed(array $a_mids): bool
115 {
116 foreach ($a_mids as $mid) {
117 if ($this->import[$mid]) {
118 return true;
119 }
120 }
121 return false;
122 }
123
129 public function getEnabledParticipants(): array
130 {
131 $ret = array();
132 foreach ($this->export as $mid => $enabled) {
133 if ($enabled) {
134 $ret[] = $mid;
135 }
136 }
137 return $ret;
138 }
139
147 public function isEnabled($a_mid): bool
148 {
149 return $this->export[$a_mid] ? true : false;
150 }
151}
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.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26