ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTimingsPersonalTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 
23 
30 {
33  private int $user_id = 0;
34  private bool $failure = false;
35 
36  protected Refinery $refinery;
37  protected HTTPServices $http;
38 
39  public function __construct(
40  object $a_parent_class,
41  string $a_parent_cmd,
42  ilObject $a_container_obj,
43  ilObjCourse $a_main_container
44  ) {
45  global $DIC;
46 
47  $this->http = $DIC->http();
48  $this->refinery = $DIC->refinery();
49 
50  $this->container = $a_container_obj;
51  $this->main_container = $a_main_container;
52  $this->setId('personal_timings_' . $this->getContainerObject()->getRefId());
53  parent::__construct($a_parent_class, $a_parent_cmd);
54  }
55 
56  public function getContainerObject(): ilObject
57  {
58  return $this->container;
59  }
60 
61  public function getMainContainer(): ilObjCourse
62  {
63  return $this->main_container;
64  }
65 
66  public function setUserId(int $a_usr_id): void
67  {
68  $this->user_id = $a_usr_id;
69  }
70 
71  public function getUserId(): int
72  {
73  return $this->user_id;
74  }
75 
76  public function init(): void
77  {
78  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
79  $this->setRowTemplate('tpl.crs_personal_timings_row.html', 'Modules/Course');
80  $this->setTitle($this->lng->txt('crs_timings_edit_personal'));
81  $this->addColumn($this->lng->txt('title'), '', '40%');
82  $this->addColumn($this->lng->txt('crs_timings_short_start_end'), '');
83  $this->addColumn($this->lng->txt('crs_timings_short_end'), '');
84  $this->addColumn($this->lng->txt('crs_timings_short_changeable'), '');
85  $this->addCommandButton('updatePersonalTimings', $this->lng->txt('save'));
86  $this->setShowRowsSelector(false);
87  }
88 
89  public function setFailureStatus(bool $a_status): void
90  {
91  $this->failure = $a_status;
92  }
93 
94  public function getFailureStatus(): bool
95  {
96  return $this->failure;
97  }
98 
99  protected function fillRow(array $a_set): void
100  {
101  if ($a_set['error'] ?? false) {
102  $this->tpl->setVariable('TD_CLASS', 'warning');
103  } else {
104  $this->tpl->setVariable('TD_CLASS', 'std');
105  }
106 
107  // title
108  if (strlen($a_set['title_link'] ?? '')) {
109  $this->tpl->setCurrentBlock('title_link');
110  $this->tpl->setVariable('TITLE_LINK', $a_set['title_link']);
111  $this->tpl->setVariable('TITLE_LINK_NAME', $a_set['title']);
112  $this->tpl->parseCurrentBlock();
113  } else {
114  $this->tpl->setCurrentBlock('title_plain');
115  $this->tpl->setVariable('TITLE', $a_set['title']);
116  $this->tpl->parseCurrentBlock();
117  }
118  if (strlen($a_set['desc'] ?? '')) {
119  $this->tpl->setCurrentBlock('item_description');
120  $this->tpl->setVariable('DESC', $a_set['desc']);
121  $this->tpl->parseCurrentBlock();
122  }
123  if ($a_set['failure'] ?? false) {
124  $this->tpl->setCurrentBlock('alert');
125  $this->tpl->setVariable('IMG_ALERT', ilUtil::getImagePath("icon_alert.svg"));
126  $this->tpl->setVariable('ALT_ALERT', $this->lng->txt("alert"));
127  $this->tpl->setVariable("TXT_ALERT", $this->lng->txt($a_set['failure']));
128  $this->tpl->parseCurrentBlock();
129  }
130 
131  // active
132  $this->tpl->setVariable('NAME_ACTIVE', 'item[' . $a_set['ref_id'] . '][active]');
133  $this->tpl->setVariable(
134  'CHECKED_ACTIVE',
135  ($a_set['item']['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) ? 'checked="checked"' : ''
136  );
137 
138  $error_post_item = (array) ($this->http->request()->getParsedBody()['item'] ?? []);
139 
140  // start
141  $dt_input = new ilDateTimeInputGUI('', 'item[' . $a_set['ref_id'] . '][sug_start]');
142  $dt_input->setDate(new ilDate($a_set['item']['suggestion_start'], IL_CAL_UNIX));
143  if ($this->getFailureStatus()) {
144  $dt_input->setDate(new ilDate($error_post_item[$a_set['ref_id']]['sug_start'] ?? '', IL_CAL_DATE));
145  }
146 
147  if (!($a_set['item']['changeable'] ?? false)) {
148  $dt_input->setDisabled(true);
149  }
150 
151  $this->tpl->setVariable('start_abs');
152  $this->tpl->setVariable('SUG_START', $dt_input->render());
153  $this->tpl->parseCurrentBlock();
154 
155  // end
156  $dt_end = new ilDateTimeInputGUI('', 'item[' . $a_set['ref_id'] . '][sug_end]');
157  $dt_end->setDate(new ilDate($a_set['item']['suggestion_end'], IL_CAL_UNIX));
158  if ($this->getFailureStatus()) {
159  $dt_end->setDate(new ilDate($error_post_item[$a_set['ref_id']]['sug_end'] ?? '', IL_CAL_DATE));
160  }
161 
162  if (!($a_set['item']['changeable'] ?? false)) {
163  $dt_end->setDisabled(true);
164  }
165  $this->tpl->setVariable('end_abs');
166  $this->tpl->setVariable('SUG_END', $dt_end->render());
167  $this->tpl->parseCurrentBlock();
168 
169  // changeable
170  $this->tpl->setVariable(
171  'TXT_CHANGEABLE',
172  $a_set['item']['changeable'] ? $this->lng->txt('yes') : $this->lng->txt('no')
173  );
174  }
175 
176  public function parse(array $a_item_data, array $failed = array()): void
177  {
178  $rows = array();
179  foreach ($a_item_data as $item) {
180  // hide objects without timings
181  if ($item['timing_type'] != ilObjectActivation::TIMINGS_PRESETTING) {
182  continue;
183  }
184 
185  $current_row = array();
186 
187  // no item groups
188  if ($item['type'] == 'itgr') {
189  continue;
190  }
191  $current_row['ref_id'] = $item['ref_id'];
192 
193  $current_row = $this->parseTitle($current_row, $item);
194 
195  $item = $this->parseUserTimings($item);
196  $current_row['start'] = $item['suggestion_start'];
197 
198  if (array_key_exists($item['ref_id'], $failed)) {
199  $current_row['failed'] = true;
200  $current_row['failure'] = $failed[$item['ref_id']];
201  }
202  $current_row['item'] = $item;
203  $rows[] = $current_row;
204  }
205  // stable sort first title, second start
206  $rows = ilArrayUtil::sortArray($rows, 'title', 'asc', false);
207  $rows = ilArrayUtil::sortArray($rows, 'start', 'asc', true);
208  $this->setData($rows);
209  }
210 
211  protected function parseUserTimings(array $a_item): array
212  {
213  $tu = new ilTimingUser($a_item['child'], $this->getUserId());
214 
215  if ($a_item['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
216  if ($tu->getStart()->get(IL_CAL_UNIX)) {
217  $a_item['suggestion_start'] = $tu->getStart()->get(IL_CAL_UNIX);
218  }
219  if ($tu->getEnd()->get(IL_CAL_UNIX)) {
220  $a_item['suggestion_end'] = $tu->getEnd()->get(IL_CAL_UNIX);
221  }
222  }
223  return $a_item;
224  }
225 
226  protected function parseTitle(array $current_row, array $item): array
227  {
228  switch ($item['type']) {
229  case 'fold':
230  case 'grp':
231  $current_row['title'] = $item['title'];
232  $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
233  break;
234 
235  case 'sess':
236  if (strlen($item['title'])) {
237  $current_row['title'] = $item['title'];
238  } else {
240  $current_row['title'] = ilSessionAppointment::_appointmentToString(
241  $app_info['start'],
242  $app_info['end'],
243  (bool) $app_info['fullday']
244  );
245  }
246  $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
247  break;
248 
249  default:
250  $current_row['title'] = $item['title'];
251  $current_row['title_link'] = '';
252  break;
253 
254  }
255  $current_row['desc'] = $item['desc'];
256 
257  return $current_row;
258  }
259 }
setData(array $a_data)
setFormAction(string $a_form_action, bool $a_multipart=false)
parse(array $a_item_data, array $failed=array())
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
__construct(object $a_parent_class, string $a_parent_cmd, ilObject $a_container_obj, ilObjCourse $a_main_container)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
parseTitle(array $current_row, array $item)
setId(string $a_val)
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...
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
static _lookupAppointment(int $a_obj_id)
static http()
Fetches the global http state from ILIAS.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
$rows
Definition: xhr_table.php:10
const IL_CAL_DATE
static _appointmentToString(int $start, int $end, bool $fulltime)
__construct(Container $dic, ilPlugin $plugin)
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)