ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
59 
60  $ilLog = $DIC['ilLog'];
61 
62  include_once('Services/WebServices/ECS/classes/class.ilECSSetting.php');
63  include_once('Services/WebServices/ECS/classes/class.ilECSConnector.php');
64  include_once('Services/WebServices/ECS/classes/class.ilECSConnectorException.php');
65  include_once('Services/WebServices/ECS/classes/class.ilECSCommunity.php');
66 
67  if ($setting) {
68  $this->settings = $setting;
69  } else {
70  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Using deprecated call');
71  $GLOBALS['DIC']['ilLog']->logStack();
72  }
73  $this->connector = new ilECSConnector($this->settings);
74  $this->log = $ilLog;
75 
76  $this->read();
77  }
78 
86  public static function _getInstance()
87  {
88  $GLOBALS['DIC']['ilLog']->write(__METHOD__ . ': Using deprecated call');
89  return self::getInstanceByServerId(15);
90  }
91 
97  public static function getInstanceByServerId($a_server_id)
98  {
99  if (isset(self::$instances[$a_server_id])) {
100  return self::$instances[$a_server_id];
101  }
102  return self::$instances[$a_server_id] = new ilECSCommunityReader(ilECSSetting::getInstanceByServerId($a_server_id));
103  }
104 
109  public function getServer()
110  {
111  return $this->settings;
112  }
113 
118  public function getParticipants()
119  {
120  return $this->participants;
121  }
122 
123 
130  public function getOwnMIDs()
131  {
132  return $this->own_ids ? $this->own_ids : array();
133  }
134 
141  public function getCommunities()
142  {
143  return $this->communities ? $this->communities : array();
144  }
145 
153  public function getCommunityById($a_id)
154  {
155  foreach ($this->communities as $community) {
156  if ($community->getId() == $a_id) {
157  return $community;
158  }
159  }
160  return null;
161  }
162 
167  public function getParticipantsByPid($a_pid)
168  {
169  $participants = [];
170  foreach ($this->getCommunities() as $community) {
171  foreach ($community->getParticipants() as $participant) {
172  if ($participant->getPid() == $a_pid) {
173  $participants[] = $participant;
174  }
175  }
176  }
177  return $participants;
178  }
179 
186  public function getParticipantByMID($a_mid)
187  {
188  return isset($this->participants[$a_mid]) ? $this->participants[$a_mid] : false;
189  }
190 
196  public function getCommunityByMID($a_mid)
197  {
198  foreach ($this->communities as $community) {
199  foreach ($community->getParticipants() as $part) {
200  if ($part->getMID() == $a_mid) {
201  return $community;
202  }
203  }
204  }
205  return null;
206  }
207 
214  public function getPublishableParticipants()
215  {
216  foreach ($this->getCommunities() as $community) {
217  foreach ($community->getParticipants() as $participant) {
218  if ($participant->isPublishable()) {
219  $p_part[] = $participant;
220  }
221  }
222  }
223  return $p_part ? $p_part : array();
224  }
225 
232  public function getEnabledParticipants()
233  {
234  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
235  $ps = ilECSParticipantSettings::getInstanceByServerId($this->getServer()->getServerId());
236  $en = $ps->getEnabledParticipants();
237  foreach ($this->getCommunities() as $community) {
238  foreach ($community->getParticipants() as $participant) {
239  if (in_array($participant->getMid(), $en)) {
240  $e_part[] = $participant;
241  }
242  }
243  }
244  return $e_part ? $e_part : array();
245  }
246 
253  private function read()
254  {
255  global $DIC;
256 
257  $ilLog = $DIC['ilLog'];
258 
259  try {
260  $res = $this->connector->getMemberships();
261  if (!is_array($res->getResult())) {
262  return false;
263  }
264  foreach ($res->getResult() as $community) {
265  $tmp_comm = new ilECSCommunity($community);
266  foreach ($tmp_comm->getParticipants() as $participant) {
267  $this->participants[$participant->getMID()] = $participant;
268  if ($participant->isSelf()) {
269  $this->own_ids[] = $participant->getMID();
270  }
271  }
272  $this->communities[] = $tmp_comm;
273  }
274  } catch (ilECSConnectorException $e) {
275  $ilLog->write(__METHOD__ . ': Error connecting to ECS server. ' . $e->getMessage());
276  throw $e;
277  }
278  }
279 }
getServer()
Get server setting.
getOwnMIDs()
get publishable ids
settings()
Definition: settings.php:2
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
global $DIC
Definition: saml.php:7
static _getInstance()
get singleton instance
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
getCommunityById($a_id)
get community by id
getEnabledParticipants()
get enabled participants
getPublishableParticipants()
get publishable communities
getCommunityByMID($a_mid)
Get community by mid.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
getParticipants()
Get participants.