ILIAS  release_8 Revision v8.24
class.ilADNNotificationGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 public const TAB_TABLE = 'notifications';
28 public const CMD_DEFAULT = 'index';
29 public const CMD_ADD = 'add';
30 public const CMD_CREATE = 'save';
31 public const CMD_UPDATE = 'update';
32 public const CMD_EDIT = 'edit';
33 public const CMD_CANCEL = 'cancel';
34 public const CMD_DELETE = 'delete';
35 public const CMD_CONFIRM_DELETE = 'confirmDelete';
36 public const CMD_CONFIRM_RESET = 'confirmReset';
37 public const CMD_RESET = 'reset';
38
39 protected function dispatchCommand($cmd): string
40 {
41 $this->tab_handling->initTabs(
44 true
45 );
46 switch ($cmd) {
47 case self::CMD_ADD:
48 return $this->add();
50 return $this->create();
51 case self::CMD_EDIT:
52 return $this->edit();
54 return $this->update();
56 return $this->confirmDelete();
58 $this->delete();
59 break;
61 return $this->confirmReset();
62 case self::CMD_RESET:
63 $this->reset();
64 break;
66 default:
67 return $this->index();
68
69 }
70
71 return "";
72 }
73
74 protected function index(): string
75 {
76 if ($this->access->hasUserPermissionTo('write')) {
77 $button = ilLinkButton::getInstance();
78 $button->setCaption($this->lng->txt('common_add_msg'), false);
79 $button->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD));
80 $this->toolbar->addButtonInstance($button);
81 }
82
83 return (new ilADNNotificationTableGUI($this, self::CMD_DEFAULT))->getHTML();
84 }
85
86 protected function add(): string
87 {
90 $this->ctrl->getLinkTarget($this, self::CMD_CREATE)
91 );
92 return $form->getHTML();
93 }
94
95 protected function create(): string
96 {
99 $this->ctrl->getLinkTarget($this, self::CMD_CREATE)
100 );
101 $form->setValuesByPost();
102 if ($form->saveObject()) {
103 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_created'), true);
104 $this->ctrl->redirect($this, self::CMD_DEFAULT);
105 }
106 return $form->getHTML();
107 }
108
109 protected function cancel(): void
110 {
111 $this->ctrl->setParameter($this, self::IDENTIFIER, null);
112 $this->ctrl->redirect($this, self::CMD_DEFAULT);
113 }
114
115 protected function edit(): string
116 {
117 $notification = $this->getNotificationFromRequest();
118 $this->ctrl->setParameter($this, ilADNAbstractGUI::IDENTIFIER, $notification->getId());
119
120 $form = new ilADNNotificationUIFormGUI($notification, $this->ctrl->getLinkTarget($this, self::CMD_UPDATE));
121 return $form->getHTML();
122 }
123
124 protected function update(): string
125 {
126 $notification = $this->getNotificationFromRequest();
127 $form = new ilADNNotificationUIFormGUI($notification, $this->ctrl->getLinkTarget($this, self::CMD_UPDATE));
128 $form->setValuesByPost();
129 if ($form->saveObject()) {
130 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_updated'), true);
131 $this->ctrl->redirect($this, self::CMD_DEFAULT);
132 }
133 return $form->getHTML();
134 }
135
136 protected function confirmDelete(): string
137 {
138 $notification = $this->getNotificationFromRequest();
139 $confirmation = new ilConfirmationGUI();
140 $confirmation->setFormAction($this->ctrl->getFormAction($this));
141 $confirmation->addItem(self::IDENTIFIER, $notification->getId(), $notification->getTitle());
142 $confirmation->setCancel($this->lng->txt('msg_form_button_cancel'), self::CMD_CANCEL);
143 $confirmation->setConfirm($this->lng->txt('msg_form_button_delete'), self::CMD_DELETE);
144
145 return $confirmation->getHTML();
146 }
147
148 protected function delete(): void
149 {
150 $notification = $this->getNotificationFromRequest();
151 $notification->delete();
152 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_deleted'), true);
153 $this->cancel();
154 }
155
156 protected function confirmReset(): string
157 {
158 $notification = $this->getNotificationFromRequest();
159 $confirmation = new ilConfirmationGUI();
160 $confirmation->setFormAction($this->ctrl->getFormAction($this));
161 $confirmation->addItem(self::IDENTIFIER, $notification->getId(), $notification->getTitle());
162 $confirmation->setCancel($this->lng->txt('msg_form_button_cancel'), self::CMD_CANCEL);
163 $confirmation->setConfirm($this->lng->txt('msg_form_button_reset'), self::CMD_RESET);
164
165 return $confirmation->getHTML();
166 }
167
168 protected function reset(): void
169 {
170 $notification = $this->getNotificationFromRequest();
171
172 $notification->resetForAllUsers();
173 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_reset'), true);
174 $this->cancel();
175 }
176
179 {
180 if (isset($this->http->request()->getParsedBody()[self::IDENTIFIER])) {
181 $identifier = $this->http->request()->getParsedBody()[self::IDENTIFIER];
182 } elseif (isset($this->http->request()->getParsedBody()['interruptive_items'][0])) {
183 $identifier = $this->http->request()->getParsedBody()['interruptive_items'][0];
184 } else {
185 $identifier = $this->http->request()->getQueryParams()[self::IDENTIFIER] ?? null;
186 }
187
188 return ilADNNotification::findOrFail($identifier);
189 }
190}
static findOrFail($primary_key, array $add_constructor_args=array())
Tries to find the object and throws an Exception if object is not found, instead of returning null.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getNotificationFromRequest()
@noinspection PhpIncompatibleReturnTypeInspection
Class ilADNNotificationTableGUI.
Class ilADNNotificationUIFormGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.