ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSParticipantSettings.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 
33 {
34  private static $instances = null;
35 
36  private $export = array();
37  private $import = array();
38  private $export_type = array();
39 
46  private function __construct($a_server_id)
47  {
48  $this->server_id = $a_server_id;
49  $this->read();
50  }
51 
59  public static function _getInstance()
60  {
61  $GLOBALS['ilLog']->write(__METHOD__.': Using deprecated call');
62  $GLOBALS['ilLog']->logStack();
63  return self::getInstanceByServerId(15);
64  }
65 
71  public static function getInstanceByServerId($a_server_id)
72  {
73  if(isset(self::$instances[$a_server_id]))
74  {
75  return self::$instances[$a_server_id];
76  }
77  return self::$instances[$a_server_id] = new ilECSParticipantSettings($a_server_id);
78  }
79 
86  public static function getAvailabeMids($a_server_id)
87  {
88  global $ilDB;
89 
90  $query = 'SELECT mid FROM ecs_part_settings '.
91  'WHERE sid = '.$ilDB->quote($a_server_id,'integer');
92  $res = $ilDB->query($query);
93 
94  $mids = array();
95  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
96  {
97  $mids[] = $row->mid;
98  }
99  return $mids;
100  }
101 
102 
106  public static function getExportableParticipants($a_type)
107  {
108  global $ilDB;
109 
110  $query = 'SELECT sid,mid,export_types FROM ecs_part_settings ep '.
111  'JOIN ecs_server es ON ep.sid = es.server_id '.
112  'WHERE export = '.$ilDB->quote(1,'integer').' '.
113  'AND active = '.$ilDB->quote(1,'integer').' '.
114  'ORDER BY cname,es.title';
115 
116  $res = $ilDB->query($query);
117  $mids = array();
118  $counter = 0;
119  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
120  {
121  if(in_array($a_type, (array) unserialize($row->export_types)))
122  {
123  $mids[$counter]['sid'] = $row->sid;
124  $mids[$counter]['mid'] = $row->mid;
125  $counter++;
126  }
127  }
128  return $mids;
129  }
130 
136  public static function getExportServers()
137  {
138  global $ilDB;
139 
140  $query = 'SELECT DISTINCT(sid) FROM ecs_part_settings ep '.
141  'JOIN ecs_server es ON ep.sid = es.server_id '.
142  'WHERE export = '.$ilDB->quote(1,'integer').' '.
143  'AND active = '.$ilDB->quote(1,'integer').' ';
144  $res = $ilDB->query($query);
145  $sids = array();
146  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
147  {
148  $sids[] = $row->sid;
149  }
150  return $sids;
151  }
152 
158  public static function deleteByServer($a_server_id)
159  {
160  global $ilDB;
161 
162  $query = 'DELETE from ecs_part_settings '.
163  'WHERE sid = '.$ilDB->quote($a_server_id,'integer');
164  $ilDB->manipulate($query);
165  }
166 
172  public static function loookupCmsMid($a_server_id)
173  {
174  global $ilDB;
175 
176  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
177 
178  $query = 'SELECT mid FROM ecs_part_settings '.
179  'WHERE sid = '.$ilDB->quote($a_server_id,'integer').' '.
180  'AND import_type = '.$ilDB->quote(ilECSParticipantSetting::IMPORT_CMS);
181  $res = $ilDB->query($query);
182  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
183  {
184  return $row->mid;
185  }
186  return 0;
187  }
188 
193  public function getServerId()
194  {
195  return $this->server_id;
196  }
197 
198 
203  public function read()
204  {
205  global $ilDB;
206 
207  $query = 'SELECT * FROM ecs_part_settings '.
208  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' ';
209  $res = $ilDB->query($query);
210  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
211  {
212  $this->export[$row->mid] = $row->export;
213  $this->import[$row->mid] = $row->import;
214  $this->import_type[$row->mid] = $row->import_type;
215  $this->export_types[$row->mid] = (array) unserialize($row->export_types);
216  $this->import_types[$row->mid] = (array) unserialize($row->import_types);
217  }
218  return true;
219  }
220 
226  public function isImportAllowed(array $a_mids)
227  {
228  foreach($a_mids as $mid)
229  {
230  if($this->import[$mid])
231  {
232  return true;
233  }
234  }
235  return false;
236  }
237 
244  public function getEnabledParticipants()
245  {
246  $ret = array();
247  foreach($this->export as $mid => $enabled)
248  {
249  if($enabled)
250  {
251  $ret[] = $mid;
252  }
253  }
254  return $ret;
255  #return $this->enabled ? $this->enabled : array();
256  }
257 
266  public function isEnabled($a_mid)
267  {
268  return $this->export[$a_mid] ? true : false;
269  }
270 
278  public function setEnabledParticipants($a_parts)
279  {
280  $this->enabled = (array) $a_parts;
281  }
282 }
283 ?>