ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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();
64 }
65
71 public static function getInstanceByServerId($a_server_id)
72 {
73 if (isset(self::$instances[$a_server_id])) {
74 return self::$instances[$a_server_id];
75 }
76 return self::$instances[$a_server_id] = new ilECSParticipantSettings($a_server_id);
77 }
78
85 public static function getAvailabeMids($a_server_id)
86 {
87 global $ilDB;
88
89 $query = 'SELECT mid FROM ecs_part_settings ' .
90 'WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
91 $res = $ilDB->query($query);
92
93 $mids = array();
94 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
95 $mids[] = $row->mid;
96 }
97 return $mids;
98 }
99
100
104 public static function getExportableParticipants($a_type)
105 {
106 global $ilDB;
107
108 $query = 'SELECT sid,mid,export_types FROM ecs_part_settings ep ' .
109 'JOIN ecs_server es ON ep.sid = es.server_id ' .
110 'WHERE export = ' . $ilDB->quote(1, 'integer') . ' ' .
111 'AND active = ' . $ilDB->quote(1, 'integer') . ' ' .
112 'ORDER BY cname,es.title';
113
114 $res = $ilDB->query($query);
115 $mids = array();
116 $counter = 0;
117 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
118 if (in_array($a_type, (array) unserialize($row->export_types))) {
119 $mids[$counter]['sid'] = $row->sid;
120 $mids[$counter]['mid'] = $row->mid;
121 $counter++;
122 }
123 }
124 return $mids;
125 }
126
132 public static function getExportServers()
133 {
134 global $ilDB;
135
136 $query = 'SELECT DISTINCT(sid) FROM ecs_part_settings ep ' .
137 'JOIN ecs_server es ON ep.sid = es.server_id ' .
138 'WHERE export = ' . $ilDB->quote(1, 'integer') . ' ' .
139 'AND active = ' . $ilDB->quote(1, 'integer') . ' ';
140 $res = $ilDB->query($query);
141 $sids = array();
142 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
143 $sids[] = $row->sid;
144 }
145 return $sids;
146 }
147
153 public static function deleteByServer($a_server_id)
154 {
155 global $ilDB;
156
157 $query = 'DELETE from ecs_part_settings ' .
158 'WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
159 $ilDB->manipulate($query);
160 }
161
167 public static function loookupCmsMid($a_server_id)
168 {
169 global $ilDB;
170
171 include_once './Services/WebServices/ECS/classes/class.ilECSParticipantSetting.php';
172
173 $query = 'SELECT mid FROM ecs_part_settings ' .
174 'WHERE sid = ' . $ilDB->quote($a_server_id, 'integer') . ' ' .
175 'AND import_type = ' . $ilDB->quote(ilECSParticipantSetting::IMPORT_CMS);
176 $res = $ilDB->query($query);
177 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
178 return $row->mid;
179 }
180 return 0;
181 }
182
187 public function getServerId()
188 {
189 return $this->server_id;
190 }
191
192
197 public function read()
198 {
199 global $ilDB;
200
201 $query = 'SELECT * FROM ecs_part_settings ' .
202 'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ';
203 $res = $ilDB->query($query);
204 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
205 $this->export[$row->mid] = $row->export;
206 $this->import[$row->mid] = $row->import;
207 $this->import_type[$row->mid] = $row->import_type;
208 $this->export_types[$row->mid] = (array) unserialize($row->export_types);
209 $this->import_types[$row->mid] = (array) unserialize($row->import_types);
210 }
211 return true;
212 }
213
219 public function isImportAllowed(array $a_mids)
220 {
221 foreach ($a_mids as $mid) {
222 if ($this->import[$mid]) {
223 return true;
224 }
225 }
226 return false;
227 }
228
235 public function getEnabledParticipants()
236 {
237 $ret = array();
238 foreach ($this->export as $mid => $enabled) {
239 if ($enabled) {
240 $ret[] = $mid;
241 }
242 }
243 return $ret;
244 #return $this->enabled ? $this->enabled : array();
245 }
246
255 public function isEnabled($a_mid)
256 {
257 return $this->export[$a_mid] ? true : false;
258 }
259
267 public function setEnabledParticipants($a_parts)
268 {
269 $this->enabled = (array) $a_parts;
270 }
271}
An exception for terminatinating execution or to throw for unit testing.
__construct($a_server_id)
Constructor (Singleton)
isEnabled($a_mid)
is partivcipant enabled
static getExportServers()
Get server ids which allow an export @global <type> $ilDB.
getEnabledParticipants()
get number of participants that are enabled
static getInstanceByServerId($a_server_id)
Get instance by server id.
static getExportableParticipants($a_type)
Get participants which are enabled and export is allowed.
static getAvailabeMids($a_server_id)
Get all available mids @global $ilDB.
static loookupCmsMid($a_server_id)
Lookup mid of current cms participant @global $ilDB.
static deleteByServer($a_server_id)
Delete by server @global $ilDB.
isImportAllowed(array $a_mids)
Check if import is allowed for scecific mid.
setEnabledParticipants($a_parts)
set enabled participants by community
$counter
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$ret
Definition: parser.php:6
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$a_type
Definition: workflow.php:92