ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTimingsPersonalTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 include_once("./Services/Table/classes/class.ilTable2GUI.php");
4 include_once './Modules/Course/classes/class.ilCourseConstants.php';
5 
15 {
16  private $container = null;
17  private $main_container = null;
18  private $user_id = null;
19  private $failure = false;
20 
24  public function __construct($a_parent_class, $a_parent_cmd, ilObject $a_container_obj, ilObjCourse $a_main_container)
25  {
26  $this->container = $a_container_obj;
27  $this->main_container = $a_main_container;
28  $this->setId('personal_timings_' . $this->getContainerObject()->getRefId());
29 
30  parent::__construct($a_parent_class, $a_parent_cmd);
31  }
32 
36  public function getContainerObject()
37  {
38  return $this->container;
39  }
40 
44  public function getMainContainer()
45  {
46  return $this->main_container;
47  }
48 
49  public function setUserId($a_usr_id)
50  {
51  $this->user_id = $a_usr_id;
52  }
53 
57  public function getUserId()
58  {
59  return $this->user_id;
60  }
61 
65  public function init()
66  {
67  $this->setFormAction($GLOBALS['ilCtrl']->getFormAction($this->getParentObject()));
68  $this->setRowTemplate('tpl.crs_personal_timings_row.html', 'Modules/Course');
69 
70  $this->setTitle($this->lng->txt('crs_timings_edit_personal'));
71 
72  $this->addColumn($this->lng->txt('title'), '', '40%');
73  $this->addColumn($this->lng->txt('crs_timings_short_start_end'), '');
74  $this->addColumn($this->lng->txt('crs_timings_short_end'), '');
75  $this->addColumn($this->lng->txt('crs_timings_short_changeable'), '');
76  $this->addCommandButton('updatePersonalTimings', $this->lng->txt('save'));
77  $this->setShowRowsSelector(false);
78  }
79 
84  public function setFailureStatus($a_status)
85  {
86  $this->failure = $a_status;
87  }
88 
93  public function getFailureStatus()
94  {
95  return $this->failure;
96  }
97 
102  public function fillRow($set)
103  {
104  if ($set['error'] == true) {
105  $this->tpl->setVariable('TD_CLASS', 'warning');
106  } else {
107  $this->tpl->setVariable('TD_CLASS', 'std');
108  }
109 
110  // title
111  if (strlen($set['title_link'])) {
112  $this->tpl->setCurrentBlock('title_link');
113  $this->tpl->setVariable('TITLE_LINK', $set['title_link']);
114  $this->tpl->setVariable('TITLE_LINK_NAME', $set['title']);
115  $this->tpl->parseCurrentBlock();
116  } else {
117  $this->tpl->setCurrentBlock('title_plain');
118  $this->tpl->setVariable('TITLE', $set['title']);
119  $this->tpl->parseCurrentBlock();
120  }
121  if (strlen($set['desc'])) {
122  $this->tpl->setCurrentBlock('item_description');
123  $this->tpl->setVariable('DESC', $set['desc']);
124  $this->tpl->parseCurrentBlock();
125  }
126  if ($set['failure']) {
127  $this->tpl->setCurrentBlock('alert');
128  $this->tpl->setVariable('IMG_ALERT', ilUtil::getImagePath("icon_alert.svg"));
129  $this->tpl->setVariable('ALT_ALERT', $this->lng->txt("alert"));
130  $this->tpl->setVariable("TXT_ALERT", $this->lng->txt($set['failure']));
131  $this->tpl->parseCurrentBlock();
132  }
133 
134  // active
135  $this->tpl->setVariable('NAME_ACTIVE', 'item[' . $set['ref_id'] . '][active]');
136  $this->tpl->setVariable('CHECKED_ACTIVE', ($set['item']['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) ? 'checked="checked"' : '');
137 
138  // start
139  include_once './Services/Form/classes/class.ilDateTimeInputGUI.php';
140  $dt_input = new ilDateTimeInputGUI('', 'item[' . $set['ref_id'] . '][sug_start]');
141  $dt_input->setDate(new ilDate($set['item']['suggestion_start'], IL_CAL_UNIX));
142  if ($this->getFailureStatus()) {
143  $dt_input->setDate(new ilDate($_POST['item'][$set['ref_id']]['sug_start'], IL_CAL_DATE));
144  }
145 
146  if (!$set['item']['changeable']) {
147  $dt_input->setDisabled(true);
148  }
149 
150  $this->tpl->setVariable('start_abs');
151  $this->tpl->setVariable('SUG_START', $dt_input->render());
152  $this->tpl->parseCurrentBlock();
153 
154  // end
155  include_once './Services/Form/classes/class.ilDateTimeInputGUI.php';
156  $dt_end = new ilDateTimeInputGUI('', 'item[' . $set['ref_id'] . '][sug_end]');
157  $dt_end->setDate(new ilDate($set['item']['suggestion_end'], IL_CAL_UNIX));
158  if ($this->getFailureStatus()) {
159  $dt_end->setDate(new ilDate($_POST['item'][$set['ref_id']]['sug_end'], IL_CAL_DATE));
160  }
161 
162  if (!$set['item']['changeable']) {
163  $dt_end->setDisabled(true);
164  }
165 
166  $this->tpl->setVariable('end_abs');
167  $this->tpl->setVariable('SUG_END', $dt_end->render());
168  $this->tpl->parseCurrentBlock();
169 
170 
171  // changeable
172  $this->tpl->setVariable('TXT_CHANGEABLE', $set['item']['changeable'] ? $this->lng->txt('yes') : $this->lng->txt('no'));
173  }
174 
175 
179  public function parse($a_item_data, $failed = array())
180  {
181  $rows = array();
182  foreach ($a_item_data as $item) {
183  // hide objects without timings
184  if ($item['timing_type'] != ilObjectActivation::TIMINGS_PRESETTING) {
185  continue;
186  }
187 
188  $current_row = array();
189 
190  // no item groups
191  if ($item['type'] == 'itgr') {
192  continue;
193  }
194  $current_row['ref_id'] = $item['ref_id'];
195 
196  $current_row = $this->parseTitle($current_row, $item);
197 
198  $item = $this->parseUserTimings($item);
199 
200 
201  if (array_key_exists($item['ref_id'], $failed)) {
202  $current_row['failed'] = true;
203  $current_row['failure'] = $failed[$item['ref_id']];
204  }
205  $current_row['item'] = $item;
206  $rows[] = $current_row;
207  }
208  $this->setData($rows);
209  }
210 
214  protected function parseUserTimings($a_item)
215  {
216  include_once './Modules/Course/classes/Timings/class.ilTimingUser.php';
217  $tu = new ilTimingUser($a_item['child'], $this->getUserId());
218 
219  if ($a_item['timing_type'] == ilObjectActivation::TIMINGS_PRESETTING) {
220  if ($tu->getStart()->get(IL_CAL_UNIX)) {
221  $a_item['suggestion_start'] = $tu->getStart()->get(IL_CAL_UNIX);
222  }
223  if ($tu->getEnd()->get(IL_CAL_UNIX)) {
224  $a_item['suggestion_end'] = $tu->getEnd()->get(IL_CAL_UNIX);
225  }
226  }
227  return $a_item;
228  }
229 
230 
231 
232 
236  protected function parseTitle($current_row, $item)
237  {
238  include_once './Services/Link/classes/class.ilLink.php';
239  switch ($item['type']) {
240  case 'fold':
241  case 'grp':
242  $current_row['title'] = $item['title'];
243  $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
244  break;
245 
246  case 'sess':
247  if (strlen($item['title'])) {
248  $current_row['title'] = $item['title'];
249  } else {
250  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
252  $current_row['title'] = ilSessionAppointment::_appointmentToString(
253  $app_info['start'],
254  $app_info['end'],
255  $app_info['fullday']
256  );
257  }
258  $current_row['title_link'] = ilLink::_getLink($item['ref_id'], $item['type']);
259  break;
260 
261  default:
262  $current_row['title'] = $item['title'];
263  $current_row['title_link'] = '';
264  break;
265 
266  }
267  $current_row['desc'] = $item['desc'];
268 
269  return $current_row;
270  }
271 }
failure()
Definition: failure.php:2
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
TableGUI class for timings administration.
const IL_CAL_UNIX
getParentObject()
Get parent object.
setId($a_val)
Set id.
parseTitle($current_row, $item)
Parse title.
This class represents a date/time property in a property form.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
Class ilTable2GUI.
Class ilObjCourse.
Class for single dates.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
parseUserTimings($a_item)
Parse/read individual timings.
static _lookupObjId($a_id)
static _appointmentToString($start, $end, $fulltime)
getFormAction()
Get Form action parameter.
$failed
Definition: Utf8Test.php:85
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$rows
Definition: xhr_table.php:10
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
const IL_CAL_DATE
__construct($a_parent_class, $a_parent_cmd, ilObject $a_container_obj, ilObjCourse $a_main_container)
Constructor.
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
static _lookupAppointment($a_obj_id)
lookup appointment
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
TableGUI class for editing personal timings.
parse($a_item_data, $failed=array())
Parse table content.
$_POST["username"]
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.