ILIAS  Release_4_4_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()
107  {
108  global $ilDB;
109 
110  $query = 'SELECT sid,mid 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  $mids[$counter]['sid'] = $row->sid;
122  $mids[$counter]['mid'] = $row->mid;
123  $counter++;
124  }
125  return $mids;
126  }
127 
133  public static function getExportServers()
134  {
135  global $ilDB;
136 
137  $query = 'SELECT DISTINCT(sid) FROM ecs_part_settings ep '.
138  'JOIN ecs_server es ON ep.sid = es.server_id '.
139  'WHERE export = '.$ilDB->quote(1,'integer').' '.
140  'AND active = '.$ilDB->quote(1,'integer').' ';
141  $res = $ilDB->query($query);
142  $sids = array();
143  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
144  {
145  $sids[] = $row->sid;
146  }
147  return $sids;
148  }
149 
155  public static function deleteByServer($a_server_id)
156  {
157  global $ilDB;
158 
159  $query = 'DELETE from ecs_part_settings '.
160  'WHERE sid = '.$ilDB->quote($a_server_id,'integer');
161  $ilDB->manipulate($query);
162  }
163 
169  public static function loookupCmsMid($a_server_id)
170  {
171  global $ilDB;
172 
173  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
174 
175  $query = 'SELECT mid FROM ecs_part_settings '.
176  'WHERE sid = '.$ilDB->quote($a_server_id,'integer').' '.
177  'AND import_type = '.$ilDB->quote(ilECSParticipantSetting::IMPORT_CMS);
178  $res = $ilDB->query($query);
179  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
180  {
181  return $row->mid;
182  }
183  return 0;
184  }
185 
190  public function getServerId()
191  {
192  return $this->server_id;
193  }
194 
195 
200  public function read()
201  {
202  global $ilDB;
203 
204  $query = 'SELECT * FROM ecs_part_settings '.
205  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' ';
206  $res = $ilDB->query($query);
207  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
208  {
209  $this->export[$row->mid] = $row->export;
210  $this->import[$row->mid] = $row->import;
211  $this->import_type[$row->mid] = $row->import_type;
212  }
213  return true;
214  }
215 
221  public function isImportAllowed(array $a_mids)
222  {
223  foreach($a_mids as $mid)
224  {
225  if($this->import[$mid])
226  {
227  return true;
228  }
229  }
230  return false;
231  }
232 
239  public function getEnabledParticipants()
240  {
241  $ret = array();
242  foreach($this->export as $mid => $enabled)
243  {
244  if($enabled)
245  {
246  $ret[] = $mid;
247  }
248  }
249  return $ret;
250  #return $this->enabled ? $this->enabled : array();
251  }
252 
261  public function isEnabled($a_mid)
262  {
263  return $this->export[$a_mid] ? true : false;
264  }
265 
273  public function setEnabledParticipants($a_parts)
274  {
275  $this->enabled = (array) $a_parts;
276  }
277 }
278 ?>