ILIAS  release_8 Revision v8.24
class.ilObjectActivationGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
31 protected ilCtrl $ctrl;
32 protected ilLanguage $lng;
36 protected ilTree $tree;
37 protected ilObjUser $user;
38 protected ilHelpGUI $help;
41
42 protected int $parent_ref_id;
43 protected int $item_id;
44
45 protected ?int $timing_mode = null;
47
48 public function __construct(int $ref_id, int $item_id)
49 {
50 global $DIC;
51
52 $this->tpl = $DIC->ui()->mainTemplate();
53 $this->ctrl = $DIC->ctrl();
54 $this->lng = $DIC->language();
55 $this->lng->loadLanguageModule('crs');
56 $this->error = $DIC['ilErr'];
57 $this->tabs_gui = $DIC->tabs();
58 $this->access = $DIC->access();
59 $this->tree = $DIC->repositoryTree();
60 $this->user = $DIC->user();
61 $this->help = $DIC["ilHelp"];
62 $this->request_wrapper = $DIC->http()->wrapper()->query();
63 $this->refinery = $DIC->refinery();
64
65 $this->parent_ref_id = $ref_id;
66 $this->item_id = $item_id;
67
68 $this->ctrl->saveParameter($this, 'item_id');
69 }
70
71 public function executeCommand(): void
72 {
73 $this->__setTabs();
74
75 $cmd = $this->ctrl->getCmd();
76
77 // Check if item id is given and valid
78 if (!$this->item_id) {
79 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("crs_no_item_id_given"), true);
80 $this->ctrl->returnToParent($this);
81 }
82
83 $this->tpl->loadStandardTemplate();
84
85 switch ($this->ctrl->getNextClass($this)) {
86 case 'ilconditionhandlergui':
87 // preconditions for single course items
88 $this->ctrl->saveParameter($this, 'item_id');
89 $item_id = $this->request_wrapper->retrieve("item_id", $this->refinery->kindlyTo()->int());
90 $new_gui = new ilConditionHandlerGUI($item_id);
91 $this->ctrl->forwardCommand($new_gui);
92 $this->tabs_gui->setTabActive('preconditions');
93 break;
94
95 default:
96 $this->initTimingMode();
97 $this->initItem();
98 $this->tabs_gui->setTabActive('timings');
99 if (!$cmd) {
100 $cmd = 'edit';
101 }
102 $this->$cmd();
103 $this->tabs_gui->setTabActive('timings');
104 break;
105 }
106
107 $this->tpl->printToStdout();
108 }
109
110 public function getItemId(): int
111 {
112 return $this->item_id;
113 }
114
115 public function getTimingMode(): ?int
116 {
117 return $this->timing_mode;
118 }
119
120 public function getParentId(): int
121 {
123 }
124
126 {
127 return $this->activation;
128 }
129
130 public function cancel(): void
131 {
132 $this->ctrl->setParameterByClass('ilrepositorygui', 'ref_id', $this->parent_ref_id);
133 $this->ctrl->redirectByClass('ilrepositorygui');
134 }
135
136 public function edit(ilPropertyFormGUI $form = null): void
137 {
138 // #19997 - see ilObjectListGUI::insertTimingsCommand()
139 if (
140 !$this->access->checkAccess('write', '', $this->parent_ref_id) &&
141 !$this->access->checkAccess('write', '', $this->getItemId())
142 ) {
143 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
144 }
145
146 if (!$form instanceof ilPropertyFormGUI) {
147 // show edit warning if timings are on
148 if ($this->tree->checkForParentType($this->getParentId(), 'crs')) {
149 if ($this->getActivation()->getTimingType() == ilObjectActivation::TIMINGS_PRESETTING) {
150 $this->tpl->setOnScreenMessage('info', $this->lng->txt('crs_timings_warning_timing_exists'));
151 }
152 }
153
154 $form = $this->initFormEdit();
155 }
156 $this->tpl->setContent($form->getHTML());
157 }
158
159 protected function initFormEdit(): ilPropertyFormGUI
160 {
161 $form = new ilPropertyFormGUI();
162 $form->setFormAction($this->ctrl->getFormAction($this));
163
164 $title = htmlspecialchars(
166 ENT_QUOTES | ENT_SUBSTITUTE,
167 'utf-8'
168 );
169 $form->setTitle($title . ': ' . $this->lng->txt('crs_edit_timings'));
170
171 $availability = new ilCheckboxInputGUI($this->lng->txt('crs_timings_availability_enabled'), 'availability');
172 $availability->setValue("1");
173 $availability->setChecked($this->getActivation()->getTimingType() == ilObjectActivation::TIMINGS_ACTIVATION);
174
175 $start = new ilDateTimeInputGUI($this->lng->txt('crs_timings_start'), 'timing_start');
176 $start->setDate(new ilDateTime($this->getActivation()->getTimingStart(), IL_CAL_UNIX));
177 $start->setShowTime(true);
178 $availability->addSubItem($start);
179
180 $end = new ilDateTimeInputGUI($this->lng->txt('crs_timings_end'), 'timing_end');
181 $end->setDate(new ilDateTime($this->getActivation()->getTimingEnd(), IL_CAL_UNIX));
182 $end->setShowTime(true);
183 $availability->addSubItem($end);
184
185 $isv = new ilCheckboxInputGUI($this->lng->txt('crs_timings_visibility_short'), 'visible');
186 $isv->setInfo($this->lng->txt('crs_timings_visibility'));
187 $isv->setValue("1");
188 $isv->setChecked($this->getActivation()->enabledVisible());
189 $availability->addSubItem($isv);
190
191 $form->addItem($availability);
192
193 $form->addCommandButton('update', $this->lng->txt('save'));
194 $form->addCommandButton('cancel', $this->lng->txt('cancel'));
195
196 return $form;
197 }
198
199 public function update(): void
200 {
201 // #19997 - see ilObjectListGUI::insertTimingsCommand()
202 if (
203 !$this->access->checkAccess('write', '', $this->parent_ref_id) &&
204 !$this->access->checkAccess('write', '', $this->getItemId())
205 ) {
206 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
207 }
208
209 $form = $this->initFormEdit();
210 if ($form->checkInput()) {
211 $valid = true;
213 $activation->read($this->getItemId());
214
215 if ($form->getInput('availability')) {
217
218 $timing_start = $form->getItemByPostVar('timing_start')->getDate();
219 $timing_end = $form->getItemByPostVar('timing_end')->getDate();
220
221 if ($timing_start && $timing_end && ilDateTime::_after($timing_start, $timing_end)) {
222 $form->getItemByPostVar('timing_start')->setAlert($this->lng->txt('crs_timing_err_start_end'));
223 $form->getItemByPostVar('timing_end')->setAlert($this->lng->txt('crs_timing_err_start_end'));
224 $valid = false;
225 }
226
227 $this->getActivation()->setTimingStart($timing_start ? $timing_start->get(IL_CAL_UNIX) : null);
228 $this->getActivation()->setTimingEnd($timing_end ? $timing_end->get(IL_CAL_UNIX) : null);
229
230 $this->getActivation()->toggleVisible((bool) $form->getInput('visible'));
231 } elseif ($this->getActivation()->getTimingType() != ilObjectActivation::TIMINGS_PRESETTING) {
233 }
234
235 if ($valid) {
236 $this->getActivation()->update($this->getItemId(), $this->getParentId());
237 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
238 $this->ctrl->redirect($this, "edit");
239 } else {
240 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
241 }
242 }
243
244 $form->setValuesByPost();
245 $this->edit($form);
246 }
247
248 protected function __setTabs(): bool
249 {
250 $this->tabs_gui->clearTargets();
251
252 $this->help->setScreenIdComponent("obj");
253
254 $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $this->parent_ref_id);
255 $back_link = $this->ctrl->getLinkTargetByClass("ilrepositorygui", "");
256 $ref_id = $this->request_wrapper->retrieve("ref_id", $this->refinery->kindlyTo()->string());
257 $this->ctrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
258 $this->tabs_gui->setBackTarget($this->lng->txt('btn_back'), $back_link);
259
260 $this->tabs_gui->addTarget(
261 "timings",
262 $this->ctrl->getLinkTarget($this, 'edit'),
263 "edit",
264 get_class($this)
265 );
266
267 $this->ctrl->setParameterByClass('ilconditionhandlergui', 'item_id', $this->item_id);
268 $this->tabs_gui->addTarget(
269 "preconditions",
270 $this->ctrl->getLinkTargetByClass('ilConditionHandlerGUI', 'listConditions'),
271 "",
272 "ilConditionHandlerGUI"
273 );
274 return true;
275 }
276
277 protected function initTimingMode(): void
278 {
279 // Check for parent course and if available read timing mode (abs | rel)
280 $crs_ref_id = $this->tree->checkForParentType($this->parent_ref_id, 'crs');
281 $crs_obj_id = ilObject::_lookupObjId($crs_ref_id);
282
283 if ($crs_obj_id) {
284 $this->timing_mode = ilObjCourse::lookupTimingMode($crs_obj_id);
285 } else {
287 }
288 }
289
290 protected function initItem(): void
291 {
292 $this->activation = new ilObjectActivation();
293 $this->getActivation()->read($this->item_id, $this->getParentId());
294 }
295}
Builds data types.
Definition: Factory.php:21
const IL_CAL_UNIX
error(string $a_errmsg)
This class represents a checkbox property in a property form.
class ilConditionHandlerGUI
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@classDescription Date and time handling
static _after(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
Error Handling & global info handling uses PEAR error class.
Help GUI class.
language handling
static lookupTimingMode(int $a_obj_id)
User class.
Class ilObjectActivationGUI.
edit(ilPropertyFormGUI $form=null)
ilGlobalTemplateInterface $tpl
__construct(int $ref_id, int $item_id)
ILIAS HTTP Wrapper RequestWrapper $request_wrapper
ILIAS Refinery Factory $refinery
Class ilObjectActivation.
read(int $ref_id, int $parent_id=0)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
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...
$valid
global $DIC
Definition: feed.php:28
Interface RequestWrapper.
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...
$ref_id
Definition: ltiauth.php:67