ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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
229 return $form;
230 }
231
232 public function saveAdditionalFeatures(
233 int $obj_id,
234 array $services
235 ): void {
236 // (local) custom metadata
237 $key = \ilObjectServiceSettingsGUI::CUSTOM_METADATA;
238 if (in_array($key, $services)) {
239 \ilContainer::_writeContainerSetting($obj_id, $key, (string) $this->getData($key));
240 }
241 // taxonomies
243 if (in_array($key, $services)) {
244 \ilContainer::_writeContainerSetting($obj_id, $key, (string) $this->getData($key));
245 }
246 }
247
248 public function addDidacticTemplates(
249 string $type,
250 int $ref_id,
251 bool $creation_mode,
252 array $additional_template_options = []
253 ): self {
254 list($existing_exclusive, $options) = $this->buildDidacticTemplateOptions(
255 $type,
256 $ref_id,
257 $additional_template_options
258 );
259 if (sizeof($options) < 2) {
260 return $this;
261 }
262
263 // workaround for containers in edit mode
264 if (!$creation_mode) {
266
267 if (!in_array(
268 $current_value,
269 array_keys($options)
270 ) || ($existing_exclusive && $current_value == "dtpl_0")) {
271 //add or rename actual value to not available
272 $options[$current_value] = [$this->lng->txt('not_available')];
273 }
274 } else {
275 if ($existing_exclusive) {
276 //if an exclusive template exists use the second template as default value - Whatever the f*** that means!
277 $keys = array_keys($options);
278 $current_value = $keys[1];
279 } else {
280 $current_value = 'dtpl_0';
281 }
282 }
283
284 $form = $this->radio(
285 'didactic_type',
286 $this->lng->txt('type'),
287 "",
288 $current_value
289 );
290
291 foreach ($options as $id => $data) {
292 /*
293 if ($existing_exclusive && $id == 'dtpl_0') {
294 //set default disabled if an exclusive template exists
295 $option->setDisabled(true);
296 }*/
297 $form = $this->radioOption(
298 (string) $id,
299 $data[0] ?? '',
300 $data[1] ?? ''
301 );
302 }
303 return $form;
304 }
305
307 string $type,
308 int $ref_id,
309 array $additional_template_options = []
310 ): array {
311 $this->lng->loadLanguageModule('didactic');
312 $existing_exclusive = false;
313 $options = [];
314 $options['dtpl_0'] = [
315 $this->lng->txt('didactic_default_type'),
316 sprintf(
317 $this->lng->txt('didactic_default_type_info'),
318 $this->lng->txt('objs_' . $type)
319 )
320 ];
321
322 $templates = \ilDidacticTemplateSettings::getInstanceByObjectType($type)->getTemplates();
323 if ($templates) {
324 foreach ($templates as $template) {
325 if ($template->isEffective((int) $ref_id)) {
326 $options["dtpl_" . $template->getId()] = [
327 $template->getPresentationTitle(),
328 $template->getPresentationDescription()
329 ];
330
331 if ($template->isExclusive()) {
332 $existing_exclusive = true;
333 }
334 }
335 }
336 }
337
338 return [$existing_exclusive, array_merge($options, $additional_template_options)];
339 }
340
342 int $ref_id,
343 string $type,
344 string $gui_class,
345 array $additional_template_options = []
346 ): void {
347 list($existing_exclusive, $options) = $this->buildDidacticTemplateOptions(
348 $type,
349 $ref_id,
350 $additional_template_options
351 );
352
353 if (sizeof($options) < 2) {
354 return;
355 }
356
358 $ref_id
359 );
360 $new_tpl_id = (int) substr($this->getData('didactic_type'), 5);
361
362 if ($new_tpl_id !== $current_tpl_id) {
363 // redirect to didactic template confirmation
364 $this->ctrl->setParameterByClass(\ilDidacticTemplateGUI::class, "didactic_template_id", $new_tpl_id);
365 $this->ctrl->redirectByClass([$gui_class, \ilDidacticTemplateGUI::class], "confirmTemplateSwitch");
366 return;
367 }
368 }
369
371 {
372 $new_tpl_id = null;
373 if ($this->http->wrapper()->query()->has('didactic_template_id')) {
374 $new_tpl_id = $this->http->wrapper()->query()->retrieve(
375 'didactic_template_id',
376 $this->refinery->kindlyTo()->int()
377 );
378 $this->ctrl->saveParameterByClass(\ilDidacticTemplateGUI::class, "didactic_template_id", $new_tpl_id);
379 }
380 return $new_tpl_id;
381 }
382
383
384}
$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)
$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:31
global $DIC
Definition: shib_login.php:26