ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilECSUtils.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
26  public const TYPE_ARRAY = 1;
27  public const TYPE_INT = 2;
28  public const TYPE_STRING = 3;
29  public const TYPE_TIMEPLACE = 4;
30 
35  public static function _getOptionalEContentFields(): array
36  {
37  // :TODO: ?
38  $def = self::getEContentDefinition('/campusconnect/courselinks');
39  return array_keys($def);
40  }
41 
46  public static function _getOptionalECourseFields(): array
47  {
48  // :TODO: ?
49  $def = self::getEContentDefinition('/campusconnect/courselinks');
50  return array_keys($def);
51  }
52 
56  public static function getPossibleRemoteTypes(bool $a_with_captions = false): array
57  {
58  global $DIC;
59 
60  $lng = $DIC['lng'];
61 
62  $all = array("rcrs", "rcat", "rfil", "rglo", "rgrp", "rlm", "rwik");
63 
64  if (!$a_with_captions) {
65  return $all;
66  }
67 
68  $res = array();
69  foreach ($all as $id) {
70  $res[$id] = $lng->txt("obj_" . $id);
71  }
72  return $res;
73  }
74 
78  public static function getPossibleReleaseTypes(bool $a_with_captions = false): array
79  {
80  global $DIC;
81 
82  $lng = $DIC['lng'];
83 
84  $all = array("crs", "cat", "file", "glo", "grp", "lm", "wiki");
85 
86  if (!$a_with_captions) {
87  return $all;
88  }
89 
90  $res = array();
91  foreach ($all as $id) {
92  $res[$id] = $lng->txt("obj_" . $id);
93  }
94  return $res;
95  }
96 
100  public static function getEContentDefinition(string $a_resource_id): array
101  {
102  switch ($a_resource_id) {
103  case '/campusconnect/courselinks':
104  return array(
105  'study_courses' => self::TYPE_ARRAY,
106  'lecturer' => self::TYPE_ARRAY,
107  'courseType' => self::TYPE_STRING,
108  'courseID' => self::TYPE_INT,
109  'credits' => self::TYPE_INT,
110  'semester_hours' => self::TYPE_INT,
111  'term' => self::TYPE_STRING,
112  'begin' => array(self::TYPE_TIMEPLACE, 'timePlace'),
113  'end' => array(self::TYPE_TIMEPLACE, 'timePlace'),
114  'room' => array(self::TYPE_TIMEPLACE, 'timePlace'),
115  'cycle' => array(self::TYPE_TIMEPLACE, 'timePlace')
116  );
117 
118  case '/campusconnect/categories':
119  case '/campusconnect/files':
120  case '/campusconnect/glossaries':
121  case '/campusconnect/groups':
122  case '/campusconnect/learningmodules':
123  case '/campusconnect/wikis':
124  // no metadata mapping yet
125  default:
126  return [];
127  }
128  }
129 
133  public static function getMatchableContent(string $a_resource_id, int $a_server_id, object $a_ecs_content, int $a_owner): array
134  {
135  // see ilECSCategoryMapping::getPossibleFields();
136  $res = array();
137  $res["part_id"] = array($a_owner, ilECSCategoryMappingRule::ATTR_INT);
138  $res["community"] = array(ilECSCommunitiesCache::getInstance()->lookupTitle($a_server_id, $a_owner),
140 
141  $definition = self::getEContentDefinition($a_resource_id);
142 
143  $timePlace = null;
144  $value = null;
145  foreach ($definition as $id => $type) {
146  if (is_array($type)) {
147  [$type, $target] = $type;
148  } else {
149  $target = $id;
150  }
151  switch ($type) {
152  case self::TYPE_ARRAY:
153  if (isset($a_ecs_content->{$target})) {
154  $value = array(implode(',', (array) $a_ecs_content->{$target}), ilECSCategoryMappingRule::ATTR_ARRAY);
155  } else {
156  $value = [];
157  }
158  break;
159 
160  case self::TYPE_INT:
161  if (isset($a_ecs_content->{$target})) {
162  $value = array((int) $a_ecs_content->{$target}, ilECSCategoryMappingRule::ATTR_INT);
163  } else {
164  $value = 0;
165  }
166  break;
167 
168  case self::TYPE_STRING:
169  if (isset($a_ecs_content->{$target})) {
170  $value = array((string) $a_ecs_content->{$target}, ilECSCategoryMappingRule::ATTR_STRING);
171  } else {
172  $value = "";
173  }
174  break;
175 
176  case self::TYPE_TIMEPLACE:
177  if (!is_object($timePlace)) {
178  $timePlace = new ilECSTimePlace();
179  if (isset($a_ecs_content->{$target}) && is_object($a_ecs_content->{$target})) {
180  $timePlace->loadFromJSON($a_ecs_content->{$target});
181  }
182  }
183  switch ($id) {
184  case 'begin':
185  case 'end':
186  $value = array($timePlace->{'getUT' . ucfirst($id)}(),
188  break;
189 
190  case 'room':
191  case 'cycle':
192  $value = array($timePlace->{'get' . ucfirst($id)}(),
194  break;
195  }
196  break;
197  }
198 
199  $res[$id] = $value;
200  }
201 
202  return $res;
203  }
204 
208  public static function getAdvancedMDValuesForObjId(int $a_obj_id): array
209  {
210  $res = array();
211 
212  // getting all records
213  foreach (ilAdvancedMDValues::getInstancesForObjectId($a_obj_id) as $a_values) {
214  // this correctly binds group and definitions
215  $a_values->read();
216 
217  // getting elements for record
218  $defs = $a_values->getDefinitions();
219  foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) {
220  if (!$element->isNull()) {
221  // :TODO: using this for a "flat" presentation
222  $res[$element_id] = $defs[$element_id]->getValueForXML($element);
223  } else {
224  // :TODO: is this needed?
225  $res[$element_id] = null;
226  }
227  }
228  }
229 
230  return $res;
231  }
232 }
static getInstancesForObjectId(int $a_obj_id, ?string $a_obj_type=null, string $a_sub_type="-", int $a_sub_id=0)
static getAdvancedMDValuesForObjId(int $a_obj_id)
Get advanced metadata values for object id.
$res
Definition: ltiservices.php:66
static getPossibleReleaseTypes(bool $a_with_captions=false)
Get all possible release object types.
Representation of ECS EContent Time Place.
static getEContentDefinition(string $a_resource_id)
Get econtent / metadata definition.
static getPossibleRemoteTypes(bool $a_with_captions=false)
Get all possible remote object types.
const TYPE_TIMEPLACE
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
static getInstance()
Singleton instance.
static _getOptionalEContentFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions ...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
global $lng
Definition: privfeed.php:31
static _getOptionalECourseFields()
get optional econtent fields These fields might be mapped against AdvancedMetaData field definitions ...
static getMatchableContent(string $a_resource_id, int $a_server_id, object $a_ecs_content, int $a_owner)
Convert ECS content to rule matchable values.