ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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_DUPLICATE = 'duplicate';
34  public const CMD_CANCEL = 'cancel';
35  public const CMD_DELETE = 'delete';
36  public const CMD_RESET = 'reset';
37 
38  protected function dispatchCommand($cmd): string
39  {
40  $this->tab_handling->initTabs(
43  true
44  );
45  switch ($cmd) {
46  case self::CMD_ADD:
47  return $this->add();
48  case self::CMD_CREATE:
49  return $this->create();
50  case self::CMD_EDIT:
51  return $this->edit();
52  case self::CMD_DUPLICATE:
53  $this->duplicate();
54  break;
55  case self::CMD_UPDATE:
56  return $this->update();
57  case self::CMD_DELETE:
58  $this->delete();
59  break;
60  case self::CMD_RESET:
61  $this->reset();
62  break;
63  case self::CMD_DEFAULT:
64  default:
65  return $this->index();
66  }
67 
68  return "";
69  }
70 
71  protected function index(): string
72  {
73  if ($this->access->hasUserPermissionTo('write')) {
74  $btn_add_msg = $this->ui->factory()->button()->standard(
75  $this->lng->txt('common_add_msg'),
76  $this->ctrl->getLinkTarget($this, self::CMD_ADD)
77  );
78  $this->toolbar->addComponent($btn_add_msg);
79  }
80 
81  return (new ilADNNotificationTableGUI($this, self::CMD_DEFAULT))->getHTML();
82  }
83 
84  protected function add(): string
85  {
86  $form = new ilADNNotificationUIFormGUI(
87  new ilADNNotification(),
88  $this->ctrl->getLinkTarget($this, self::CMD_CREATE)
89  );
90  return $form->getHTML();
91  }
92 
93  protected function create(): string
94  {
95  $form = new ilADNNotificationUIFormGUI(
96  new ilADNNotification(),
97  $this->ctrl->getLinkTarget($this, self::CMD_CREATE)
98  );
99  $form->setValuesByPost();
100  if ($form->saveObject()) {
101  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_created'), true);
102  $this->ctrl->redirect($this, self::CMD_DEFAULT);
103  }
104  return $form->getHTML();
105  }
106 
107  protected function cancel(): void
108  {
109  $this->ctrl->setParameter($this, self::IDENTIFIER, null);
110  $this->ctrl->redirect($this, self::CMD_DEFAULT);
111  }
112 
113  protected function edit(): string
114  {
115  $notification = $this->getNotificationFromRequest();
116  $this->ctrl->setParameter($this, ilADNAbstractGUI::IDENTIFIER, $notification->getId());
117 
118  $form = new ilADNNotificationUIFormGUI($notification, $this->ctrl->getLinkTarget($this, self::CMD_UPDATE));
119  return $form->getHTML();
120  }
121 
122  protected function duplicate(): void
123  {
124  $notification = $this->getNotificationFromRequest();
125  $notification->setId(0);
126  $notification->create();
127  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_duplicated'), true);
128  $this->cancel();
129  }
130 
131  protected function update(): string
132  {
133  $notification = $this->getNotificationFromRequest();
134  $form = new ilADNNotificationUIFormGUI($notification, $this->ctrl->getLinkTarget($this, self::CMD_UPDATE));
135  $form->setValuesByPost();
136  if ($form->saveObject()) {
137  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_updated'), true);
138  $this->ctrl->redirect($this, self::CMD_DEFAULT);
139  }
140  return $form->getHTML();
141  }
142 
143  protected function delete(): void
144  {
145  $notification = $this->getNotificationFromRequest();
146  $notification->delete();
147  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_deleted'), true);
148  $this->cancel();
149  }
150 
151  protected function reset(): void
152  {
153  $notification = $this->getNotificationFromRequest();
154 
155  $notification->resetForAllUsers();
156  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_success_reset'), true);
157  $this->cancel();
158  }
159 
162  {
163  if (isset($this->http->request()->getParsedBody()[self::IDENTIFIER])) {
164  $identifier = $this->http->request()->getParsedBody()[self::IDENTIFIER];
165  } elseif (isset($this->http->request()->getParsedBody()['interruptive_items'][0])) {
166  $identifier = $this->http->request()->getParsedBody()['interruptive_items'][0];
167  } else {
168  $identifier = $this->http->request()->getQueryParams()[self::IDENTIFIER] ?? null;
169  }
170 
171  return ilADNNotification::findOrFail($identifier);
172  }
173 }
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 findOrFail($primary_key, array $add_constructor_args=[])
Tries to find the object and throws an Exception if object is not found, instead of returning null...
getNotificationFromRequest()
PhpIncompatibleReturnTypeInspection
static http()
Fetches the global http state from ILIAS.
Class ilADNNotificationTableGUI.