ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilECSUtils.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
35{
36 const TYPE_ARRAY = 1;
37 const TYPE_INT = 2;
38 const TYPE_STRING = 3;
39 const TYPE_TIMEPLACE = 4;
40
47 public static function lookupParticipantName($a_owner, $a_server_id)
48 {
49 global $ilLog;
50
51 try {
52 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
54 if ($part = $reader->getParticipantByMID($a_owner)) {
55 return $part->getParticipantName();
56 }
57 return '';
58 } catch (ilECSConnectorException $e) {
59 $ilLog->write(__METHOD__ . ': Error reading participants.');
60 return '';
61 }
62 }
63
72 public static function _getOptionalEContentFields()
73 {
74 // :TODO: ?
75 $def = self::getEContentDefinition('/campusconnect/courselinks');
76 return array_keys($def);
77 }
78
87 public static function _getOptionalECourseFields()
88 {
89 // :TODO: ?
90 $def = self::getEContentDefinition('/campusconnect/courselinks');
91 return array_keys($def);
92 }
93
100 public static function getPossibleRemoteTypes($a_with_captions = false)
101 {
102 global $lng;
103
104 $all = array("rcrs", "rcat", "rfil", "rglo", "rgrp", "rlm", "rwik");
105
106 if (!$a_with_captions) {
107 return $all;
108 }
109
110 $res = array();
111 foreach ($all as $id) {
112 $res[$id] = $lng->txt("obj_" . $id);
113 }
114 return $res;
115 }
116
123 public static function getPossibleReleaseTypes($a_with_captions = false)
124 {
125 global $lng;
126
127 $all = array("crs", "cat", "file", "glo", "grp", "lm", "wiki");
128
129 if (!$a_with_captions) {
130 return $all;
131 }
132
133 $res = array();
134 foreach ($all as $id) {
135 $res[$id] = $lng->txt("obj_" . $id);
136 }
137 return $res;
138 }
139
146 public static function getEContentDefinition($a_resource_id)
147 {
148 switch ($a_resource_id) {
149 case '/campusconnect/courselinks':
150 return array(
151 'study_courses' => self::TYPE_ARRAY,
152 'lecturer' => self::TYPE_ARRAY,
153 'courseType' => self::TYPE_STRING,
154 'courseID' => self::TYPE_INT,
155 'credits' => self::TYPE_INT,
156 'semester_hours' => self::TYPE_INT,
157 'term' => self::TYPE_STRING,
158 'begin' => array(self::TYPE_TIMEPLACE, 'timePlace'),
159 'end' => array(self::TYPE_TIMEPLACE, 'timePlace'),
160 'room' => array(self::TYPE_TIMEPLACE, 'timePlace'),
161 'cycle' => array(self::TYPE_TIMEPLACE, 'timePlace')
162 );
163
164 case '/campusconnect/categories':
165 case '/campusconnect/files':
166 case '/campusconnect/glossaries':
167 case '/campusconnect/groups':
168 case '/campusconnect/learningmodules':
169 case '/campusconnect/wikis':
170 // no metadata mapping yet
171 return array();
172 }
173 }
174
184 public static function getMatchableContent($a_resource_id, $a_server_id, $a_ecs_content, $a_owner)
185 {
186 include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
187 include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
188
189 // see ilECSCategoryMapping::getPossibleFields();
190 $res = array();
191 $res["part_id"] = array($a_owner, ilECSCategoryMappingRule::ATTR_INT);
192 $res["community"] = array(ilECSCommunitiesCache::getInstance()->lookupTitle($a_server_id, $a_owner),
194
195 $definition = self::getEContentDefinition($a_resource_id);
196
197 $timePlace = null;
198 foreach ($definition as $id => $type) {
199 if (is_array($type)) {
200 $target = $type[1];
201 $type = $type[0];
202 } else {
203 $target = $id;
204 }
205 switch ($type) {
207 $value = array(implode(',', (array) $a_ecs_content->$target), ilECSCategoryMappingRule::ATTR_ARRAY);
208 break;
209
211 $value = array((int) $a_ecs_content->$target, ilECSCategoryMappingRule::ATTR_INT);
212 break;
213
215 $value = array((string) $a_ecs_content->$target, ilECSCategoryMappingRule::ATTR_STRING);
216 break;
217
219 if (!is_object($timePlace)) {
220 include_once('./Services/WebServices/ECS/classes/class.ilECSTimePlace.php');
221 if (is_object($a_ecs_content->$target)) {
222 $timePlace = new ilECSTimePlace();
223 $timePlace->loadFromJSON($a_ecs_content->$target);
224 } else {
225 $timePlace = new ilECSTimePlace();
226 }
227 }
228 switch ($id) {
229 case 'begin':
230 case 'end':
231 $value = array($timePlace->{'getUT' . ucfirst($id)}(),
233 break;
234
235 case 'room':
236 case 'cycle':
237 $value = array($timePlace->{'get' . ucfirst($id)}(),
239 break;
240 }
241 break;
242 }
243
244 $res[$id] = $value;
245 }
246
247 return $res;
248 }
249
256 public static function getAdvancedMDValuesForObjId($a_obj_id)
257 {
258 $res = array();
259
260 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
261
262 // getting all records
263 foreach (ilAdvancedMDValues::getInstancesForObjectId($a_obj_id) as $a_values) {
264 // this correctly binds group and definitions
265 $a_values->read();
266
267 // getting elements for record
268 $defs = $a_values->getDefinitions();
269 foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) {
270 if (!$element->isNull()) {
271 // :TODO: using this for a "flat" presentation
272 $res[$element_id] = $defs[$element_id]->getValueForXML($element);
273 } else {
274 // :TODO: is this needed?
275 $res[$element_id] = null;
276 }
277 }
278 }
279
280 return $res;
281 }
282}
An exception for terminatinating execution or to throw for unit testing.
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
static getInstance()
Singleton instance.
static getInstanceByServerId($a_server_id)
Get instance by server id.
Representation of ECS EContent Time Place.
static getPossibleRemoteTypes($a_with_captions=false)
Get all possible remote object types.
static getEContentDefinition($a_resource_id)
Get econtent / metadata definition.
static getMatchableContent($a_resource_id, $a_server_id, $a_ecs_content, $a_owner)
Convert ECS content to rule matchable values.
static getAdvancedMDValuesForObjId($a_obj_id)
Get advanced metadata values for object id.
static getPossibleReleaseTypes($a_with_captions=false)
Get all possible release object types.
static lookupParticipantName($a_owner, $a_server_id)
Lookup participant name.
static _getOptionalECourseFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions
const TYPE_TIMEPLACE
static _getOptionalEContentFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions
$def
Definition: croninfo.php:21
if(!array_key_exists('StateId', $_REQUEST)) $id
global $lng
Definition: privfeed.php:17
$type
foreach($_POST as $key=> $value) $res