ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
56  return $part->getParticipantName();
57  }
58  return '';
59  }
60  catch(ilECSConnectorException $e)
61  {
62  $ilLog->write(__METHOD__.': Error reading participants.');
63  return '';
64  }
65  }
66 
75  public static function _getOptionalEContentFields()
76  {
77  // :TODO: ?
78  $def = self::getEContentDefinition('/campusconnect/courselinks');
79  return array_keys($def);
80  }
81 
90  public static function _getOptionalECourseFields()
91  {
92  // :TODO: ?
93  $def = self::getEContentDefinition('/campusconnect/courselinks');
94  return array_keys($def);
95  }
96 
103  public static function getPossibleRemoteTypes($a_with_captions = false)
104  {
105  global $lng;
106 
107  $all = array("rcrs", "rcat", "rfil", "rglo", "rgrp", "rlm", "rwik");
108 
109  if(!$a_with_captions)
110  {
111  return $all;
112  }
113 
114  $res = array();
115  foreach($all as $id)
116  {
117  $res[$id] = $lng->txt("obj_".$id);
118  }
119  return $res;
120  }
121 
128  public static function getPossibleReleaseTypes($a_with_captions = false)
129  {
130  global $lng;
131 
132  $all = array("crs", "cat", "file", "glo", "grp", "lm", "wiki");
133 
134  if(!$a_with_captions)
135  {
136  return $all;
137  }
138 
139  $res = array();
140  foreach($all as $id)
141  {
142  $res[$id] = $lng->txt("obj_".$id);
143  }
144  return $res;
145  }
146 
153  public static function getEContentDefinition($a_resource_id)
154  {
155  switch($a_resource_id)
156  {
157  case '/campusconnect/courselinks':
158  return array(
159  'study_courses' => self::TYPE_ARRAY,
160  'lecturer' => self::TYPE_ARRAY,
161  'courseType' => self::TYPE_STRING,
162  'courseID' => self::TYPE_INT,
163  'credits' => self::TYPE_INT,
164  'semester_hours' => self::TYPE_INT,
165  'term' => self::TYPE_STRING,
166  'begin' => array(self::TYPE_TIMEPLACE, 'timePlace'),
167  'end' => array(self::TYPE_TIMEPLACE, 'timePlace'),
168  'room' => array(self::TYPE_TIMEPLACE, 'timePlace'),
169  'cycle' => array(self::TYPE_TIMEPLACE, 'timePlace')
170  );
171 
172  case '/campusconnect/categories':
173  case '/campusconnect/files':
174  case '/campusconnect/glossaries':
175  case '/campusconnect/groups':
176  case '/campusconnect/learningmodules':
177  case '/campusconnect/wikis':
178  // no metadata mapping yet
179  return array();
180  }
181  }
182 
192  public static function getMatchableContent($a_resource_id, $a_server_id, $a_ecs_content, $a_owner)
193  {
194  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
195  include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
196 
197  // see ilECSCategoryMapping::getPossibleFields();
198  $res = array();
199  $res["part_id"] = array($a_owner, ilECSCategoryMappingRule::ATTR_INT);
200  $res["community"] = array(ilECSCommunitiesCache::getInstance()->lookupTitle($a_server_id, $a_owner),
202 
203  $definition = self::getEContentDefinition($a_resource_id);
204 
205  $timePlace = null;
206  foreach($definition as $id => $type)
207  {
208  if(is_array($type))
209  {
210  $target = $type[1];
211  $type = $type[0];
212  }
213  else
214  {
215  $target = $id;
216  }
217  switch($type)
218  {
220  $value = array(implode(',', (array) $a_ecs_content->$target), ilECSCategoryMappingRule::ATTR_ARRAY);
221  break;
222 
224  $value = array((int)$a_ecs_content->$target, ilECSCategoryMappingRule::ATTR_INT);
225  break;
226 
228  $value = array((string)$a_ecs_content->$target, ilECSCategoryMappingRule::ATTR_STRING);
229  break;
230 
232  if(!is_object($timePlace))
233  {
234  include_once('./Services/WebServices/ECS/classes/class.ilECSTimePlace.php');
235  if(is_object($a_ecs_content->$target))
236  {
237  $timePlace = new ilECSTimePlace();
238  $timePlace->loadFromJSON($a_ecs_content->$target);
239  }
240  else
241  {
242  $timePlace = new ilECSTimePlace();
243  }
244  }
245  switch($id)
246  {
247  case 'begin':
248  case 'end':
249  $value = array($timePlace->{'getUT'.ucfirst($id)}(),
251  break;
252 
253  case 'room':
254  case 'cycle':
255  $value = array($timePlace->{'get'.ucfirst($id)}(),
257  break;
258  }
259  break;
260  }
261 
262  $res[$id] = $value;
263  }
264 
265  return $res;
266  }
267 
274  public static function getAdvancedMDValuesForObjId($a_obj_id)
275  {
276  $res = array();
277 
278  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
279 
280  // getting all records
281  foreach(ilAdvancedMDValues::getInstancesForObjectId($a_obj_id) as $a_values)
282  {
283  // this correctly binds group and definitions
284  $a_values->read();
285 
286  // getting elements for record
287  $defs = $a_values->getDefinitions();
288  foreach($a_values->getADTGroup()->getElements() as $element_id => $element)
289  {
290  if(!$element->isNull())
291  {
292  // :TODO: using this for a "flat" presentation
293  $res[$element_id] = $defs[$element_id]->getValueForXML($element);
294  }
295  else
296  {
297  // :TODO: is this needed?
298  $res[$element_id] = null;
299  }
300  }
301  }
302 
303  return $res;
304  }
305 }
306 
307 ?>