ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
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');
90  return self::getInstanceByServerId(15);
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 
116 
123  public function getOwnMIDs()
124  {
125  return $this->own_ids ? $this->own_ids : array();
126  }
127 
135  public function getCommunities()
136  {
137  return $this->communities ? $this->communities : array();
138  }
139 
147  public function getCommunityById($a_id)
148  {
149  foreach($this->communities as $community)
150  {
151  if($community->getId() == $a_id)
152  {
153  return $community;
154  }
155  }
156  return null;
157  }
158 
165  public function getParticipantByMID($a_mid)
166  {
167  return isset($this->participants[$a_mid]) ? $this->participants[$a_mid] : false;
168  }
169 
175  public function getCommunityByMID($a_mid)
176  {
177  foreach($this->communities as $community)
178  {
179  foreach($community->getParticipants() as $part)
180  {
181  if($part->getMID() == $a_mid)
182  {
183  return $community;
184  }
185  }
186  }
187  return null;
188  }
189 
196  public function getPublishableParticipants()
197  {
198  foreach($this->getCommunities() as $community)
199  {
200  foreach($community->getParticipants() as $participant)
201  {
202  if($participant->isPublishable())
203  {
204  $p_part[] = $participant;
205  }
206  }
207  }
208  return $p_part ? $p_part : array();
209  }
210 
217  public function getEnabledParticipants()
218  {
219  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSettings.php';
220  $ps = ilECSParticipantSettings::getInstanceByServerId($this->getServer()->getServerId());
221  $en = $ps->getEnabledParticipants();
222  foreach($this->getCommunities() as $community)
223  {
224  foreach($community->getParticipants() as $participant)
225  {
226  if(in_array($participant->getMid(), $en))
227  {
228  $e_part[] = $participant;
229  }
230  }
231  }
232  return $e_part ? $e_part : array();
233  }
234 
241  private function read()
242  {
243  global $ilLog;
244 
245  try
246  {
247  $res = $this->connector->getMemberships();
248  if(!is_array($res->getResult()))
249  {
250  return false;
251  }
252  foreach($res->getResult() as $community)
253  {
254  $tmp_comm = new ilECSCommunity($community);
255  foreach($tmp_comm->getParticipants() as $participant)
256  {
257  $this->participants[$participant->getMID()] = $participant;
258  if($participant->isSelf())
259  {
260  $this->own_ids[] = $participant->getMID();
261  }
262  }
263  $this->communities[] = $tmp_comm;
264  }
265  }
266  catch(ilECSConnectorException $e)
267  {
268  $ilLog->write(__METHOD__.': Error connecting to ECS server. '.$e->getMessage());
269  throw $e;
270  }
271  }
272 }
273 ?>