ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
50 
51  $ilLog = $DIC['ilLog'];
52 
53  try {
54  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
56  if ($part = $reader->getParticipantByMID($a_owner)) {
57  return $part->getParticipantName();
58  }
59  return '';
60  } catch (ilECSConnectorException $e) {
61  $ilLog->write(__METHOD__ . ': Error reading participants.');
62  return '';
63  }
64  }
65 
74  public static function _getOptionalEContentFields()
75  {
76  // :TODO: ?
77  $def = self::getEContentDefinition('/campusconnect/courselinks');
78  return array_keys($def);
79  }
80 
89  public static function _getOptionalECourseFields()
90  {
91  // :TODO: ?
92  $def = self::getEContentDefinition('/campusconnect/courselinks');
93  return array_keys($def);
94  }
95 
102  public static function getPossibleRemoteTypes($a_with_captions = false)
103  {
104  global $DIC;
105 
106  $lng = $DIC['lng'];
107 
108  $all = array("rcrs", "rcat", "rfil", "rglo", "rgrp", "rlm", "rwik");
109 
110  if (!$a_with_captions) {
111  return $all;
112  }
113 
114  $res = array();
115  foreach ($all as $id) {
116  $res[$id] = $lng->txt("obj_" . $id);
117  }
118  return $res;
119  }
120 
127  public static function getPossibleReleaseTypes($a_with_captions = false)
128  {
129  global $DIC;
130 
131  $lng = $DIC['lng'];
132 
133  $all = array("crs", "cat", "file", "glo", "grp", "lm", "wiki");
134 
135  if (!$a_with_captions) {
136  return $all;
137  }
138 
139  $res = array();
140  foreach ($all as $id) {
141  $res[$id] = $lng->txt("obj_" . $id);
142  }
143  return $res;
144  }
145 
152  public static function getEContentDefinition($a_resource_id)
153  {
154  switch ($a_resource_id) {
155  case '/campusconnect/courselinks':
156  return array(
157  'study_courses' => self::TYPE_ARRAY,
158  'lecturer' => self::TYPE_ARRAY,
159  'courseType' => self::TYPE_STRING,
160  'courseID' => self::TYPE_INT,
161  'credits' => self::TYPE_INT,
162  'semester_hours' => self::TYPE_INT,
163  'term' => self::TYPE_STRING,
164  'begin' => array(self::TYPE_TIMEPLACE, 'timePlace'),
165  'end' => array(self::TYPE_TIMEPLACE, 'timePlace'),
166  'room' => array(self::TYPE_TIMEPLACE, 'timePlace'),
167  'cycle' => array(self::TYPE_TIMEPLACE, 'timePlace')
168  );
169 
170  case '/campusconnect/categories':
171  case '/campusconnect/files':
172  case '/campusconnect/glossaries':
173  case '/campusconnect/groups':
174  case '/campusconnect/learningmodules':
175  case '/campusconnect/wikis':
176  // no metadata mapping yet
177  return array();
178  }
179  }
180 
190  public static function getMatchableContent($a_resource_id, $a_server_id, $a_ecs_content, $a_owner)
191  {
192  include_once './Services/WebServices/ECS/classes/class.ilECSCategoryMappingRule.php';
193  include_once './Services/WebServices/ECS/classes/class.ilECSCommunitiesCache.php';
194 
195  // see ilECSCategoryMapping::getPossibleFields();
196  $res = array();
197  $res["part_id"] = array($a_owner, ilECSCategoryMappingRule::ATTR_INT);
198  $res["community"] = array(ilECSCommunitiesCache::getInstance()->lookupTitle($a_server_id, $a_owner),
200 
201  $definition = self::getEContentDefinition($a_resource_id);
202 
203  $timePlace = null;
204  foreach ($definition as $id => $type) {
205  if (is_array($type)) {
206  $target = $type[1];
207  $type = $type[0];
208  } else {
209  $target = $id;
210  }
211  switch ($type) {
213  $value = array(implode(',', (array) $a_ecs_content->$target), ilECSCategoryMappingRule::ATTR_ARRAY);
214  break;
215 
217  $value = array((int) $a_ecs_content->$target, ilECSCategoryMappingRule::ATTR_INT);
218  break;
219 
221  $value = array((string) $a_ecs_content->$target, ilECSCategoryMappingRule::ATTR_STRING);
222  break;
223 
225  if (!is_object($timePlace)) {
226  include_once('./Services/WebServices/ECS/classes/class.ilECSTimePlace.php');
227  if (is_object($a_ecs_content->$target)) {
228  $timePlace = new ilECSTimePlace();
229  $timePlace->loadFromJSON($a_ecs_content->$target);
230  } else {
231  $timePlace = new ilECSTimePlace();
232  }
233  }
234  switch ($id) {
235  case 'begin':
236  case 'end':
237  $value = array($timePlace->{'getUT' . ucfirst($id)}(),
239  break;
240 
241  case 'room':
242  case 'cycle':
243  $value = array($timePlace->{'get' . ucfirst($id)}(),
245  break;
246  }
247  break;
248  }
249 
250  $res[$id] = $value;
251  }
252 
253  return $res;
254  }
255 
262  public static function getAdvancedMDValuesForObjId($a_obj_id)
263  {
264  $res = array();
265 
266  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
267 
268  // getting all records
269  foreach (ilAdvancedMDValues::getInstancesForObjectId($a_obj_id) as $a_values) {
270  // this correctly binds group and definitions
271  $a_values->read();
272 
273  // getting elements for record
274  $defs = $a_values->getDefinitions();
275  foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) {
276  if (!$element->isNull()) {
277  // :TODO: using this for a "flat" presentation
278  $res[$element_id] = $defs[$element_id]->getValueForXML($element);
279  } else {
280  // :TODO: is this needed?
281  $res[$element_id] = null;
282  }
283  }
284  }
285 
286  return $res;
287  }
288 }
static getPossibleReleaseTypes($a_with_captions=false)
Get all possible release object types.
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
static lookupParticipantName($a_owner, $a_server_id)
Lookup participant name.
static getPossibleRemoteTypes($a_with_captions=false)
Get all possible remote object types.
Representation of ECS EContent Time Place.
$type
global $DIC
Definition: saml.php:7
static getEContentDefinition($a_resource_id)
Get econtent / metadata definition.
if(!array_key_exists('StateId', $_REQUEST)) $id
const TYPE_TIMEPLACE
static getMatchableContent($a_resource_id, $a_server_id, $a_ecs_content, $a_owner)
Convert ECS content to rule matchable values.
static getInstanceByServerId($a_server_id)
Get instance by server id.
foreach($_POST as $key=> $value) $res
$lng
static getAdvancedMDValuesForObjId($a_obj_id)
Get advanced metadata values for object id.
static getInstance()
Singleton instance.
static _getOptionalEContentFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions ...
$def
Definition: croninfo.php:21
$target
Definition: test.php:19
static _getOptionalECourseFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions ...