ILIAS  release_8 Revision v8.24
class.ilECSCommunitiesCache.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
24{
25 private static ?\ilECSCommunitiesCache $instance = null;
26
28
29 private array $communities = array();
30
34 protected function __construct()
35 {
36 global $DIC;
37
38 $this->db = $DIC->database();
39
40 $this->read();
41 }
42
47 public static function getInstance(): ilECSCommunitiesCache
48 {
49 return self::$instance ?? (self::$instance = new ilECSCommunitiesCache());
50 }
51
55 public function delete(int $a_server_id): void
56 {
57 $query = 'DELETE FROM ecs_community ' .
58 'WHERE sid = ' . $this->db->quote($a_server_id, 'integer');
59 $this->db->manipulate($query);
60 $this->read();
61 }
62
67 public function getCommunities(): array
68 {
69 return $this->communities;
70 }
71
75 public function lookupOwnId(int $a_server_id, int $a_mid): int
76 {
77 foreach ($this->getCommunities() as $com) {
78 if (($com->getServerId() === $a_server_id) && in_array($a_mid, $com->getMids(), true)) {
79 return $com->getOwnId();
80 }
81 }
82 return 0;
83 }
84
90 public function lookupTitle(int $a_server_id, int $a_mid): string
91 {
92 foreach ($this->getCommunities() as $com) {
93 if (($com->getServerId() === $a_server_id) && in_array($a_mid, $com->getMids(), true)) {
94 return $com->getCommunityName();
95 }
96 }
97 return '';
98 }
99
103 private function read(): void
104 {
105 $query = 'SELECT sid,cid FROM ecs_community ';
106 $res = $this->db->query($query);
107 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
108 $this->communities[] = ilECSCommunityCache::getInstance((int) $row->sid, (int) $row->cid);
109 }
110 }
111}
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.
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query