ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilECSCommunityReader Class Reference
+ Collaboration diagram for ilECSCommunityReader:

Public Member Functions

 getServer ()
 Get server setting. More...
 
 getParticipants ()
 Get participants. More...
 
 getOwnMIDs ()
 get publishable ids More...
 
 getCommunities ()
 get communities More...
 
 getCommunityById ($a_id)
 get community by id More...
 
 getParticipantsByPid (int $a_pid)
 
 getParticipantByMID ($a_mid)
 get participant by id More...
 
 getParticipantNameByMid ($a_mid)
 
 getCommunityByMID (int $a_mid)
 Get community by mid. More...
 
 getEnabledParticipants ()
 get enabled participants More...
 

Static Public Member Functions

static getInstanceByServerId (int $a_server_id)
 Get instance by server id. More...
 

Private Member Functions

 __construct (ilECSSetting $setting)
 Singleton constructor. More...
 
 read ()
 Read. More...
 
 createNewParticipants ()
 

Private Attributes

int $position = 0
 
ilLogger $logger
 
ilECSSetting $settings
 
ilECSConnector $connector
 
ilDBInterface $database
 
array $communities = array()
 
array $participants = array()
 
array $own_ids = array()
 

Static Private Attributes

static array $instances = null
 

Detailed Description

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 24 of file class.ilECSCommunityReader.php.

Constructor & Destructor Documentation

◆ __construct()

ilECSCommunityReader::__construct ( ilECSSetting  $setting)
private

Singleton constructor.

@access private

Exceptions
ilECSConnectorException

Definition at line 48 of file class.ilECSCommunityReader.php.

