ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjContentPageAdministrationGUI.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
3
6use Psr\Http\Message\ServerRequestInterface;
11
18{
19 private const CMD_VIEW = 'view';
20 private const CMD_EDIT = 'edit';
21 private const CMD_SAVE = 'save';
22
23 private const F_READING_TIME = 'reading_time';
24
26 private $httpRequest;
28 private $uiFactory;
30 private $uiRenderer;
32 private $refinery;
36 private $error;
37
41 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
42 {
43 global $DIC;
44
45 $this->type = 'cpad';
46 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
47 $this->lng->loadLanguageModule($this->type);
48
49 $this->uiFactory = $DIC->ui()->factory();
50 $this->uiRenderer = $DIC->ui()->renderer();
51 $this->httpRequest = $DIC->http()->request();
52 $this->refinery = $DIC->refinery();
53 $this->error = $DIC['ilErr'];
54 $this->settingsStorage = new StorageImpl($DIC->settings());
55 }
56
60 public function getAdminTabs()
61 {
62 if ($this->rbacsystem->checkAccess('visible,read', $this->object->getRefId())) {
63 $this->tabs_gui->addTarget('settings', $this->ctrl->getLinkTargetByClass(self::class, self::CMD_EDIT));
64 }
65
66 if ($this->rbacsystem->checkAccess('edit_permission', $this->object->getRefId())) {
67 $this->tabs_gui->addTarget('perm_settings', $this->ctrl->getLinkTargetByClass('ilpermissiongui', 'perm'), [], 'ilpermissiongui');
68 }
69 }
70
74 public function executeCommand()
75 {
76 if (!$this->rbacsystem->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 'ilpermissiongui':
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 Exception(__METHOD__ . " :: Unknown command " . $cmd);
102 }
103 }
104 }
105
110 private function getForm(array $values = []) : Form
111 {
112 $action = $this->ctrl->getLinkTargetByClass(self::class, self::CMD_SAVE);
113
114 $readingTimeStatus = $this->uiFactory
115 ->input()
116 ->field()
117 ->checkbox(
118 $this->lng->txt('cpad_reading_time_status'),
119 $this->lng->txt('cpad_reading_time_status_desc')
120 );
121
122 if (isset($values[self::F_READING_TIME])) {
123 $readingTimeStatus = $readingTimeStatus->withValue($values[self::F_READING_TIME]);
124 }
125
126 $section = $this->uiFactory->input()->field()->section(
127 [self::F_READING_TIME => $readingTimeStatus],
128 $this->lng->txt('settings')
129 );
130
131 return $this->uiFactory
132 ->input()
133 ->container()
134 ->form()
135 ->standard($action, [$section])
136 ->withAdditionalTransformation($this->refinery->custom()->transformation(static function ($values) : array {
137 return call_user_func_array('array_merge', $values);
138 }));
139 }
140
144 protected function show(array $components) : void
145 {
146 $this->tpl->setContent(
147 $this->uiRenderer->render($components)
148 );
149 }
150
151 protected function edit() : void
152 {
153 $values = [
154 self::F_READING_TIME => $this->settingsStorage->getSettings()->isReadingTimeEnabled(),
155 ];
156
157 $form = $this->getForm($values);
158
159 $this->show([$form]);
160 }
161
162 protected function save() : void
163 {
164 if (!$this->checkPermissionBool('write')) {
165 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
166 }
167
168 $form = $this->getForm()->withRequest($this->httpRequest);
169
170 $data = $form->getData();
171 if ($data) {
172 $readingTime = $data[self::F_READING_TIME];
173 $settings = $this->settingsStorage->getSettings()
174 ->withDisabledReadingTime();
175 if ($readingTime) {
176 $settings = $settings->withEnabledReadingTime();
177 }
178 $this->settingsStorage->store($settings);
179 }
180
181 $this->show(
182 [$this->uiFactory->messageBox()->success($this->lng->txt('saved_successfully')), $form]
183 );
184 }
185}
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
error($a_errmsg)
set error message @access public
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
@ineritdoc
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput($a_show_subobjects=true)
prepare output
checkPermissionBool($a_perm, $a_cmd="", $a_type="", $a_ref_id=null)
Check permission.
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
global $DIC
Definition: goto.php:24
A component is the most general form of an entity in the UI.
Definition: Component.php:14
This describes a standard form.
Definition: Standard.php:11
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc