ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
67 $this->settings = $setting;
68 }
69 else
70 {
71 $GLOBALS['ilLog']->write(__METHOD__.': Using deprecated call');
72 $GLOBALS['ilLog']->logStack();
73 }
74 $this->connector = new ilECSConnector($this->settings);
75 $this->log = $ilLog;
76
77 $this->read();
78 }
79
87 public static function _getInstance()
88 {
89 $GLOBALS['ilLog']->write(__METHOD__.': Using deprecated call');
91 }
92
98 public static function getInstanceByServerId($a_server_id)
99 {
100 if(isset(self::$instances[$a_server_id]))
101 {
102 return self::$instances[$a_server_id];
103 }
104 return self::$instances[$a_server_id] = new ilECSCommunityReader(ilECSSetting::getInstanceByServerId($a_server_id));
105 }
106
111 public function getServer()
112 {
113 return $this->settings;
114 }
115
120 public function getParticipants()
121 {
122 return $this->participants;
123 }
124
125
132 public function getOwnMIDs()
133 {
134 return $this->own_ids ? $this->own_ids : array();
135 }
136
144 public function getCommunities()
145 {
146 return $this->communities ? $this->communities : array();
147 }
148
156 public function getCommunityById($a_id)
157 {
158 foreach($this->communities as $community)
159 {
160 if($community->getId() == $a_id)
161 {
162 return $community;
163 }
164 }
165 return null;
166 }
167
174 public function getParticipantByMID($a_mid)
175 {
176 return isset($this->participants[$a_mid]) ? $this->participants[$a_mid] : false;
177 }
178
184 public function getCommunityByMID($a_mid)
185 {
186 foreach($this->communities as $community)
187 {
188 foreach($community->getParticipants() as $part)
189 {
190 if($part->getMID() == $a_mid)
191 {
192 return $community;
193 }
194 }
195 }
196 return null;
197 }
198
206 {
207 foreach($this->getCommunities() as $community)
208 {
209 foreach($community->getParticipants() as $participant)
210 {
211 if($participant->isPublishable())
212 {
213 $p_part[] = $participant;
214 }
215 }
216 }
217 return $p_part ? $p_part : array();
218 }
219
226 public function getEnabledParticipants()
227 {
228 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
229 $ps = ilECSParticipantSettings::getInstanceByServerId($this->getServer()->getServerId());
230 $en = $ps->getEnabledParticipants();
231 foreach($this->getCommunities() as $community)
232 {
233 foreach($community->getParticipants() as $participant)
234 {
235 if(in_array($participant->getMid(), $en))
236 {
237 $e_part[] = $participant;
238 }
239 }
240 }
241 return $e_part ? $e_part : array();
242 }
243
250 private function read()
251 {
252 global $ilLog;
253
254 try
255 {
256 $res = $this->connector->getMemberships();
257 if(!is_array($res->getResult()))
258 {
259 return false;
260 }
261 foreach($res->getResult() as $community)
262 {
263 $tmp_comm = new ilECSCommunity($community);
264 foreach($tmp_comm->getParticipants() as $participant)
265 {
266 $this->participants[$participant->getMID()] = $participant;
267 if($participant->isSelf())
268 {
269 $this->own_ids[] = $participant->getMID();
270 }
271 }
272 $this->communities[] = $tmp_comm;
273 }
274 }
276 {
277 $ilLog->write(__METHOD__.': Error connecting to ECS server. '.$e->getMessage());
278 throw $e;
279 }
280 }
281}
282?>
getEnabledParticipants()
get enabled participants
getCommunityById($a_id)
get community by id
static getInstanceByServerId($a_server_id)
Get instance by server id.
getPublishableParticipants()
get publishable communities
getCommunityByMID($a_mid)
Get community by mid.
__construct(ilECSSetting $setting=null)
Singleton constructor.
static _getInstance()
get singleton instance
getParticipantByMID($a_mid)
get participant by id
static getInstanceByServerId($a_server_id)
Get instance by server id.
static getInstanceByServerId($a_server_id)
Get singleton instance per server.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276