ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADNNotificationGUI.php
Go to the documentation of this file.
1<?php
2
10{
11 public const TAB_TABLE = 'notifications';
12 public const CMD_DEFAULT = 'index';
13 public const CMD_ADD = 'add';
14 public const CMD_CREATE = 'save';
15 public const CMD_UPDATE = 'update';
16 public const CMD_EDIT = 'edit';
17 public const CMD_CANCEL = 'cancel';
18 public const CMD_DELETE = 'delete';
19 public const CMD_CONFIRM_DELETE = 'confirmDelete';
20 public const CMD_CONFIRM_RESET = 'confirmReset';
21 public const CMD_RESET = 'reset';
22
23 protected function dispatchCommand($cmd) : string
24 {
25 $this->tab_handling->initTabs(
28 true,
29 self::class
30 );
31 switch ($cmd) {
32 case self::CMD_ADD:
33 return $this->add();
35 return $this->create();
36 case self::CMD_EDIT:
37 return $this->edit();
39 return $this->update();
41 return $this->confirmDelete();
43 $this->delete();
44 break;
46 return $this->confirmReset();
47 case self::CMD_RESET:
48 return $this->reset();
50 default:
51 return $this->index();
52
53 }
54
55 return "";
56 }
57
58 protected function index() : string
59 {
60 if ($this->access->hasUserPermissionTo('write')) {
61 $button = ilLinkButton::getInstance();
62 $button->setCaption($this->lng->txt('common_add_msg'), false);
63 $button->setUrl($this->ctrl->getLinkTarget($this, self::CMD_ADD));
64 $this->toolbar->addButtonInstance($button);
65 }
66
67 $notMessageTableGUI = new ilADNNotificationTableGUI($this, self::CMD_DEFAULT);
68 return $notMessageTableGUI->getHTML();
69 }
70
71 protected function add() : string
72 {
75 $this->ctrl->getLinkTarget($this, self::CMD_CREATE)
76 );
77 $form->fillForm();
78 return $form->getHTML();
79 }
80
81 protected function create() : string
82 {
85 $this->ctrl->getLinkTarget($this, self::CMD_CREATE)
86 );
87 $form->setValuesByPost();
88 if ($form->saveObject()) {
89 ilUtil::sendSuccess($this->lng->txt('msg_success_created'), true);
90 $this->ctrl->redirect($this, self::CMD_DEFAULT);
91 }
92 return $form->getHTML();
93 }
94
95 protected function cancel() : string
96 {
97 $this->ctrl->setParameter($this, self::IDENTIFIER, null);
98 $this->ctrl->redirect($this, self::CMD_DEFAULT);
99 }
100
101 protected function edit() : string
102 {
103 $notification = $this->getNotificationFromRequest();
104 $this->ctrl->setParameter($this, ilADNNotificationGUI::IDENTIFIER, $notification->getId());
105
106 $form = new ilADNNotificationUIFormGUI($notification, $this->ctrl->getLinkTarget($this, self::CMD_UPDATE));
107 $form->fillForm();
108 return $form->getHTML();
109 }
110
111 protected function update() : string
112 {
113 $notification = $this->getNotificationFromRequest();
114 $form = new ilADNNotificationUIFormGUI($notification, $this->ctrl->getLinkTarget($this, self::CMD_UPDATE));
115 $form->setValuesByPost();
116 if ($form->saveObject()) {
117 ilUtil::sendSuccess($this->lng->txt('msg_success_updated'), true);
118 $this->ctrl->redirect($this, self::CMD_DEFAULT);
119 }
120 return $form->getHTML();
121 }
122
123 protected function confirmDelete() : string
124 {
125 $notification = $this->getNotificationFromRequest();
126 $confirmation = new ilConfirmationGUI();
127 $confirmation->setFormAction($this->ctrl->getFormAction($this));
128 $confirmation->addItem(self::IDENTIFIER, $notification->getId(), $notification->getTitle());
129 $confirmation->setCancel($this->lng->txt('msg_form_button_cancel'), self::CMD_CANCEL);
130 $confirmation->setConfirm($this->lng->txt('msg_form_button_delete'), self::CMD_DELETE);
131
132 return $confirmation->getHTML();
133 }
134
135 protected function delete() : void
136 {
137 $notification = $this->getNotificationFromRequest();
138 $notification->delete();
139 ilUtil::sendSuccess($this->lng->txt('msg_success_deleted'), true);
140 $this->cancel();
141 }
142
143 protected function confirmReset() : string
144 {
145 $notification = $this->getNotificationFromRequest();
146 $confirmation = new ilConfirmationGUI();
147 $confirmation->setFormAction($this->ctrl->getFormAction($this));
148 $confirmation->addItem(self::IDENTIFIER, $notification->getId(), $notification->getTitle());
149 $confirmation->setCancel($this->lng->txt('msg_form_button_cancel'), self::CMD_CANCEL);
150 $confirmation->setConfirm($this->lng->txt('msg_form_button_reset'), self::CMD_RESET);
151
152 return $confirmation->getHTML();
153 }
154
155 protected function reset()
156 {
157 $notification = $this->getNotificationFromRequest();
158
159 $notification->resetForAllUsers();
160 ilUtil::sendSuccess($this->lng->txt('msg_success_reset'), true);
161 $this->cancel();
162 }
163
168 {
169 if (isset($this->http->request()->getParsedBody()[self::IDENTIFIER])) {
170 $identifier = $this->http->request()->getParsedBody()[self::IDENTIFIER];
171 } elseif (isset($this->http->request()->getParsedBody()['interruptive_items'][0])) {
172 $identifier = $this->http->request()->getParsedBody()['interruptive_items'][0];
173 } else {
174 $identifier = $this->http->request()->getQueryParams()[self::IDENTIFIER];
175 }
176
177 return ilADNNotification::findOrFail($identifier);
178 }
179}
Class ActiveRecord.
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.
An exception for terminatinating execution or to throw for unit testing.
Class ilADNAbstractGUI.
Class ilADNNotificationGUI @ilCtrl_IsCalledBy ilADNNotificationGUI: ilObjAdministrativeNotificationGU...
Class ilADNNotificationTableGUI.
Class ilADNNotificationUIFormGUI.
Confirmation screen class.
static getInstance()
Factory.
static http()
Fetches the global http state from ILIAS.