ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTimingsManageTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
21use ILIAS\Refinery\Factory as Refinery;
22use ILIAS\HTTP\Services as HTTPServices;
23use ILIAS\UI\Factory as UIFactory;
24use ILIAS\UI\Renderer as UIRenderer;
25
32{
35 private bool $failure = false;
36
37 protected Refinery $refinery;
38 protected HTTPServices $http;
39 protected UIFactory $ui_factory;
40 protected UIRenderer $ui_renderer;
41
42
46 public function __construct(
47 object $a_parent_class,
48 string $a_parent_cmd,
49 ilObject $a_container_obj,
50 ilObjCourse $a_main_container
51 ) {
52 global $DIC;
53
54 $this->http = $DIC->http();
55 $this->refinery = $DIC->refinery();
56 $this->ui_factory = $DIC->ui()->factory();
57 $this->ui_renderer = $DIC->ui()->renderer();
58
59 $this->container = $a_container_obj;
60 $this->main_container = $a_main_container;
61 $this->setId('manage_timings_' . $this->getContainerObject()->getRefId());
62 parent::__construct($a_parent_class, $a_parent_cmd);
63 }
64
65 public function getContainerObject(): ilObject
66 {
67 return $this->container;
68 }
69
70 public function getMainContainer(): ilObjCourse
71 {
73 }
74
78 public function init(): void
79 {
80 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
81 $this->setRowTemplate('tpl.crs_manage_timings_row.html', 'components/ILIAS/Course');
82
83 $this->setTitle($this->lng->txt('edit_timings_list'));
84
85 $this->addColumn($this->lng->txt('title'), '', '40%');
86 $this->addColumn($this->lng->txt('crs_timings_short_active'), '', '', false);
87
89 $this->addColumn($this->lng->txt('crs_timings_short_start_end_rel'), '', '', false);
90 $this->addColumn($this->lng->txt('crs_timings_time_frame'), '', '', false);
91 } else {
92 $this->addColumn($this->lng->txt('crs_timings_short_start_end'), '', '', false);
93 $this->addColumn($this->lng->txt('crs_timings_short_end'), '');
94 }
95 $this->addColumn($this->lng->txt('crs_timings_short_changeable'), '', '', false);
96 $this->addCommandButton('updateManagedTimings', $this->lng->txt('save'));
97 $this->setShowRowsSelector(false);
98 }
99
100 public function setFailureStatus(bool $a_status): void
101 {
102 $this->failure = $a_status;
103 }
104
105 public function getFailureStatus(): bool
106 {
107 return $this->failure;
108 }
109
110 protected function fillRow(array $a_set): void
111 {
112 if ($a_set['error'] ?? false) {
113 $this->tpl->setVariable('TD_CLASS', 'warning');
114 } else {
115 $this->tpl->setVariable('TD_CLASS', 'std');
116 }
117
118 // title
119 if (strlen($a_set['title_link'] ?? '')) {
120 $this->tpl->setCurrentBlock('title_link');
121 $this->tpl->setVariable('TITLE_LINK', $a_set['title_link'] ?? '');
122 $this->tpl->setVariable(
123 'TITLE_LINK_NAME',
124 htmlspecialchars(
125 $a_set['title'] ?? '',
126 ENT_QUOTES | ENT_SUBSTITUTE,
127 'utf-8'
128 )
129 );
130 $this->tpl->parseCurrentBlock();
131 } else {
132 $this->tpl->setCurrentBlock('title_plain');
133 $this->tpl->setVariable(
134 'TITLE',
135 htmlspecialchars(
136 $a_set['title'] ?? '',
137 ENT_QUOTES | ENT_SUBSTITUTE,
138 'utf-8'
139 )
140 );
141 $this->tpl->parseCurrentBlock();
142 }
143 if (strlen($a_set['desc'] ?? '')) {
144 $this->tpl->setCurrentBlock('item_description');
145 $this->tpl->setVariable('DESC', $a_set['desc'] ?? '');
146 $this->tpl->parseCurrentBlock();
147 }
148
149 if ($a_set['failure'] ?? false) {
150 $icon = $this->ui_factory->symbol()->icon()->custom(
151 ilUtil::getImagePath("standard/icon_alert.svg"),
152 $this->lng->txt("alert"),
153 'medium'
154 );
155 $this->tpl->setCurrentBlock('alert');
156 $this->tpl->setVariable('IMG_ALERT', $this->ui_renderer->render($icon));
157 $this->tpl->setVariable("TXT_ALERT", $this->lng->txt($a_set['failure'] ?? ''));
158 $this->tpl->parseCurrentBlock();
159 }
160
161 $error_post_item = (array) ($this->http->request()->getParsedBody()['item'] ?? []);
162
163 // active
164 $this->tpl->setVariable('NAME_ACTIVE', 'item[' . $a_set['ref_id'] . '][active]');
165 if ($this->getFailureStatus()) {
166 $active = (bool) ($error_post_item[$a_set['ref_id']]['active'] ?? false);
167 $this->tpl->setVariable(
168 'CHECKED_ACTIVE',
169 $active ? 'checked="checked"' : ''
170 );
171 } else {
172 $this->tpl->setVariable(
173 'CHECKED_ACTIVE',
174 ($a_set['item']['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) ? 'checked="checked"' : ''
175 );
176 }
177
178 // start
179 if ($this->getMainContainer()->getTimingMode() == ilCourseConstants::IL_CRS_VIEW_TIMING_ABSOLUTE) {
180 $dt_input = new ilDateTimeInputGUI('', 'item[' . $a_set['ref_id'] . '][sug_start]');
181 $dt_input->setDate(new ilDate($a_set['item']['suggestion_start'], IL_CAL_UNIX));
182 if ($this->getFailureStatus()) {
183 $start = (string) ($error_post_item[$a_set['ref_id']]['sug_start'] ?? '');
184 $dt_input->setDate(new ilDate($start, IL_CAL_DATE));
185 }
186
187 $this->tpl->setVariable('start_abs');
188 $this->tpl->setVariable('SUG_START', $dt_input->render());
189 $this->tpl->parseCurrentBlock();
190 } else {
191 $this->tpl->setCurrentBlock('start_rel');
192 $this->tpl->setVariable('START_REL_VAL', (int) $a_set['item']['suggestion_start_rel']);
193 if ($this->getFailureStatus()) {
194 $start = (string) ($error_post_item[$a_set['ref_id']]['sug_start_rel'] ?? '');
195 $this->tpl->setVariable('START_REL_VAL', $start);
196 } else {
197 $this->tpl->setVariable('START_REL_VAL', (int) $a_set['item']['suggestion_start_rel']);
198 }
199 $this->tpl->setVariable('START_REL_NAME', 'item[' . $a_set['ref_id'] . '][sug_start_rel]');
200 $this->tpl->parseCurrentBlock();
201 }
202
203 if ($this->getMainContainer()->getTimingMode() == ilCourseConstants::IL_CRS_VIEW_TIMING_RELATIVE) {
204 if ($this->getFailureStatus()) {
205 $duration = (string) ($error_post_item[$a_set['ref_id']]['duration_a'] ?? '');
206 $this->tpl->setVariable('VAL_DURATION_A', $duration);
207 } else {
208 $duration = $a_set['item']['suggestion_end_rel'] - $a_set['item']['suggestion_start_rel'];
209 $this->tpl->setVariable('VAL_DURATION_A', (int) $duration);
210 }
211 $this->tpl->setVariable('NAME_DURATION_A', 'item[' . $a_set['ref_id'] . '][duration_a]');
212 } else {
213 $dt_end = new ilDateTimeInputGUI('', 'item[' . $a_set['ref_id'] . '][sug_end]');
214 $dt_end->setDate(new ilDate($a_set['item']['suggestion_end'], IL_CAL_UNIX));
215 if ($this->getFailureStatus()) {
216 $end = (string) ($error_post_item[$a_set['ref_id']]['sug_end'] ?? '');
217 $dt_end->setDate(new ilDate($end, IL_CAL_DATE));
218 }
219
220 $this->tpl->setVariable('end_abs');
221 $this->tpl->setVariable('SUG_END', $dt_end->render());
222 $this->tpl->parseCurrentBlock();
223 }
224
225 // changeable
226 $this->tpl->setVariable('NAME_CHANGE', 'item[' . $a_set['ref_id'] . '][change]');
227 $this->tpl->setVariable('CHECKED_CHANGE', $a_set['item']['changeable'] ? 'checked="checked"' : '');
228 if ($this->getFailureStatus()) {
229 $change = (bool) ($error_post_item[$a_set['ref_id']]['change'] ?? false);
230 $this->tpl->setVariable(
231 'CHECKED_CHANGE',
232 $change ? 'checked="checked"' : ''
233 );
234 } else {
235 $this->tpl->setVariable('CHECKED_CHANGE', $a_set['item']['changeable'] ? 'checked="checked"' : '');
236 }
237 }
238
239 public function parse(array $a_item_data, array $a_failed_update = array()): void
240 {
241 $rows = array();
242 foreach ($a_item_data as $item) {
243 $current_row = array();
244
245 // no item groups
246 if ($item['type'] == 'itgr') {
247 continue;
248 }
249 $current_row['ref_id'] = $item['ref_id'];
250 $current_row = $this->parseTitle($current_row, $item);
251
252 // dubios error handling
253 if (array_key_exists($item['ref_id'], $a_failed_update)) {
254 $current_row['failed'] = true;
255 $current_row['failure'] = $a_failed_update[$item['ref_id']];
256 }
257 $current_row['item'] = $item;
258
259 $rows[] = $current_row;
260 }
261 $this->setData($rows);
262 }
263
264 protected function parseTitle(array $current_row, array $item): array
265 {
266 switch ($item['type']) {
267 case 'fold':
268 case 'grp':
269 $current_row['title'] = $item['title'];
270 $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
271 break;
272
273 case 'sess':
274 if (strlen($item['title'])) {
275 $current_row['title'] = $item['title'];
276 } else {
278 $current_row['title'] = ilSessionAppointment::_appointmentToString(
279 $app_info['start'],
280 $app_info['end'],
281 (bool) $app_info['fullday']
282 );
283 }
284 $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
285 break;
286
287 default:
288 $current_row['title'] = $item['title'];
289 $current_row['title_link'] = '';
290 break;
291 }
292 $current_row['desc'] = $item['desc'];
293
294 return $current_row;
295 }
296}
$duration
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
const IL_CAL_DATE
const IL_CAL_UNIX
This class represents a date/time property in a property form.
Class for single dates.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObject Basic functions for all objects.
static _lookupObjId(int $ref_id)
static _lookupAppointment(int $a_obj_id)
static _appointmentToString(int $start, int $end, bool $fulltime)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
TableGUI class for timings administration.
parse(array $a_item_data, array $a_failed_update=array())
__construct(object $a_parent_class, string $a_parent_cmd, ilObject $a_container_obj, ilObjCourse $a_main_container)
Constructor.
parseTitle(array $current_row, array $item)
fillRow(array $a_set)
Standard Version of Fill Row.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
An entity that renders components to a string output.
Definition: Renderer.php:31
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26