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