ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjContentPageAdministrationGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 
33 {
34  private const CMD_VIEW = 'view';
35  private const CMD_EDIT = 'edit';
36  private const CMD_SAVE = 'save';
37  private const F_READING_TIME = 'reading_time';
38 
43 
44  public function __construct($a_data, int $a_id, bool $a_call_by_reference = true, bool $a_prepare_output = true)
45  {
46  global $DIC;
47 
48  $this->type = 'cpad';
49  parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
50  $this->lng->loadLanguageModule($this->type);
51 
52  $this->uiFactory = $DIC->ui()->factory();
53  $this->uiRenderer = $DIC->ui()->renderer();
54  $this->http = $DIC->http();
55  $this->settingsStorage = new StorageImpl($DIC->settings());
56  }
57 
58  public function getAdminTabs(): void
59  {
60  if ($this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
61  $this->tabs_gui->addTarget('settings', $this->ctrl->getLinkTargetByClass(self::class, self::CMD_EDIT));
62  }
63 
64  if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
65  $this->tabs_gui->addTarget(
66  'perm_settings',
67  $this->ctrl->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
68  [],
69  ilPermissionGUI::class
70  );
71  }
72  }
73 
74  public function executeCommand(): void
75  {
76  if (!$this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
77  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
78  }
79 
80  $nextClass = $this->ctrl->getNextClass($this);
81  $cmd = $this->ctrl->getCmd();
82  $this->prepareOutput();
83 
84  switch (strtolower($nextClass)) {
85  case strtolower(ilPermissionGUI::class):
86  $this->tabs_gui->setTabActive('perm_settings');
87  $perm_gui = new ilPermissionGUI($this);
88  $this->ctrl->forwardCommand($perm_gui);
89  break;
90 
91  default:
92  switch ($cmd) {
93  case self::CMD_VIEW:
94  case self::CMD_EDIT:
95  $this->edit();
96  break;
97  case self::CMD_SAVE:
98  $this->save();
99  break;
100  default:
101  throw new RuntimeException(__METHOD__ . ' :: Unknown command ' . $cmd);
102  }
103  }
104  }
105 
106  private function getForm(array $values = []): Form
107  {
108  $action = $this->ctrl->getLinkTargetByClass(self::class, self::CMD_SAVE);
109 
110  $readingTimeStatus = $this->uiFactory
111  ->input()
112  ->field()
113  ->checkbox(
114  $this->lng->txt('cpad_reading_time_status'),
115  $this->lng->txt('cpad_reading_time_status_desc')
116  );
117 
118  if (isset($values[self::F_READING_TIME])) {
119  $readingTimeStatus = $readingTimeStatus->withValue($values[self::F_READING_TIME]);
120  }
121 
122  $section = $this->uiFactory->input()->field()->section(
123  [self::F_READING_TIME => $readingTimeStatus],
124  $this->lng->txt('settings')
125  );
126 
127  return $this->uiFactory
128  ->input()
129  ->container()
130  ->form()
131  ->standard($action, [$section])
132  ->withAdditionalTransformation($this->refinery->custom()->transformation(static function ($values): array {
133  return array_merge(...$values);
134  }));
135  }
136 
140  protected function show(array $components): void
141  {
142  $this->tpl->setContent(
143  $this->uiRenderer->render($components)
144  );
145  }
146 
147  protected function edit(): void
148  {
149  $values = [
150  self::F_READING_TIME => $this->settingsStorage->getSettings()->isReadingTimeEnabled(),
151  ];
152 
153  $form = $this->getForm($values);
154 
155  $this->show([$form]);
156  }
157 
158  protected function save(): void
159  {
160  if (!$this->checkPermissionBool('write')) {
161  $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
162  }
163 
164  $form = $this->getForm()->withRequest($this->http->request());
165  $data = $form->getData();
166  if ($data) {
167  $readingTime = $data[self::F_READING_TIME];
168  $settings = $this->settingsStorage->getSettings()
169  ->withDisabledReadingTime();
170  if ($readingTime) {
171  $settings = $settings->withEnabledReadingTime();
172  }
173  $this->settingsStorage->store($settings);
174  }
175 
176  $this->show(
177  [$this->uiFactory->messageBox()->success($this->lng->txt('saved_successfully')), $form]
178  );
179  }
180 }
Interface GlobalHttpState.
An entity that renders components to a string output.
Definition: Renderer.php:30
__construct($a_data, int $a_id, bool $a_call_by_reference=true, bool $a_prepare_output=true)
prepareOutput(bool $show_sub_objects=true)
global $DIC
Definition: feed.php:28
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.
Class ilObjectGUI Basic methods of all Output classes.
ilObjContentPageAdministrationGUI: ilPermissionGUI
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
__construct(Container $dic, ilPlugin $plugin)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
ilSetting $settings