ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTimingsPersonalTableGUI.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 int $user_id = 0;
36 private bool $failure = false;
37
38 protected Refinery $refinery;
39 protected HTTPServices $http;
40 protected UIFactory $ui_factory;
41 protected UIRenderer $ui_renderer;
42
43 public function __construct(
44 object $a_parent_class,
45 string $a_parent_cmd,
46 ilObject $a_container_obj,
47 ilObjCourse $a_main_container
48 ) {
49 global $DIC;
50
51 $this->http = $DIC->http();
52 $this->refinery = $DIC->refinery();
53 $this->ui_factory = $DIC->ui()->factory();
54 $this->ui_renderer = $DIC->ui()->renderer();
55
56 $this->container = $a_container_obj;
57 $this->main_container = $a_main_container;
58 $this->setId('personal_timings_' . $this->getContainerObject()->getRefId());
59 parent::__construct($a_parent_class, $a_parent_cmd);
60 }
61
62 public function getContainerObject(): ilObject
63 {
64 return $this->container;
65 }
66
67 public function getMainContainer(): ilObjCourse
68 {
70 }
71
72 public function setUserId(int $a_usr_id): void
73 {
74 $this->user_id = $a_usr_id;
75 }
76
77 public function getUserId(): int
78 {
79 return $this->user_id;
80 }
81
82 public function init(): void
83 {
84 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
85 $this->setRowTemplate('tpl.crs_personal_timings_row.html', 'components/ILIAS/Course');
86 $this->setTitle($this->lng->txt('crs_timings_edit_personal'));
87 $this->addColumn($this->lng->txt('title'), '', '40%');
88 $this->addColumn($this->lng->txt('crs_timings_short_start_end'), '');
89 $this->addColumn($this->lng->txt('crs_timings_short_end'), '');
90 $this->addColumn($this->lng->txt('crs_timings_short_changeable'), '');
91 $this->addCommandButton('updatePersonalTimings', $this->lng->txt('save'));
92 $this->setShowRowsSelector(false);
93 }
94
95 public function setFailureStatus(bool $a_status): void
96 {
97 $this->failure = $a_status;
98 }
99
100 public function getFailureStatus(): bool
101 {
102 return $this->failure;
103 }
104
105 protected function fillRow(array $a_set): void
106 {
107 if ($a_set['error'] ?? false) {
108 $this->tpl->setVariable('TD_CLASS', 'warning');
109 } else {
110 $this->tpl->setVariable('TD_CLASS', 'std');
111 }
112
113 // title
114 if (strlen($a_set['title_link'] ?? '')) {
115 $this->tpl->setCurrentBlock('title_link');
116 $this->tpl->setVariable('TITLE_LINK', $a_set['title_link']);
117 $this->tpl->setVariable('TITLE_LINK_NAME', $a_set['title']);
118 $this->tpl->parseCurrentBlock();
119 } else {
120 $this->tpl->setCurrentBlock('title_plain');
121 $this->tpl->setVariable('TITLE', $a_set['title']);
122 $this->tpl->parseCurrentBlock();
123 }
124 if (strlen($a_set['desc'] ?? '')) {
125 $this->tpl->setCurrentBlock('item_description');
126 $this->tpl->setVariable('DESC', $a_set['desc']);
127 $this->tpl->parseCurrentBlock();
128 }
129 if ($a_set['failure'] ?? false) {
130 $icon = $this->ui_factory->symbol()->icon()->custom(
131 ilUtil::getImagePath("standard/icon_alert.svg"),
132 $this->lng->txt("alert"),
133 'medium'
134 );
135 $this->tpl->setCurrentBlock('alert');
136 $this->tpl->setVariable('IMG_ALERT', $this->ui_renderer->render($icon));
137 $this->tpl->setVariable("TXT_ALERT", $this->lng->txt($a_set['failure']));
138 $this->tpl->parseCurrentBlock();
139 }
140
141 // active
142 $this->tpl->setVariable('NAME_ACTIVE', 'item[' . $a_set['ref_id'] . '][active]');
143 $this->tpl->setVariable(
144 'CHECKED_ACTIVE',
145 ($a_set['item']['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) ? 'checked="checked"' : ''
146 );
147
148 $error_post_item = (array) ($this->http->request()->getParsedBody()['item'] ?? []);
149
150 // start
151 $dt_input = new ilDateTimeInputGUI('', 'item[' . $a_set['ref_id'] . '][sug_start]');
152 $dt_input->setDate(new ilDate($a_set['item']['suggestion_start'], IL_CAL_UNIX));
153 if ($this->getFailureStatus()) {
154 $dt_input->setDate(new ilDate($error_post_item[$a_set['ref_id']]['sug_start'] ?? '', IL_CAL_DATE));
155 }
156
157 if (!($a_set['item']['changeable'] ?? false)) {
158 $dt_input->setDisabled(true);
159 }
160
161 $this->tpl->setVariable('start_abs');
162 $this->tpl->setVariable('SUG_START', $dt_input->render());
163 $this->tpl->parseCurrentBlock();
164
165 // end
166 $dt_end = new ilDateTimeInputGUI('', 'item[' . $a_set['ref_id'] . '][sug_end]');
167 $dt_end->setDate(new ilDate($a_set['item']['suggestion_end'], IL_CAL_UNIX));
168 if ($this->getFailureStatus()) {
169 $dt_end->setDate(new ilDate($error_post_item[$a_set['ref_id']]['sug_end'] ?? '', IL_CAL_DATE));
170 }
171
172 if (!($a_set['item']['changeable'] ?? false)) {
173 $dt_end->setDisabled(true);
174 }
175 $this->tpl->setVariable('end_abs');
176 $this->tpl->setVariable('SUG_END', $dt_end->render());
177 $this->tpl->parseCurrentBlock();
178
179 // changeable
180 $this->tpl->setVariable(
181 'TXT_CHANGEABLE',
182 $a_set['item']['changeable'] ? $this->lng->txt('yes') : $this->lng->txt('no')
183 );
184 }
185
186 public function parse(array $a_item_data, array $failed = array()): void
187 {
188 $rows = array();
189 foreach ($a_item_data as $item) {
190 // hide objects without timings
191 if ($item['timing_type'] != ilObjectActivation::TIMINGS_PRESETTING) {
192 continue;
193 }
194
195 $current_row = array();
196
197 // no item groups
198 if ($item['type'] == 'itgr') {
199 continue;
200 }
201 $current_row['ref_id'] = $item['ref_id'];
202
203 $current_row = $this->parseTitle($current_row, $item);
204
205 $item = $this->parseUserTimings($item);
206 $current_row['start'] = $item['suggestion_start'];
207
208 if (array_key_exists($item['ref_id'], $failed)) {
209 $current_row['failed'] = true;
210 $current_row['failure'] = $failed[$item['ref_id']];
211 }
212 $current_row['item'] = $item;
213 $rows[] = $current_row;
214 }
215 // stable sort first title, second start
216 $rows = ilArrayUtil::sortArray($rows, 'title', 'asc', false);
217 $rows = ilArrayUtil::sortArray($rows, 'start', 'asc', true);
218 $this->setData($rows);
219 }
220
221 protected function parseUserTimings(array $a_item): array
222 {
223 $tu = new ilTimingUser($a_item['child'], $this->getUserId());
224
225 if ($a_item['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
226 if ($tu->getStart()->get(IL_CAL_UNIX)) {
227 $a_item['suggestion_start'] = $tu->getStart()->get(IL_CAL_UNIX);
228 }
229 if ($tu->getEnd()->get(IL_CAL_UNIX)) {
230 $a_item['suggestion_end'] = $tu->getEnd()->get(IL_CAL_UNIX);
231 }
232 }
233 return $a_item;
234 }
235
236 protected function parseTitle(array $current_row, array $item): array
237 {
238 switch ($item['type']) {
239 case 'fold':
240 case 'grp':
241 $current_row['title'] = $item['title'];
242 $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
243 break;
244
245 case 'sess':
246 if (strlen($item['title'])) {
247 $current_row['title'] = $item['title'];
248 } else {
250 $current_row['title'] = ilSessionAppointment::_appointmentToString(
251 $app_info['start'],
252 $app_info['end'],
253 (bool) $app_info['fullday']
254 );
255 }
256 $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
257 break;
258
259 default:
260 $current_row['title'] = $item['title'];
261 $current_row['title_link'] = '';
262 break;
263 }
264 $current_row['desc'] = $item['desc'];
265
266 return $current_row;
267 }
268}
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
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
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.
TableGUI class for editing personal timings.
fillRow(array $a_set)
Standard Version of Fill Row.
parse(array $a_item_data, array $failed=array())
parseTitle(array $current_row, array $item)
__construct(object $a_parent_class, string $a_parent_cmd, ilObject $a_container_obj, ilObjCourse $a_main_container)
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