ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
trait.StdObjProperties.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Repository\Form;
22
26
28{
29 protected \ILIAS\ILIASObject\Properties\Aggregator $object_prop;
30
31 protected function initStdObjProperties(Container $DIC): void
32 {
33 $this->object_prop = LocalDIC::dic()['properties.aggregator'];
34 }
35
37 int $obj_id,
38 string $type
40 $obj_prop = $this->object_prop->getFor($obj_id, $type);
41 $inputs = $obj_prop
42 ->getPropertyTitleAndDescription()
43 ->toForm($this->lng, $this->ui->factory()->input()->field(), $this->refinery)->getInputs();
44 $this->addField("title", $inputs[0]);
45 $this->addField("description", $inputs[1]);
46 return $this;
47 }
48
49 public function addStdTitle(
50 int $obj_id,
51 string $type
53 $obj_prop = $this->object_prop->getFor($obj_id, $type);
54 $inputs = $obj_prop
55 ->getPropertyTitleAndDescription()
56 ->toForm($this->lng, $this->ui->factory()->input()->field(), $this->refinery)->getInputs();
57 $this->addField("title", $inputs[0]);
58 return $this;
59 }
60
62 int $obj_id,
63 string $type
64 ): void {
65 $obj_prop = $this->object_prop->getFor($obj_id, $type);
66 $obj_prop->storePropertyTitleAndDescription(
68 $this->getData("title"),
69 $this->getData("description")
70 )
71 );
72 }
73
74 public function saveStdTitle(
75 int $obj_id,
76 string $type
77 ): void {
78 $obj_prop = $this->object_prop->getFor($obj_id, $type);
79 $obj_prop->storePropertyTitleAndDescription(
81 $this->getData("title"),
82 ""
83 )
84 );
85 }
86
87 public function addStdTile(
88 int $obj_id,
89 string $type
91 $obj_prop = $this->object_prop->getFor($obj_id, $type);
92 $input = $obj_prop->getPropertyTileImage()
93 ->toForm($this->lng, $this->ui->factory()->input()->field(), $this->refinery);
94 $this->addField("tile", $input, true);
95 return $this;
96 }
97
98 public function saveStdTile(
99 int $obj_id,
100 string $type
101 ): void {
102 $obj_prop = $this->object_prop->getFor($obj_id, $type);
103 $tile = $this->getData("tile");
104 if (!is_null($tile)) {
105 $obj_prop->storePropertyTileImage($this->getData("tile"));
106 }
107 }
108
109 public function addOnline(
110 int $obj_id,
111 string $type
112 ): FormAdapterGUI {
113 $obj_prop = $this->object_prop->getFor($obj_id, $type);
114 $input = $obj_prop->getPropertyIsOnline()
115 ->toForm($this->lng, $this->ui->factory()->input()->field(), $this->refinery);
116 $this->addField("is_online", $input, true);
117 return $this;
118 }
119
120 public function saveOnline(
121 int $obj_id,
122 string $type
123 ): void {
124 $obj_prop = $this->object_prop->getFor($obj_id, $type);
125 $obj_prop->storePropertyIsOnline($this->getData("is_online"));
126 }
127
128 public function addStdAvailability(int $ref_id, $visibility_info = ""): self
129 {
132 $start = $end = $visibility = null;
133 if (($activation["timing_type"] ?? null) === \ilObjectActivation::TIMINGS_ACTIVATION) {
134 $start = (int) $activation["timing_start"];
135 $end = (int) $activation["timing_end"];
136 $visibility = (bool) $activation["visible"];
137 }
138 $enabled = ($end > 0) || ($start > 0);
139 $form = $this
140 ->optional(
141 "limited",
142 $lng->txt("rep_time_based_availability"),
143 "",
144 $enabled
145 )
146 ->dateTimeDuration(
147 "availability",
148 $this->lng->txt("rep_time_period"),
149 "",
150 new \ilDateTime($start, IL_CAL_UNIX),
151 new \ilDateTime($end, IL_CAL_UNIX)
152 )
153 ->checkbox(
154 "visibility",
155 $this->lng->txt("rep_activation_limited_visibility"),
156 $visibility_info,
157 $visibility
158 )
159 ->end();
160 return $form;
161 }
162
163 public function saveStdAvailability(int $ref_id): void
164 {
165 $item = new \ilObjectActivation();
166 if (!$this->getData("limited")) {
167 $item->setTimingType(\ilObjectActivation::TIMINGS_DEACTIVATED);
168 } else {
169 $avail = $this->getData("availability");
170 $from = $to = null;
171 if (!is_null($avail) && !is_null($avail[0])) {
172 $from = $avail[0]->getUnixTime();
173 }
174 if (!is_null($avail) && !is_null($avail[1])) {
175 $to = $avail[1]->getUnixTime();
176 }
177 if ($from > 0 || $to > 0) {
178 $item->setTimingType(\ilObjectActivation::TIMINGS_ACTIVATION);
179 $item->setTimingStart($from);
180 $item->setTimingEnd($to);
181 $item->toggleVisible($this->getData("visibility"));
182 } else {
183 $item->setTimingType(\ilObjectActivation::TIMINGS_DEACTIVATED);
184 }
185 }
186 $item->update($ref_id);
187 }
188
189
190 public function addAdditionalFeatures(
191 int $obj_id,
192 array $services
193 ): self {
194 global $DIC;
195
196 $lng = $DIC->language();
197
198 $lng->loadLanguageModule("obj");
199
200 $form = $this->section("add", $lng->txt("obj_features"));
201
202 // (local) custom metadata
203 if (in_array(\ilObjectServiceSettingsGUI::CUSTOM_METADATA, $services)) {
204 $form = $this->checkbox(
206 $lng->txt('obj_tool_setting_custom_metadata'),
207 $lng->txt('obj_tool_setting_custom_metadata_info'),
209 $obj_id,
211 )
212 );
213 }
214
215 // taxonomies
216 if (in_array(\ilObjectServiceSettingsGUI::TAXONOMIES, $services)) {
217 $form = $this->checkbox(
219 $lng->txt('obj_tool_setting_taxonomies'),
220 "",
222 $obj_id,
224 )
225 );
226 }
227
228 if (\in_array(\ilObjectServiceSettingsGUI::ORGU_POSITION_ACCESS, $services, true)) {
229 $position_settings = \ilOrgUnitGlobalSettings::getInstance()->getObjectPositionSettingsByType(
230 \ilObject::_lookupType($obj_id)
231 );
232 if ($position_settings->isActive()) {
233 $form = $this->checkbox(
235 $lng->txt('obj_orgunit_positions'),
236 $lng->txt('obj_orgunit_positions_info'),
237 \ilOrgUnitGlobalSettings::getInstance()->isPositionAccessActiveForObject($obj_id),
238 !$position_settings->isChangeableForObject()
239 );
240 }
241 }
242
243 return $form;
244 }
245
246 public function saveAdditionalFeatures(
247 int $obj_id,
248 array $services
249 ): void {
250 // (local) custom metadata
251 $key = \ilObjectServiceSettingsGUI::CUSTOM_METADATA;
252 if (in_array($key, $services)) {
253 \ilContainer::_writeContainerSetting($obj_id, $key, (string) $this->getData($key));
254 }
255 // taxonomies
257 if (in_array($key, $services)) {
258 \ilContainer::_writeContainerSetting($obj_id, $key, (string) $this->getData($key));
259 }
260 // extended user access
261 if (\in_array(\ilObjectServiceSettingsGUI::ORGU_POSITION_ACCESS, $services, true)) {
262 $position_settings = \ilOrgUnitGlobalSettings::getInstance()->getObjectPositionSettingsByType(
263 \ilObject::_lookupType($obj_id)
264 );
265 if ($position_settings->isActive() && $position_settings->isChangeableForObject()) {
266 $orgu_object_settings = new \ilOrgUnitObjectPositionSetting($obj_id);
267 $orgu_object_settings->setActive($this->getData(\ilObjectServiceSettingsGUI::ORGU_POSITION_ACCESS));
268 $orgu_object_settings->update();
269 }
270 }
271 }
272
273 public function addDidacticTemplates(
274 string $type,
275 int $ref_id,
276 bool $creation_mode,
277 array $additional_template_options = []
278 ): self {
279 list($existing_exclusive, $options) = $this->buildDidacticTemplateOptions(
280 $type,
281 $ref_id,
282 $additional_template_options
283 );
284 if (sizeof($options) < 2) {
285 return $this;
286 }
287
288 // workaround for containers in edit mode
289 if (!$creation_mode) {
291
292 if (!in_array(
293 $current_value,
294 array_keys($options)
295 ) || ($existing_exclusive && $current_value == "dtpl_0")) {
296 //add or rename actual value to not available
297 $options[$current_value] = [$this->lng->txt('not_available')];
298 }
299 } else {
300 if ($existing_exclusive) {
301 //if an exclusive template exists use the second template as default value - Whatever the f*** that means!
302 $keys = array_keys($options);
303 $current_value = $keys[1];
304 } else {
305 $current_value = 'dtpl_0';
306 }
307 }
308
309 $form = $this->radio(
310 'didactic_type',
311 $this->lng->txt('type'),
312 "",
313 $current_value
314 );
315
316 foreach ($options as $id => $data) {
317 /*
318 if ($existing_exclusive && $id == 'dtpl_0') {
319 //set default disabled if an exclusive template exists
320 $option->setDisabled(true);
321 }*/
322 $form = $this->radioOption(
323 (string) $id,
324 $data[0] ?? '',
325 $data[1] ?? ''
326 );
327 }
328 return $form;
329 }
330
332 string $type,
333 int $ref_id,
334 array $additional_template_options = []
335 ): array {
336 $this->lng->loadLanguageModule('didactic');
337 $existing_exclusive = false;
338 $options = [];
339 $options['dtpl_0'] = [
340 $this->lng->txt('didactic_default_type'),
341 sprintf(
342 $this->lng->txt('didactic_default_type_info'),
343 $this->lng->txt('objs_' . $type)
344 )
345 ];
346
347 $templates = \ilDidacticTemplateSettings::getInstanceByObjectType($type)->getTemplates();
348 if ($templates) {
349 foreach ($templates as $template) {
350 if ($template->isEffective((int) $ref_id)) {
351 $options["dtpl_" . $template->getId()] = [
352 $template->getPresentationTitle(),
353 $template->getPresentationDescription()
354 ];
355
356 if ($template->isExclusive()) {
357 $existing_exclusive = true;
358 }
359 }
360 }
361 }
362
363 return [$existing_exclusive, array_merge($options, $additional_template_options)];
364 }
365
367 int $ref_id,
368 string $type,
369 string $gui_class,
370 array $additional_template_options = []
371 ): void {
372 list($existing_exclusive, $options) = $this->buildDidacticTemplateOptions(
373 $type,
374 $ref_id,
375 $additional_template_options
376 );
377
378 if (sizeof($options) < 2) {
379 return;
380 }
381
383 $ref_id
384 );
385 $new_tpl_id = (int) substr($this->getData('didactic_type'), 5);
386
387 if ($new_tpl_id !== $current_tpl_id) {
388 // redirect to didactic template confirmation
389 $this->ctrl->setParameterByClass(\ilDidacticTemplateGUI::class, "didactic_template_id", $new_tpl_id);
390 $this->ctrl->redirectByClass([$gui_class, \ilDidacticTemplateGUI::class], "confirmTemplateSwitch");
391 return;
392 }
393 }
394
396 {
397 $new_tpl_id = null;
398 if ($this->http->wrapper()->query()->has('didactic_template_id')) {
399 $new_tpl_id = $this->http->wrapper()->query()->retrieve(
400 'didactic_template_id',
401 $this->refinery->kindlyTo()->int()
402 );
403 $this->ctrl->saveParameterByClass(\ilDidacticTemplateGUI::class, "didactic_template_id", $new_tpl_id);
404 }
405 return $new_tpl_id;
406 }
407
408
409}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
const IL_CAL_UNIX
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
static getInstanceByObjectType(string $a_obj_type)
static getItem(int $ref_id)
GUI class for service settings (calendar, notes, comments)
static _lookupType(int $id, bool $reference=false)
$ref_id
Definition: ltiauth.php:66
static http()
Fetches the global http state from ILIAS.
saveStdTitle(int $obj_id, string $type)
addAdditionalFeatures(int $obj_id, array $services)
addStdTitle(int $obj_id, string $type)
buildDidacticTemplateOptions(string $type, int $ref_id, array $additional_template_options=[])
initStdObjProperties(Container $DIC)
addStdTitleAndDescription(int $obj_id, string $type)
addStdAvailability(int $ref_id, $visibility_info="")
saveStdTitleAndDescription(int $obj_id, string $type)
saveAdditionalFeatures(int $obj_id, array $services)
addOnline(int $obj_id, string $type)
saveStdTile(int $obj_id, string $type)
addStdTile(int $obj_id, string $type)
redirectToDidacticConfirmationIfChanged(int $ref_id, string $type, string $gui_class, array $additional_template_options=[])
saveOnline(int $obj_id, string $type)
addDidacticTemplates(string $type, int $ref_id, bool $creation_mode, array $additional_template_options=[])
global $lng
Definition: privfeed.php:26
global $DIC
Definition: shib_login.php:26