ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilObjectServiceSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
35 {
36  // unfortunately the following constants are not stored
37  // in a non-GUI class, other classes are currently directly
38  // accessing these, see ilObjectDataSet (changes should be
39  // made there accordingly)
40 
41  public const CALENDAR_CONFIGURATION = 'cont_cal_configuration';
42  public const CALENDAR_VISIBILITY = 'cont_show_calendar';
43  public const CALENDAR_ACTIVATION = 'cont_activation_calendar';
44 
45  public const NEWS_VISIBILITY = 'cont_show_news';
46  public const USE_NEWS = 'cont_use_news';
47  public const AUTO_RATING_NEW_OBJECTS = 'cont_auto_rate_new_obj';
48  public const INFO_TAB_VISIBILITY = 'cont_show_info_tab';
49  public const TAXONOMIES = 'cont_taxonomies';
50  public const TAG_CLOUD = 'cont_tag_cloud';
51  public const CUSTOM_METADATA = 'cont_custom_md';
52  public const BADGES = 'cont_badges';
53  public const ORGU_POSITION_ACCESS = 'obj_orgunit_positions';
54  public const SKILLS = 'cont_skills';
55  public const FILTER = 'filter';
56  public const BOOKING = 'cont_bookings';
57  public const EXTERNAL_MAIL_PREFIX = 'mail_external_prefix';
58 
59  protected ilCtrl $ctrl;
61  protected ilLanguage $lng;
62 
63  protected ?ilObjectGUI $gui = null;
64  protected array $modes = [];
65  protected int $obj_id = 0;
66 
70  public function __construct(ilObjectGUI $parent_gui, int $obj_id, array $modes)
71  {
72  global $DIC;
73  $this->main_tpl = $DIC->ui()->mainTemplate();
74  $this->ctrl = $DIC->ctrl();
75  $this->lng = $DIC["lng"];
76 
77  $this->gui = $parent_gui;
78  $this->modes = $DIC->refinery()->to()->listOf(
79  $DIC->refinery()->kindlyTo()->string()
80  )->transform($modes);
81 
82  $this->obj_id = $obj_id;
83  }
84 
85  public function executeCommand(): void
86  {
87  $this->ctrl->getNextClass($this);
88  $cmd = $this->ctrl->getCmd('editSettings');
89  $this->$cmd();
90  }
91 
92  public static function initServiceSettingsForm(
93  int $obj_id,
94  ilPropertyFormGUI $form,
95  array $services
97  global $DIC;
98 
99  $ilSetting = $DIC->settings();
100  $ilCtrl = $DIC->ctrl();
101  $lng = $DIC->language();
102 
103  $lng->loadLanguageModule("obj");
104 
105  // info tab
106  if (in_array(self::INFO_TAB_VISIBILITY, $services)) {
107  $info = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_info_tab'), self::INFO_TAB_VISIBILITY);
108  $info->setValue("1");
109  $info->setChecked((bool) ilContainer::_lookupContainerSetting(
110  $obj_id,
111  self::INFO_TAB_VISIBILITY
112  ));
113  //$info->setOptionTitle($lng->txt('obj_tool_setting_info_tab'));
114  $info->setInfo($lng->txt('obj_tool_setting_info_tab_info'));
115  $form->addItem($info);
116  }
117 
118  // calendar
119  if (in_array(self::CALENDAR_CONFIGURATION, $services)) {
120  $settings = ilCalendarSettings::_getInstance();
121  if ($settings->isEnabled()) {
122  $active = new ilCheckboxInputGUI(
123  $lng->txt('obj_tool_setting_calendar_active'),
124  self::CALENDAR_ACTIVATION
125  );
126  $active->setValue("1");
127  $active->setChecked(ilCalendarSettings::lookupCalendarActivated($obj_id));
128  $active->setInfo($lng->txt('obj_tool_setting_calendar_active_info'));
129 
130  $visible = new ilCheckboxInputGUI(
131  $lng->txt('obj_tool_setting_calendar'),
132  self::CALENDAR_VISIBILITY
133  );
134  $visible->setValue("1");
136  $visible->setInfo($lng->txt('obj_tool_setting_calendar_info'));
137  $active->addSubItem($visible);
138 
139  $form->addItem($active);
140  }
141  }
142 
143  // news
144  if (in_array(self::USE_NEWS, $services)) {
145  $news = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_use_news'), self::USE_NEWS);
146  $news->setValue("1");
147  $checked = (bool) ilContainer::_lookupContainerSetting(
148  $obj_id,
149  self::USE_NEWS
150  );
151  $news->setChecked($checked);
152  $info = $lng->txt('obj_tool_setting_use_news_info');
153  if ($checked) {
154  $info .= " <a href='" . $ilCtrl->getLinkTargetByClass("ilcontainernewssettingsgui", "") .
155  "'>ยป " . $lng->txt('obj_tool_setting_use_news_open_settings') . "</a>";
156  }
157  $news->setInfo($info);
158  $form->addItem($news);
159  }
160  if (in_array(self::NEWS_VISIBILITY, $services)) {
161  if ($ilSetting->get('block_activated_news')) {
162  // Container tools (calendar, news, ... activation)
163  $news = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_news'), self::NEWS_VISIBILITY);
164  $news->setValue("1");
165  $news->setChecked((bool) ilContainer::_lookupContainerSetting(
166  $obj_id,
167  self::NEWS_VISIBILITY,
168  $ilSetting->get('block_activated_news')
169  ));
170  //$news->setOptionTitle($lng->txt('obj_tool_setting_news'));
171  $news->setInfo($lng->txt('obj_tool_setting_news_info'));
172  $form->addItem($news);
173 
174  if (in_array(ilObject::_lookupType($obj_id), ['crs', 'grp'])) {
175  $refs = ilObject::_getAllReferences($obj_id);
176  $ref_id = array_pop($refs);
177 
179  }
180  }
181  }
182 
183  // (local) custom metadata
184  if (in_array(self::CUSTOM_METADATA, $services)) {
185  $md = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_custom_metadata'), self::CUSTOM_METADATA);
186  $md->setInfo($lng->txt('obj_tool_setting_custom_metadata_info'));
187  $md->setValue("1");
188  $md->setChecked((bool) ilContainer::_lookupContainerSetting(
189  $obj_id,
190  self::CUSTOM_METADATA
191  ));
192  $form->addItem($md);
193  }
194 
195  // tag cloud
196  if (in_array(self::TAG_CLOUD, $services)) {
197  $tags_active = new ilSetting("tags");
198  if ($tags_active->get("enable")) {
199  $tag = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_tag_cloud'), self::TAG_CLOUD);
200  $tag->setInfo($lng->txt('obj_tool_setting_tag_cloud_info'));
201  $tag->setValue("1");
202  $tag->setChecked((bool) ilContainer::_lookupContainerSetting(
203  $obj_id,
204  self::TAG_CLOUD
205  ));
206  $form->addItem($tag);
207  }
208  }
209 
210  // taxonomies
211  if (in_array(self::TAXONOMIES, $services)) {
212  $tax = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_taxonomies'), self::TAXONOMIES);
213  $tax->setInfo($lng->txt('obj_tool_setting_taxonomies_info'));
214  $tax->setValue("1");
215  $tax->setChecked((bool) ilContainer::_lookupContainerSetting(
216  $obj_id,
217  self::TAXONOMIES
218  ));
219  $form->addItem($tax);
220  }
221 
222  // auto rating
223  if (in_array(self::AUTO_RATING_NEW_OBJECTS, $services)) {
224  $lng->loadLanguageModule("rating");
225 
226  // auto rating for new objects
227  $rate = new ilCheckboxInputGUI($lng->txt('rating_new_objects_auto'), self::AUTO_RATING_NEW_OBJECTS);
228  $rate->setValue("1");
229  //$rate->setOptionTitle($lng->txt('rating_new_objects_auto'));
230  $rate->setInfo($lng->txt('rating_new_objects_auto_info'));
231  $rate->setChecked((bool) ilContainer::_lookupContainerSetting(
232  $obj_id,
233  self::AUTO_RATING_NEW_OBJECTS
234  ));
235  $form->addItem($rate);
236  }
237 
238  // badges
239  if (in_array(self::BADGES, $services)) {
240  if (ilBadgeHandler::getInstance()->isActive()) {
241  $bdg = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_badges'), self::BADGES);
242  $bdg->setInfo($lng->txt('obj_tool_setting_badges_info'));
243  $bdg->setValue("1");
244  $bdg->setChecked((bool) ilContainer::_lookupContainerSetting(
245  $obj_id,
246  self::BADGES
247  ));
248  $form->addItem($bdg);
249  }
250  }
251  if (in_array(self::ORGU_POSITION_ACCESS, $services)) {
252  $position_settings = ilOrgUnitGlobalSettings::getInstance()->getObjectPositionSettingsByType(
253  ilObject::_lookupType($obj_id)
254  );
255  if (
256  $position_settings->isActive()
257  ) {
258  $lia = new ilCheckboxInputGUI(
259  $GLOBALS['DIC']->language()->txt('obj_orgunit_positions'),
260  self::ORGU_POSITION_ACCESS
261  );
262  $lia->setInfo($GLOBALS['DIC']->language()->txt('obj_orgunit_positions_info'));
263  $lia->setValue("1");
264  $lia->setChecked(
265  ilOrgUnitGlobalSettings::getInstance()->isPositionAccessActiveForObject($obj_id)
266  );
267  if (!$position_settings->isChangeableForObject()) {
268  $lia->setDisabled(true);
269  }
270  $form->addItem($lia);
271  }
272  }
273 
274  // skills
275  if (in_array(self::SKILLS, $services)) {
276  $skmg_set = new ilSetting("skmg");
277  if ($skmg_set->get("enable_skmg")) {
278  $skill = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_skills'), self::SKILLS);
279  $skill->setInfo($lng->txt('obj_tool_setting_skills_info'));
280  $skill->setValue("1");
281  $skill->setChecked((bool) ilContainer::_lookupContainerSetting(
282  $obj_id,
283  self::SKILLS
284  ));
285  $form->addItem($skill);
286  }
287  }
288 
289  // filter
290  if (in_array(self::FILTER, $services)) {
291  $filter = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_filter'), self::FILTER);
292  $filter->setInfo($lng->txt('obj_tool_setting_filter_info'));
293  $filter->setValue("1");
294  $filter->setChecked((bool) ilContainer::_lookupContainerSetting(
295  $obj_id,
296  self::FILTER
297  ));
298  $form->addItem($filter);
299 
300  $filter_show_empty = new ilCheckboxInputGUI($lng->txt('obj_tool_setting_filter_empty'), "filter_show_empty");
301  $filter_show_empty->setInfo($lng->txt('obj_tool_setting_filter_empty_info'));
302  $filter_show_empty->setValue("1");
303  $filter_show_empty->setChecked((bool) ilContainer::_lookupContainerSetting(
304  $obj_id,
305  "filter_show_empty"
306  ));
307  $filter->addSubItem($filter_show_empty);
308  }
309  // booking tool
310  if (in_array(self::BOOKING, $services)) {
311  $book = new ilCheckboxInputGUI($lng->txt('obj_tool_booking'), self::BOOKING);
312  $book->setInfo($lng->txt('obj_tool_booking_info'));
313  $book->setValue("1");
314  $book->setChecked((bool) ilContainer::_lookupContainerSetting(
315  $obj_id,
316  self::BOOKING
317  ));
318  $form->addItem($book);
319  }
320 
321  if (in_array(self::EXTERNAL_MAIL_PREFIX, $services)) {
322  $externalMailPrefix = new ilTextInputGUI($lng->txt('obj_tool_ext_mail_subject_prefix'), self::EXTERNAL_MAIL_PREFIX);
323  $externalMailPrefix->setMaxLength(50);
324  $externalMailPrefix->setInfo($lng->txt('obj_tool_ext_mail_subject_prefix_info'));
325  $externalMailPrefix->setValue(ilContainer::_lookupContainerSetting($obj_id, self::EXTERNAL_MAIL_PREFIX, ''));
326  $form->addItem($externalMailPrefix);
327  }
328 
329  return $form;
330  }
331 
335  public static function updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services): bool
336  {
337  // info
338  if (in_array(self::INFO_TAB_VISIBILITY, $services)) {
340  $obj_id,
341  self::INFO_TAB_VISIBILITY,
342  $form->getInput(self::INFO_TAB_VISIBILITY)
343  );
344  }
345 
346  // calendar
347  if (in_array(self::CALENDAR_CONFIGURATION, $services)) {
348  if (ilCalendarSettings::_getInstance()->isEnabled()) {
349  $active = $form->getInput(self::CALENDAR_ACTIVATION);
350  $visible = $form->getInput(self::CALENDAR_VISIBILITY);
352  $obj_id,
353  self::CALENDAR_ACTIVATION,
354  $active
355  );
357  $obj_id,
358  self::CALENDAR_VISIBILITY,
359  $active ? $visible : ""
360  );
361  }
362  }
363  // news
364  if (in_array(self::USE_NEWS, $services)) {
365  ilContainer::_writeContainerSetting($obj_id, self::USE_NEWS, $form->getInput(self::USE_NEWS));
366  }
367  if (in_array(self::NEWS_VISIBILITY, $services)) {
368  ilContainer::_writeContainerSetting($obj_id, self::NEWS_VISIBILITY, $form->getInput(self::NEWS_VISIBILITY));
369 
370  if (in_array(ilObject::_lookupType($obj_id), ['crs', 'grp'])) {
371  $refs = ilObject::_getAllReferences($obj_id);
372  $ref_id = array_pop($refs);
373 
375  }
376  }
377 
378  // rating
379  if (in_array(self::AUTO_RATING_NEW_OBJECTS, $services)) {
381  $obj_id,
382  self::AUTO_RATING_NEW_OBJECTS,
383  $form->getInput(self::AUTO_RATING_NEW_OBJECTS)
384  );
385  }
386 
387  // taxonomies
388  if (in_array(self::TAXONOMIES, $services)) {
389  ilContainer::_writeContainerSetting($obj_id, self::TAXONOMIES, $form->getInput(self::TAXONOMIES));
390  }
391 
392  // tag cloud
393  if (in_array(self::TAG_CLOUD, $services)) {
394  ilContainer::_writeContainerSetting($obj_id, self::TAG_CLOUD, $form->getInput(self::TAG_CLOUD));
395  }
396 
397  // (local) custom metadata
398  if (in_array(self::CUSTOM_METADATA, $services)) {
399  ilContainer::_writeContainerSetting($obj_id, self::CUSTOM_METADATA, $form->getInput(self::CUSTOM_METADATA));
400  }
401 
402  // badges
403  if (in_array(self::BADGES, $services)) {
404  if (ilBadgeHandler::getInstance()->isActive()) {
405  ilContainer::_writeContainerSetting($obj_id, self::BADGES, $form->getInput(self::BADGES));
406  }
407  }
408 
409  // booking
410  if (in_array(self::BOOKING, $services)) {
411  ilContainer::_writeContainerSetting($obj_id, self::BOOKING, $form->getInput(self::BOOKING));
412  }
413 
414  // extended user access
415  if (in_array(self::ORGU_POSITION_ACCESS, $services)) {
416  $position_settings = ilOrgUnitGlobalSettings::getInstance()->getObjectPositionSettingsByType(
417  ilObject::_lookupType($obj_id)
418  );
419 
420  if ($position_settings->isActive() && $position_settings->isChangeableForObject()) {
421  $orgu_object_settings = new ilOrgUnitObjectPositionSetting($obj_id);
422  $orgu_object_settings->setActive(
423  (bool) $form->getInput(self::ORGU_POSITION_ACCESS)
424  );
425  $orgu_object_settings->update();
426  }
427  }
428 
429  // skills
430  if (in_array(self::SKILLS, $services)) {
431  $skmg_set = new ilSetting("skmg");
432  if ($skmg_set->get("enable_skmg")) {
433  ilContainer::_writeContainerSetting($obj_id, self::SKILLS, $form->getInput(self::SKILLS));
434  }
435  }
436 
437  // filter
438  if (in_array(self::FILTER, $services)) {
439  ilContainer::_writeContainerSetting($obj_id, self::FILTER, $form->getInput(self::FILTER));
440  ilContainer::_writeContainerSetting($obj_id, "filter_show_empty", $form->getInput("filter_show_empty"));
441  }
442 
443  if (in_array(self::EXTERNAL_MAIL_PREFIX, $services)) {
445  $obj_id,
446  self::EXTERNAL_MAIL_PREFIX,
447  mb_substr($form->getInput(self::EXTERNAL_MAIL_PREFIX), 0, 50)
448  );
449  }
450 
451  return true;
452  }
453 
454 
459  public function getModes(): array
460  {
461  return $this->modes;
462  }
463 
467  public function getObjId(): int
468  {
469  return $this->obj_id;
470  }
471 
472  protected function cancel(): void
473  {
474  $this->ctrl->returnToParent($this);
475  }
476 
481  protected function editSettings(?ilPropertyFormGUI $form = null): void
482  {
483  if (!$form instanceof ilPropertyFormGUI) {
484  // TODO: cant find initSettingsForm, is editSettings ever called?
485  $form = $this->initSettingsForm();
486  }
487  $this->main_tpl->setContent($form->getHTML());
488  }
489 
493  protected function isModeActive(string $mode): bool
494  {
495  return in_array($mode, $this->getModes(), true);
496  }
497 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static lookupCalendarActivated(int $a_obj_id)
editSettings(?ilPropertyFormGUI $form=null)
Edit tool settings (calendar, news, comments, ...)
static _getAllReferences(int $id)
get all reference ids for object ID
__construct(ilObjectGUI $parent_gui, int $obj_id, array $modes)
Constructor.
loadLanguageModule(string $a_module)
Load language module.
static updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isModeActive(string $mode)
Check if specific mode is active.
$ref_id
Definition: ltiauth.php:65
$GLOBALS["DIC"]
Definition: wac.php:53
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: shib_login.php:26
static initServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
static importFromForm(int $a_ref_id, ?ilPropertyFormGUI $a_form=null)
static lookupCalendarContentPresentationEnabled(int $obj_id)
static _writeContainerSetting(int $a_id, string $a_keyword, string $a_value)
global $ilSetting
Definition: privfeed.php:31
$info
Definition: entry_point.php:21
static _lookupContainerSetting(int $a_id, string $a_keyword, ?string $a_default_value=null)
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
GUI class for service settings (calendar, notes, comments)
static _lookupType(int $id, bool $reference=false)
static addToSettingsForm(int $a_ref_id, ?ilPropertyFormGUI $a_form=null, ?ilFormPropertyGUI $a_input=null)
Add notification settings to form.