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