ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSCommunitiesCache.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 private static ?\ilECSCommunitiesCache $instance = null;
27
29
30 private array $communities = array();
31
35 protected function __construct()
36 {
37 global $DIC;
38
39 $this->db = $DIC->database();
40
41 $this->read();
42 }
43
48 public static function getInstance(): ilECSCommunitiesCache
49 {
50 return self::$instance ?? (self::$instance = new ilECSCommunitiesCache());
51 }
52
56 public function delete(int $a_server_id): void
57 {
58 $query = 'DELETE FROM ecs_community ' .
59 'WHERE sid = ' . $this->db->quote($a_server_id, 'integer');
60 $this->db->manipulate($query);
61 $this->read();
62 }
63
68 public function getCommunities(): array
69 {
70 return $this->communities;
71 }
72
76 public function lookupOwnId(int $a_server_id, int $a_mid): int
77 {
78 foreach ($this->getCommunities() as $com) {
79 if (($com->getServerId() === $a_server_id) && in_array($a_mid, $com->getMids(), true)) {
80 return $com->getOwnId();
81 }
82 }
83 return 0;
84 }
85
91 public function lookupTitle(int $a_server_id, int $a_mid): string
92 {
93 foreach ($this->getCommunities() as $com) {
94 if (($com->getServerId() === $a_server_id) && in_array($a_mid, $com->getMids(), true)) {
95 return $com->getCommunityName();
96 }
97 }
98 return '';
99 }
100
104 private function read(): void
105 {
106 $query = 'SELECT sid,cid FROM ecs_community ';
107 $res = $this->db->query($query);
108 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
109 $this->communities[] = ilECSCommunityCache::getInstance((int) $row->sid, (int) $row->cid);
110 }
111 }
112}
static getInstance()
Singleton instance.
__construct()
Singleton constructor.
static ilECSCommunitiesCache $instance
lookupTitle(int $a_server_id, int $a_mid)
Lookup community title.
lookupOwnId(int $a_server_id, int $a_mid)
Lookup own mid of the community of a mid.
static getInstance(int $a_server_id, int $a_community_id)
Get instance.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26