ILIAS  release_4-3 Revision
 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 
83  public static function getExportableParticipants()
84  {
85  global $ilDB;
86 
87  $query = 'SELECT sid,mid FROM ecs_part_settings ep '.
88  'JOIN ecs_server es ON ep.sid = es.server_id '.
89  'WHERE export = '.$ilDB->quote(1,'integer').' '.
90  'AND active = '.$ilDB->quote(1,'integer').' '.
91  'ORDER BY cname,es.title';
92 
93  $res = $ilDB->query($query);
94  $mids = array();
95  $counter = 0;
96  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
97  {
98  $mids[$counter]['sid'] = $row->sid;
99  $mids[$counter]['mid'] = $row->mid;
100  $counter++;
101  }
102  return $mids;
103  }
104 
110  public static function getExportServers()
111  {
112  global $ilDB;
113 
114  $query = 'SELECT DISTINCT(sid) FROM ecs_part_settings ep '.
115  'JOIN ecs_server es ON ep.sid = es.server_id '.
116  'WHERE export = '.$ilDB->quote(1,'integer').' '.
117  'AND active = '.$ilDB->quote(1,'integer').' ';
118  $res = $ilDB->query($query);
119  $sids = array();
120  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
121  {
122  $sids[] = $row->sid;
123  }
124  return $sids;
125  }
126 
132  public static function deleteByServer($a_server_id)
133  {
134  global $ilDB;
135 
136  $query = 'DELETE from ecs_part_settings '.
137  'WHERE sid = '.$ilDB->quote($a_server_id,'integer');
138  $ilDB->manipulate($query);
139  }
140 
146  public static function loookupCmsMid($a_server_id)
147  {
148  global $ilDB;
149 
150  include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
151 
152  $query = 'SELECT mid FROM ecs_part_settings '.
153  'WHERE sid = '.$ilDB->quote($a_server_id,'integer').' '.
154  'AND import_type = '.$ilDB->quote(ilECSParticipantSetting::IMPORT_CMS);
155  $res = $ilDB->query($query);
156  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
157  {
158  return $row->mid;
159  }
160  return 0;
161  }
162 
167  public function getServerId()
168  {
169  return $this->server_id;
170  }
171 
172 
177  public function read()
178  {
179  global $ilDB;
180 
181  $query = 'SELECT * FROM ecs_part_settings '.
182  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' ';
183  $res = $ilDB->query($query);
184  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
185  {
186  $this->export[$row->mid] = $row->export;
187  $this->import[$row->mid] = $row->import;
188  $this->import_type[$row->mid] = $row->import_type;
189  }
190  return true;
191  }
192 
198  public function isImportAllowed(array $a_mids)
199  {
200  foreach($a_mids as $mid)
201  {
202  if($this->import[$mid])
203  {
204  return true;
205  }
206  }
207  return false;
208  }
209 
216  public function getEnabledParticipants()
217  {
218  $ret = array();
219  foreach($this->export as $mid => $enabled)
220  {
221  if($enabled)
222  {
223  $ret[] = $mid;
224  }
225  }
226  return $ret;
227  #return $this->enabled ? $this->enabled : array();
228  }
229 
238  public function isEnabled($a_mid)
239  {
240  return $this->export[$a_mid] ? true : false;
241  }
242 
250  public function setEnabledParticipants($a_parts)
251  {
252  $this->enabled = (array) $a_parts;
253  }
254 }
255 ?>