ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilECSCommunityReader.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
37 {
38  private static $instances = null;
39 
40  protected $position = 0;
41 
42  protected $log;
43  protected $settings = null;
44  protected $connector = null;
45 
46  protected $communities = array();
47  protected $participants = array();
48  protected $own_ids = array();
49 
56  private function __construct(ilECSSetting $setting = null)
57  {
58  global $ilLog;
59 
60  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
61  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
62  include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
63  include_once('Services/WebServices/ECS/classes/class.ilECSCommunity.php');
64 
65  if ($setting) {
66  $this->settings = $setting;
67  } else {
68  $GLOBALS['ilLog']->write(__METHOD__ . ': Using deprecated call');
69  $GLOBALS['ilLog']->logStack();
70  }
71  $this->connector = new ilECSConnector($this->settings);
72  $this->log = $ilLog;
73 
74  $this->read();
75  }
76 
84  public static function _getInstance()
85  {
86  $GLOBALS['ilLog']->write(__METHOD__ . ': Using deprecated call');
87  return self::getInstanceByServerId(15);
88  }
89 
95  public static function getInstanceByServerId($a_server_id)
96  {
97  if (isset(self::$instances[$a_server_id])) {
98  return self::$instances[$a_server_id];
99  }
100  return self::$instances[$a_server_id] = new ilECSCommunityReader(ilECSSetting::getInstanceByServerId($a_server_id));
101  }
102 
107  public function getServer()
108  {
109  return $this->settings;
110  }
111 
116  public function getParticipants()
117  {
118  return $this->participants;
119  }
120 
121 
128  public function getOwnMIDs()
129  {
130  return $this->own_ids ? $this->own_ids : array();
131  }
132 
139  public function getCommunities()
140  {
141  return $this->communities ? $this->communities : array();
142  }
143 
151  public function getCommunityById($a_id)
152  {
153  foreach ($this->communities as $community) {
154  if ($community->getId() == $a_id) {
155  return $community;
156  }
157  }
158  return null;
159  }
160 
165  public function getParticipantsByPid($a_pid)
166  {
167  $participants = [];
168  foreach ($this->getCommunities() as $community) {
169  foreach ($community->getParticipants() as $participant) {
170  if ($participant->getPid() == $a_pid) {
171  $participants[] = $participant;
172  }
173  }
174  }
175  return $participants;
176  }
177 
184  public function getParticipantByMID($a_mid)
185  {
186  return isset($this->participants[$a_mid]) ? $this->participants[$a_mid] : false;
187  }
188 
194  public function getCommunityByMID($a_mid)
195  {
196  foreach ($this->communities as $community) {
197  foreach ($community->getParticipants() as $part) {
198  if ($part->getMID() == $a_mid) {
199  return $community;
200  }
201  }
202  }
203  return null;
204  }
205 
212  public function getPublishableParticipants()
213  {
214  foreach ($this->getCommunities() as $community) {
215  foreach ($community->getParticipants() as $participant) {
216  if ($participant->isPublishable()) {
217  $p_part[] = $participant;
218  }
219  }
220  }
221  return $p_part ? $p_part : array();
222  }
223 
230  public function getEnabledParticipants()
231  {
232  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
233  $ps = ilECSParticipantSettings::getInstanceByServerId($this->getServer()->getServerId());
234  $en = $ps->getEnabledParticipants();
235  foreach ($this->getCommunities() as $community) {
236  foreach ($community->getParticipants() as $participant) {
237  if (in_array($participant->getMid(), $en)) {
238  $e_part[] = $participant;
239  }
240  }
241  }
242  return $e_part ? $e_part : array();
243  }
244 
251  private function read()
252  {
253  global $ilLog;
254 
255  try {
256  $res = $this->connector->getMemberships();
257  if (!is_array($res->getResult())) {
258  return false;
259  }
260  foreach ($res->getResult() as $community) {
261  $tmp_comm = new ilECSCommunity($community);
262  foreach ($tmp_comm->getParticipants() as $participant) {
263  $this->participants[$participant->getMID()] = $participant;
264  if ($participant->isSelf()) {
265  $this->own_ids[] = $participant->getMID();
266  }
267  }
268  $this->communities[] = $tmp_comm;
269  }
270  } catch (ilECSConnectorException $e) {
271  $ilLog->write(__METHOD__ . ': Error connecting to ECS server. ' . $e->getMessage());
272  throw $e;
273  }
274  }
275 }
getServer()
Get server setting.
getOwnMIDs()
get publishable ids
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
static _getInstance()
get singleton instance
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getParticipantByMID($a_mid)
get participant by id
__construct(ilECSSetting $setting=null)
Singleton constructor.
static getInstanceByServerId($a_server_id)
Get instance by server id.
static getInstanceByServerId($a_server_id)
Get instance by server id.
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
getCommunityById($a_id)
get community by id
settings()
Definition: settings.php:2
getEnabledParticipants()
get enabled participants
getPublishableParticipants()
get publishable communities
getCommunityByMID($a_mid)
Get community by mid.
getParticipants()
Get participants.