49 {
50 global $DIC;
51
52 $this->logger = $DIC->logger()->wsrv();
53 $this->logger->debug(print_r($setting->getServerId(), true));
54 $this->database = $DIC->database();
55 $this->settings = $setting;
56
57 $this->connector = new ilECSConnector($this->settings);
58
59 $this->read();
60 $this->logger->debug(__METHOD__ . ': Finished reading communities');
61 }
getServerId()
Get current server id.
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\database(), ilECSSetting\getServerId(), ILIAS\Repository\logger(), read(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ createNewParticipants()

ilECSCommunityReader::createNewParticipants ( )
private

Definition at line 222 of file class.ilECSCommunityReader.php.

222 : void
223 {
224 $query = $this->database->queryF(
225 "SELECT mid FROM ecs_part_settings WHERE sid = %s",
227 [$this->connector->getServer()->getServerId()]
228 );
229 $existing_ids = array_map(fn($row) => $row['mid'], $this->database->fetchAll($query));
230 $missing_ids = array_diff(array_keys($this->participants), $existing_ids);
231
232 foreach ($missing_ids as $mid) {
233 $participant = $this->getParticipantByMID($mid);
234 $community = $this->getCommunityByMID($mid);
235
236 $part_settings = ilECSParticipantSetting::getInstance($this->getServer()->getServerId(), $mid);
237 $part_settings->setTitle($participant->getParticipantName());
238 $part_settings->setCommunityName($community->getTitle());
239 $part_settings->update();
240 }
241 }
getServer()
Get server setting.
getCommunityByMID(int $a_mid)
Get community by mid.
getParticipantByMID($a_mid)
get participant by id
static getInstance(int $a_server_id, int $mid)
Get instance by server id and mid.

References ILIAS\Repository\database(), getCommunityByMID(), ilECSParticipantSetting\getInstance(), getParticipantByMID(), getServer(), and ilDBConstants\T_INTEGER.

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCommunities()

ilECSCommunityReader::getCommunities ( )

get communities

@access public

Returns
\ilECSCommunity[]

Definition at line 103 of file class.ilECSCommunityReader.php.

103 : array
104 {
105 return $this->communities ?: [];
106 }

Referenced by getEnabledParticipants(), and getParticipantsByPid().

+ Here is the caller graph for this function:

◆ getCommunityById()

ilECSCommunityReader::getCommunityById (   $a_id)

get community by id

@access public

Parameters
intcomm_id

Definition at line 114 of file class.ilECSCommunityReader.php.

115 {
116 foreach ($this->communities as $community) {
117 if ($community->getId() === $a_id) {
118 return $community;
119 }
120 }
121 return null;
122 }

◆ getCommunityByMID()

ilECSCommunityReader::getCommunityByMID ( int  $a_mid)

Get community by mid.

Definition at line 161 of file class.ilECSCommunityReader.php.

162 {
163 foreach ($this->communities as $community) {
164 foreach ($community->getParticipants() as $part) {
165 if ($part->getMID() === $a_mid) {
166 return $community;
167 }
168 }
169 }
170 return null;
171 }

Referenced by createNewParticipants().

+ Here is the caller graph for this function:

◆ getEnabledParticipants()

ilECSCommunityReader::getEnabledParticipants ( )

get enabled participants

Definition at line 176 of file class.ilECSCommunityReader.php.

176 : array
177 {
178 $ps = ilECSParticipantSettings::getInstanceByServerId($this->getServer()->getServerId());
179 $en = $ps->getEnabledParticipants();
180 $e_part = [];
181 foreach ($this->getCommunities() as $community) {
182 foreach ($community->getParticipants() as $participant) {
183 if (in_array($participant->getMid(), $en, true)) {
184 $e_part[] = $participant;
185 }
186 }
187 }
188 return $e_part;
189 }
static getInstanceByServerId(int $a_server_id)
Get instance by server id.

References getCommunities(), ilECSParticipantSettings\getInstanceByServerId(), and getServer().

+ Here is the call graph for this function:

◆ getInstanceByServerId()

static ilECSCommunityReader::getInstanceByServerId ( int  $a_server_id)
static

◆ getOwnMIDs()

ilECSCommunityReader::getOwnMIDs ( )

get publishable ids

Definition at line 92 of file class.ilECSCommunityReader.php.

92 : array
93 {
94 return $this->own_ids ?: [];
95 }

◆ getParticipantByMID()

ilECSCommunityReader::getParticipantByMID (   $a_mid)

get participant by id

@access public

Parameters
intmid

Definition at line 146 of file class.ilECSCommunityReader.php.

147 {
148 return $this->participants[$a_mid] ?? false;
149 }

Referenced by createNewParticipants().

+ Here is the caller graph for this function:

◆ getParticipantNameByMid()

ilECSCommunityReader::getParticipantNameByMid (   $a_mid)

Definition at line 151 of file class.ilECSCommunityReader.php.

151 : string
152 {
153 return isset($this->participants[$a_mid]) ?
154 $this->participants[$a_mid]->getParticipantName() :
155 '';
156 }

◆ getParticipants()

ilECSCommunityReader::getParticipants ( )

Get participants.

Returns
ilECSParticipant[]

Definition at line 83 of file class.ilECSCommunityReader.php.

83 : array
84 {
86 }

References $participants.

◆ getParticipantsByPid()

ilECSCommunityReader::getParticipantsByPid ( int  $a_pid)
Returns
\ilECSParticipant[]

Definition at line 127 of file class.ilECSCommunityReader.php.

127 : array
128 {
129 $participants = [];
130 foreach ($this->getCommunities() as $community) {
131 foreach ($community->getParticipants() as $participant) {
132 if ($participant->getPid() === $a_pid) {
133 $participants[] = $participant;
134 }
135 }
136 }
137 return $participants;
138 }

References $participants, and getCommunities().

+ Here is the call graph for this function:

◆ getServer()

ilECSCommunityReader::getServer ( )

Get server setting.

Definition at line 74 of file class.ilECSCommunityReader.php.

References $settings.

Referenced by createNewParticipants(), and getEnabledParticipants().

+ Here is the caller graph for this function:

◆ read()

ilECSCommunityReader::read ( )
private

Read.

Exceptions
ilECSConnectorException

Definition at line 196 of file class.ilECSCommunityReader.php.

196 : void
197 {
198 try {
199 $res = $this->connector->getMemberships();
200
201 if (!is_array($res->getResult())) {
202 return;
203 }
204 foreach ($res->getResult() as $community) {
205 $tmp_comm = new ilECSCommunity($community);
206 foreach ($tmp_comm->getParticipants() as $participant) {
207 $this->participants[$participant->getMID()] = $participant;
208 if ($participant->isSelf()) {
209 $this->own_ids[] = $participant->getMID();
210 }
211 }
212 $this->communities[] = $tmp_comm;
213 }
214
215 $this->createNewParticipants();
216 } catch (ilECSConnectorException $e) {
217 $this->logger->error(__METHOD__ . ': Error connecting to ECS server. ' . $e->getMessage());
218 throw $e;
219 }
220 }
$res
Definition: ltiservices.php:69

References Vendor\Package\$e, $res, createNewParticipants(), and ILIAS\Repository\logger().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $communities

array ilECSCommunityReader::$communities = array()
private

Definition at line 38 of file class.ilECSCommunityReader.php.

◆ $connector

ilECSConnector ilECSCommunityReader::$connector
private

Definition at line 32 of file class.ilECSCommunityReader.php.

◆ $database

ilDBInterface ilECSCommunityReader::$database
private

Definition at line 33 of file class.ilECSCommunityReader.php.

◆ $instances

array ilECSCommunityReader::$instances = null
staticprivate

Definition at line 26 of file class.ilECSCommunityReader.php.

◆ $logger

ilLogger ilECSCommunityReader::$logger
private

Definition at line 30 of file class.ilECSCommunityReader.php.

◆ $own_ids

array ilECSCommunityReader::$own_ids = array()
private

Definition at line 40 of file class.ilECSCommunityReader.php.

◆ $participants

array ilECSCommunityReader::$participants = array()
private

Definition at line 39 of file class.ilECSCommunityReader.php.

Referenced by getParticipants(), and getParticipantsByPid().

◆ $position

int ilECSCommunityReader::$position = 0
private

Definition at line 28 of file class.ilECSCommunityReader.php.

◆ $settings

ilECSSetting ilECSCommunityReader::$settings
private

Definition at line 31 of file class.ilECSCommunityReader.php.

Referenced by getServer().


The documentation for this class was generated from the following file: