ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilADNNotificationTableGUI.php
Go to the documentation of this file.
1 <?php
2 
23 
30 {
31  protected \ILIAS\Data\Factory $data_factory;
32 
33  protected \ILIAS\DI\UIServices $ui;
34  protected \ilObjAdministrativeNotificationAccess $access;
38  protected array $modals = [];
39 
44  public function __construct(ilADNNotificationGUI $a_parent_obj, string $a_parent_cmd)
45  {
46  global $DIC;
50  $this->ctrl = $DIC->ctrl();
51  $this->lng = $DIC->language();
52  $this->data_factory = new Factory();
53  $this->ui = $DIC->ui();
55 
56  $this->setId('msg_msg_table');
57  $this->setRowTemplate('Services/AdministrativeNotification/templates/default/tpl.row.html');
58  parent::__construct($a_parent_obj, $a_parent_cmd);
59  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
60  //
61  // Columns
62  $this->addColumn($this->lng->txt('msg_title'));
63  $this->addColumn($this->lng->txt('msg_type'));
64  $this->addColumn($this->lng->txt('msg_languages'));
65  $this->addColumn($this->lng->txt('msg_type_during_event'));
66  $this->addColumn($this->lng->txt('msg_event_date_start'));
67  $this->addColumn($this->lng->txt('msg_event_date_end'));
68  $this->addColumn($this->lng->txt('msg_display_date_start'));
69  $this->addColumn($this->lng->txt('msg_display_date_end'));
70  $this->addColumn($this->lng->txt('common_actions'));
71 
72  $this->initData();
73  }
74 
75  protected function initData(): void
76  {
78  }
79 
80  protected function formatDate(DateTimeImmutable $timestamp): string
81  {
82  return ilDatePresentation::formatDate(new ilDateTime($timestamp->getTimestamp(), IL_CAL_UNIX));
83  }
84 
85  protected function fillRow(array $a_set): void
86  {
90  $notification = ilADNNotification::find($a_set['id']);
91  $this->tpl->setVariable('TITLE', $notification->getTitle());
92  $this->tpl->setVariable('TYPE', $this->lng->txt('msg_type_' . $notification->getType()));
93  $this->tpl->setVariable('LANGUAGES', $this->getLanguagesTextForNotification($notification));
94 
95  if (!$notification->isPermanent()) {
96  $this->tpl->setVariable(
97  'TYPE_DURING_EVENT',
98  $this->lng->txt('msg_type_' . $notification->getTypeDuringEvent())
99  );
100  $this->tpl->setVariable('EVENT_START', $this->formatDate($notification->getEventStart()));
101  $this->tpl->setVariable('EVENT_END', $this->formatDate($notification->getEventEnd()));
102  $this->tpl->setVariable('DISPLAY_START', $this->formatDate($notification->getDisplayStart()));
103  $this->tpl->setVariable('DISPLAY_END', $this->formatDate($notification->getDisplayEnd()));
104  }
105  // Actions
106  if ($this->access->hasUserPermissionTo('write')) {
107  $items = [];
108  $this->ctrl->setParameter($this->parent_obj, ilADNAbstractGUI::IDENTIFIER, $notification->getId());
109 
110  $items[] = $this->ui->factory()->button()->shy(
111  $this->lng->txt('btn_' . ilADNNotificationGUI::CMD_EDIT),
112  $this->ctrl->getLinkTargetByClass(ilADNNotificationGUI::class, ilADNNotificationGUI::CMD_EDIT)
113  );
114 
115  // Modals and actions
116  $ditem = $this->ui->factory()->modal()->interruptiveItem()->standard((string) $notification->getId(), $notification->getTitle());
117  $delete_modal = $this->modal($ditem, ilADNNotificationGUI::CMD_DELETE);
118  $items[] = $this->ui->factory()->button()->shy($this->lng->txt('btn_' . ilADNNotificationGUI::CMD_DELETE), "")
119  ->withOnClick($delete_modal->getShowSignal());
120  $this->modals[] = $delete_modal;
121 
122  $reset_modal = $this->modal($ditem, ilADNNotificationGUI::CMD_RESET);
123  $items[] = $this->ui->factory()->button()->shy($this->lng->txt('btn_' . ilADNNotificationGUI::CMD_RESET), "")
124  ->withOnClick($reset_modal->getShowSignal());
125  $this->modals[] = $reset_modal;
126 
127  $items[] = $this->ui->factory()->button()->shy(
128  $this->lng->txt('btn_' . ilADNNotificationGUI::CMD_DUPLICATE),
129  $this->ctrl->getLinkTargetByClass(ilADNNotificationGUI::class, ilADNNotificationGUI::CMD_DUPLICATE)
130  );
131 
132  $actions = $this->ui->renderer()->render([$this->ui->factory()->dropdown()->standard($items)->withLabel($this->lng->txt('actions'))]);
133 
134  $this->tpl->setVariable('ACTIONS', $actions);
135  } else {
136  $this->tpl->setVariable('ACTIONS', "");
137  }
138  }
139 
140  protected function modal(InterruptiveItem $i, string $cmd): Interruptive
141  {
142  $action = $this->ctrl->getLinkTargetByClass(ilADNNotificationGUI::class, $cmd);
143 
144  return $this->ui->factory()->modal()
145  ->interruptive(
146  $this->lng->txt('btn_' . $cmd),
147  $this->lng->txt('btn_' . $cmd . '_confirm'),
148  $action
149  )
150  ->withAffectedItems([$i])
151  ->withActionButtonLabel($this->lng->txt($cmd));
152  }
153 
154  public function getHTML(): string
155  {
156  return parent::getHTML() . $this->ui->renderer()->render($this->modals);
157  }
158 
159  protected function getLanguagesTextForNotification(ilADNNotification $notification): string
160  {
161  $has_language_limitation = $notification->hasLanguageLimitation();
162  $limited_to_languages = $notification->getLimitedToLanguages();
163  // text is all by default
164  $languages_text = $this->lng->txt("all");
165  if ($has_language_limitation) {
166  // text is none in case the notification has a language limitation but no languages are specified
167  $languages_text = $this->lng->txt("none");
168  if (!empty($limited_to_languages)) {
169  $this->lng->loadLanguageModule("meta");
170  // text is comma separated list of languages if the notification has a language limitation
171  // and the languages have been specified
172  $languages_text = implode(
173  ', ',
174  array_map(
175  function (string $lng_code): string {
176  return $this->lng->txt("meta_l_" . $lng_code);
177  },
178  $limited_to_languages
179  )
180  );
181  }
182  }
183 
184  return $languages_text;
185  }
186 }
setData(array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getArray(?string $key=null, $values=null)
setFormAction(string $a_form_action, bool $a_multipart=false)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
modal(InterruptiveItem $i, string $cmd)
const IL_CAL_UNIX
setId(string $a_val)
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
formatDate(DateTimeImmutable $timestamp)
fillRow(array $a_set)
Standard Version of Fill Row.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
ilObjAdministrativeNotificationAccess $access
Class ilADNNotificationTableGUI.
getLanguagesTextForNotification(ilADNNotification $notification)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(?object $a_parent_obj, string $a_parent_cmd="", string $a_template_context="")