ILIAS  Release_4_0_x_branch Revision 61816
 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 $instance = 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()
57  {
58  global $ilLog;
59 
60  include_once('Services/WebServices/ECS/classes/class.ilECSSettings.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  $this->settings = ilECSSettings::_getInstance();
66  $this->connector = new ilECSConnector();
67  $this->log = $ilLog;
68 
69  $this->read();
70  }
71 
79  public static function _getInstance()
80  {
81  if(self::$instance)
82  {
83  return self::$instance;
84  }
85  return self::$instance = new ilECSCommunityReader();
86  }
87 
94  public function getOwnMIDs()
95  {
96  return $this->own_ids ? $this->own_ids : array();
97  }
98 
106  public function getCommunities()
107  {
108  return $this->communities ? $this->communities : array();
109  }
110 
118  public function getCommunityById($a_id)
119  {
120  foreach($this->communities as $community)
121  {
122  if($community->getId() == $a_id)
123  {
124  return $community;
125  }
126  }
127  return null;
128  }
129 
136  public function getParticipantByMID($a_mid)
137  {
138  return isset($this->participants[$a_mid]) ? $this->participants[$a_mid] : false;
139 
140  }
141 
148  public function getPublishableParticipants()
149  {
150  foreach($this->getCommunities() as $community)
151  {
152  foreach($community->getParticipants() as $participant)
153  {
154  if($participant->isPublishable())
155  {
156  $p_part[] = $participant;
157  }
158  }
159  }
160  return $p_part ? $p_part : array();
161  }
162 
169  public function getEnabledParticipants()
170  {
171  foreach($this->getCommunities() as $community)
172  {
173  foreach($community->getParticipants() as $participant)
174  {
175  if($participant->isEnabled())
176  {
177  $e_part[] = $participant;
178  }
179  }
180  }
181  return $e_part ? $e_part : array();
182  }
183 
191  private function read()
192  {
193  global $ilLog;
194 
195  try
196  {
197  $res = $this->connector->getMemberships();
198  if(!is_array($res->getResult()))
199  {
200  return false;
201  }
202  foreach($res->getResult() as $community)
203  {
204  $tmp_comm = new ilECSCommunity($community);
205  foreach($tmp_comm->getParticipants() as $participant)
206  {
207  $this->participants[$participant->getMID()] = $participant;
208  if($participant->isSelf())
209  {
210  $this->own_ids[] = $participant->getMID();
211  }
212  }
213  $this->communities[] = $tmp_comm;
214  }
215 
216  }
217  catch(ilECSConnectorException $e)
218  {
219  $ilLog->write(__METHOD__.': Error connecting to ECS server. '.$e->getMessage());
220  throw $e;
221  }
222  }
223  /*
224  // Iterator methods
225  public function rewind()
226  {
227  $this->position = 0;
228  }
229 
230  public function valid()
231  {
232  return $this->position < sizeof($this->communities);
233  }
234 
235  public function key()
236  {
237  return $this->position;
238  }
239 
240  public function current()
241  {
242  return $this->communities[$this->position];
243  }
244 
245  public function next()
246  {
247  $this->position++;
248  }
249  */
250 }
251 ?>