ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilForumNotificationTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
29  private array $notification_modals = [];
30  private \ILIAS\UI\Factory $ui_factory;
32 
33  public function __construct(ilForumSettingsGUI $settings_gui, string $cmd, string $type)
34  {
35  global $DIC;
36 
37  $this->ui_factory = $DIC->ui()->factory();
38  $this->ui_renderer = $DIC->ui()->renderer();
39 
40  $this->lng = $DIC->language();
41  $this->ctrl = $DIC->ctrl();
42  $this->mainTemplate = $DIC->ui()->mainTemplate();
43 
44  $this->setId('frmev_' . $settings_gui->getRefId() . substr($type, 0, 3));
45 
46  parent::__construct($settings_gui, $cmd);
47 
48  $this->setTitle($this->lng->txt(strtolower($type)));
49  $this->setRowTemplate('tpl.forums_members_row.html', 'Modules/Forum');
50  $this->setFormAction($this->ctrl->getFormAction($settings_gui, 'showMembers'));
51 
52  $this->addColumn('', '', '1%', true);
53  $this->addColumn($this->lng->txt('login'), '', '20%');
54  $this->addColumn($this->lng->txt('firstname'), '', '20%');
55  $this->addColumn($this->lng->txt('lastname'), '', '20%');
56  $this->addColumn($this->lng->txt('allow_user_toggle_noti'), '', '20%');
57  $this->addColumn($this->lng->txt('actions'), '', '20%');
58  $this->setSelectAllCheckbox('user_id');
59 
60  $this->addMultiCommand('enableHideUserToggleNoti', $this->lng->txt('enable_hide_user_toggle'));
61  $this->addMultiCommand('disableHideUserToggleNoti', $this->lng->txt('disable_hide_user_toggle'));
62  }
63 
64  private function getIcon(int $user_toggle_noti): string
65  {
66  $icon_ok = $this->ui_factory->symbol()->icon()->custom(
67  ilUtil::getImagePath('icon_ok.svg'),
68  $this->lng->txt('enabled')
69  );
70  $icon_not_ok = $this->ui_factory->symbol()->icon()->custom(
71  ilUtil::getImagePath('icon_not_ok.svg'),
72  $this->lng->txt('disabled')
73  );
74  $icon = $user_toggle_noti === 0 ? $icon_ok : $icon_not_ok;
75 
76  return $this->ui_renderer->render($icon);
77  }
78 
79  protected function fillRow(array $a_set): void
80  {
81  $this->tpl->setVariable('VAL_USER_ID', $a_set['user_id']);
82  $this->tpl->setVariable('VAL_LOGIN', $a_set['login']);
83  $this->tpl->setVariable('VAL_FIRSTNAME', $a_set['firstname']);
84  $this->tpl->setVariable('VAL_LASTNAME', $a_set['lastname']);
85 
86  $icon_ok = $this->getIcon((int) $a_set['user_toggle_noti']);
87  $this->tpl->setVariable('VAL_USER_TOGGLE_NOTI', $icon_ok);
88 
89  $this->populateWithModal($a_set);
90  }
91 
93  {
94  $interested_events = $row['interested_events'];
95 
97  $this->ctrl->getFormAction($this->parent_obj, 'saveEventsForUser'),
98  [
99  'hidden_value' => json_encode([
100  'usr_id' => $row['usr_id_events']
101  ], JSON_THROW_ON_ERROR),
102  'notify_modified' => (bool) ($interested_events & ilForumNotificationEvents::UPDATED),
103  'notify_censored' => (bool) ($interested_events & ilForumNotificationEvents::CENSORED),
104  'notify_uncensored' => (bool) ($interested_events & ilForumNotificationEvents::UNCENSORED),
105  'notify_post_deleted' => (bool) ($interested_events & ilForumNotificationEvents::POST_DELETED),
106  'notify_thread_deleted' => (bool) ($interested_events & ilForumNotificationEvents::THREAD_DELETED),
107  ],
109  $this->lng
110  );
111  }
112 
113  private function populateWithModal(array $row): void
114  {
115  $notificationsModal = $this->ui_factory->modal()->roundtrip(
116  $this->lng->txt('notification_settings'),
117  $this->eventsFormBuilder($row)->build()
118  )->withActionButtons([
119  $this->ui_factory->button()
120  ->primary($this->lng->txt('save'), '#')
121  ->withOnLoadCode(function (string $id) use ($row): string {
122  return "
123  $('#$id').closest('.modal').find('form').addClass('ilForumNotificationSettingsForm');
124  $('#$id').closest('.modal').find('form .il-standard-form-header, .il-standard-form-footer').remove();
125  $('#$id').click(function() { $(this).closest('.modal').find('form').submit(); return false; });
126  ";
127  })
128  ]);
129 
130  $showNotificationSettingsBtn = $this->ui_factory->button()
131  ->shy($this->lng->txt('notification_settings'), '#')
132  ->withOnClick(
133  $notificationsModal->getShowSignal()
134  );
135 
136  $this->notification_modals[] = $notificationsModal;
137 
138  $this->tpl->setVariable('VAL_NOTIFICATION', $this->ui_renderer->render($showNotificationSettingsBtn));
139  }
140 
141  public function render(): string
142  {
143  return parent::render() . $this->ui_renderer->render($this->notification_modals);
144  }
145 }
setFormAction(string $a_form_action, bool $a_multipart=false)
__construct(ilForumSettingsGUI $settings_gui, string $cmd, string $type)
$type
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Class ilForumSettingsGUI.
ilLanguage $lng
setId(string $a_val)
global $DIC
Definition: feed.php:28
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
__construct(Container $dic, ilPlugin $plugin)
Class ilForumNotificationTableGUI.
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)
addMultiCommand(string $a_cmd, string $a_text)