ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 
26 
27 trait StdObjProperties
28 {
29  protected \ilObjectPropertiesAgregator $object_prop;
30 
31  protected function initStdObjProperties(Container $DIC)
32  {
33  $this->object_prop = ilObjectDIC::dic()['object_properties_agregator'];
34  }
35 
36  public function addStdTitleAndDescription(
37  int $obj_id,
38  string $type
39  ): FormAdapterGUI {
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
52  ): FormAdapterGUI {
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 
61  public function saveStdTitleAndDescription(
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
90  ): FormAdapterGUI {
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  {
130  $lng = $this->lng;
131  $activation = \ilObjectActivation::getItem($ref_id);
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
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) {
265  $current_value = 'dtpl_' . \ilDidacticTemplateObjSettings::lookupTemplateId($ref_id);
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 }
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:22
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)