ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
class.ilDataCollectionRecordListTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once('./Services/Table/classes/class.ilTable2GUI.php');
6 require_once('class.ilDataCollectionRecordViewGUI.php');
7 require_once('class.ilDataCollectionField.php');
8 require_once('./Services/Tracking/classes/class.ilLPStatus.php');
9 require_once('./Services/Tracking/classes/class.ilLearningProgressBaseGUI.php');
10 require_once('class.ilDataCollectionDatatype.php');
11 require_once('./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php');
12 require_once('./Services/Table/classes/class.ilTablePropertiesStorage.php');
13 
26 
30  protected $table;
34  protected $object_data;
38  protected $numeric_fields = array();
42  protected $filter = array();
46  protected $mode;
47 
48 
56  global $lng, $ilCtrl;
57 
58  $identifier = 'dcl_rl' . $table->getId();
59  $this->setPrefix($identifier);
60  $this->setFormName($identifier);
61  $this->setId($identifier);
62  parent::__construct($a_parent_obj, $a_parent_cmd);
63  $this->table = $table;
64  $this->parent_obj = $a_parent_obj;
65  $this->setRowTemplate("tpl.record_list_row.html", "Modules/DataCollection");
66  $this->mode = $mode;
67 
68  // Setup columns and sorting columns
69  if ($this->mode == ilDataCollectionRecordListGUI::MODE_MANAGE) {
70  // Add checkbox columns
71  $this->addColumn("", "", "1", true);
72  $this->setSelectAllCheckbox("record_ids[]");
73  $this->addMultiCommand("confirmDeleteRecords", $lng->txt('dcl_delete_records'));
74  }
75 
77  $this->addColumn("", "_front", '15px');
78  }
79 
80  $this->numeric_fields = array();
81  foreach ($this->table->getVisibleFields() as $field) {
82  $title = $field->getTitle();
83  $sort_field = $title;
84  if ($field->getId() == 'comments') {
85  $sort_field = 'n_comments';
86  $this->numeric_fields[] = $title;
87  }
88  // switch($field->getDatatypeId()) {
89  // case ilDataCollectionDatatype::INPUTFORMAT_NUMBER:
90  // $this->addColumn($title, $sort_field, '', false, 'text-right');
91  // break;
92  // default:
93  // $this->addColumn($title, $sort_field);
94  // break;
95  // }
96  $this->addColumn($title, $sort_field);
97  if ($field->getLearningProgress()) {
98  $this->addColumn($lng->txt("dcl_status"), "_status_" . $field->getTitle());
99  }
100  if ($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
101  $this->numeric_fields[] = $title;
102  }
103  }
104  $this->addColumn($lng->txt("actions"), "", "30px");
105  $this->setTopCommands(true);
106  $this->setEnableHeader(true);
107  $this->setShowRowsSelector(true);
108  $this->setShowTemplates(true);
109  $this->setEnableHeader(true);
110  $this->setEnableTitle(true);
111  $this->setDefaultOrderDirection($this->table->getDefaultSortFieldOrder());
112  // Set a default sorting?
113  $default_sort_title = 'id';
114  if ($fieldId = $this->table->getDefaultSortField()) {
117  foreach (ilDataCollectionStandardField::_getStandardFields($this->table->getId()) as $stdField) {
118  if ($stdField->getId() == $fieldId) {
119  $default_sort_title = $stdField->getTitle();
120  break;
121  }
122  }
123  } else {
124  $default_sort_title = ilDataCollectionCache::getFieldCache($fieldId)->getTitle();
125  }
126  $this->setDefaultOrderField($default_sort_title);
127  }
128  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, "applyFilter"));
129  $this->initFilter();
130  $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
131  }
132 
133 
139  public function getFilter() {
140  return $this->filter;
141  }
142 
143 
144  public function setRecordData($data) {
145  $this->object_data = $data;
146  $this->buildData($data);
147  }
148 
149 
154  public function fillHeaderExcel($worksheet, &$row) {
155  $this->writeFilterToSession();
156  $this->initFilter();
157  $col = 0;
158 
159  foreach ($this->table->getFields() as $field) {
160  if ($field->getExportable()) {
161  $worksheet->writeString($row, $col, $field->getTitle());
162  $col ++;
163  }
164  }
165  }
166 
167 
168  public function numericOrdering($field) {
169  return in_array($field, $this->numeric_fields);
170  }
171 
172 
176  private function buildData() {
177  global $ilCtrl, $lng;
178 
179  $data = array();
180  foreach ($this->object_data as $record) {
181  $record_data = array();
182  $record_data["_front"] = NULL;
183  $record_data['_record'] = $record;
184 
185  foreach ($this->table->getVisibleFields() as $field) {
186  $title = $field->getTitle();
187  $record_data[$title] = $record->getRecordFieldHTML($field->getId());
188 
189  // Additional column filled in ::fillRow() method, showing the learning progress
190  if ($field->getLearningProgress()) {
191  $record_data["_status_" . $title] = $this->getStatus($record, $field);
192  }
193  if ($field->getId() == 'comments') {
194  $record_data['n_comments'] = count($record->getComments());
195  }
196  }
197 
198  $ilCtrl->setParameterByClass("ildatacollectionfieldeditgui", "record_id", $record->getId());
199  $ilCtrl->setParameterByClass("ildatacollectionrecordviewgui", "record_id", $record->getId());
200  $ilCtrl->setParameterByClass("ildatacollectionrecordeditgui", "record_id", $record->getId());
201  $ilCtrl->setParameterByClass("ildatacollectionrecordeditgui", "mode", $this->mode);
202 
204  $record_data["_front"] = $ilCtrl->getLinkTargetByClass("ildatacollectionrecordviewgui", 'renderRecord');
205  }
206 
207  $alist = new ilAdvancedSelectionListGUI();
208  $alist->setId($record->getId());
209  $alist->setListTitle($lng->txt("actions"));
210 
212  $alist->addItem($lng->txt('view'), 'view', $ilCtrl->getLinkTargetByClass("ildatacollectionrecordviewgui", 'renderRecord'));
213  }
214 
215  if ($record->hasPermissionToEdit($this->parent_obj->parent_obj->ref_id)) {
216  $alist->addItem($lng->txt('edit'), 'edit', $ilCtrl->getLinkTargetByClass("ildatacollectionrecordeditgui", 'edit'));
217  }
218 
219  if ($record->hasPermissionToDelete($this->parent_obj->parent_obj->ref_id)) {
220  $alist->addItem($lng->txt('delete'), 'delete', $ilCtrl->getLinkTargetByClass("ildatacollectionrecordeditgui", 'confirmDelete'));
221  }
222 
223  if ($this->table->getPublicCommentsEnabled()) {
224  $alist->addItem($lng->txt('dcl_comments'), 'comment', '', '', '', '', '', '', $this->getCommentsAjaxLink($record->getId()));
225  }
226 
227  $record_data["_actions"] = $alist->getHTML();
228  $data[] = $record_data;
229  }
230  $this->setData($data);
231  }
232 
233 
239  public function fillRowExcel($worksheet, &$row, $record) {
240  $col = 0;
241  foreach ($this->table->getFields() as $field) {
242  if ($field->getExportable()) {
243  $worksheet->writeString($row, $col, $record["_record"]->getRecordFieldExportValue($field->getId()));
244  $col ++;
245  }
246  }
247  }
248 
249 
255  public function fillRow($record_data) {
256  global $ilUser, $ilAccess;
257  $record_obj = $record_data['_record'];
258 
263  foreach ($this->table->getVisibleFields() as $field) {
264  $title = $field->getTitle();
265  $this->tpl->setCurrentBlock("field");
266  $content = $record_data[$title];
267  if ($content === false OR $content === NULL) {
268  $content = '';
269  } // SW - This ensures to display also zeros in the table...
270 
271  switch ($field->getDatatypeId()) {
273  $this->tpl->setVariable("ADDITIONAL_CLASS", 'text-right');
274  break;
275  }
276 
277  $this->tpl->setVariable("CONTENT", $content);
278  $this->tpl->parseCurrentBlock();
279  if ($field->getLearningProgress()) {
280  $this->tpl->setCurrentBlock("field");
281  $this->tpl->setVariable("CONTENT", $record_data["_status_" . $title]);
282  $this->tpl->parseCurrentBlock();
283  }
284  }
285 
286  if ($record_data["_front"]) {
287  $this->tpl->setCurrentBlock('view');
288  $this->tpl->setVariable("VIEW_IMAGE_LINK", $record_data["_front"]);
289  $this->tpl->setVariable("VIEW_IMAGE_SRC", ilUtil::img(ilUtil::getImagePath("cmd_view_s.png")));
290  $this->tpl->parseCurrentBlock();
291  }
292  $this->tpl->setVariable("ACTIONS", $record_data["_actions"]);
293 
294  if ($this->mode == ilDataCollectionRecordListGUI::MODE_MANAGE) {
295  if ($record_obj->getOwner() == $ilUser->getId() OR $ilAccess->checkAccess('write', '', $_GET['ref_id'])) {
296  $this->tpl->setCurrentBlock('mode_manage');
297  $this->tpl->setVariable('RECORD_ID', $record_obj->getId());
298  $this->tpl->parseCurrentBlock();
299  } else {
300  $this->tpl->touchBlock('mode_manage_no_owner');
301  }
302  }
303 
304  return true;
305  }
306 
307 
316  protected function getStatus(ilDataCollectionRecord $record, ilDataCollectionField $field) {
317  $record_field = ilDataCollectionCache::getRecordFieldCache($record, $field);
318  $return = "";
319  if ($status = $record_field->getStatus()) {
320  $return = "<img src='" . ilLearningProgressBaseGUI::_getImagePathForStatus($status->status) . "'>";
321  }
322 
323  return $return;
324  }
325 
326 
327  public function initFilter() {
328 
329  foreach ($this->table->getFilterableFields() as $field) {
331  $input->readFromSession();
332  $value = $input->getValue();
333  if (is_array($value)) {
334  if ($value['from'] || $value['to']) {
335  $this->filter["filter_" . $field->getId()] = $value;
336  }
337  } else {
338  if ($value != '') {
339  $this->filter["filter_" . $field->getId()] = $value;
340  }
341  }
342  }
343  }
344 
345 
351  public function loadProperty($type) {
352  global $ilUser;
353 
354  if ($ilUser instanceof ilObjUser AND $this->getId()) {
355  $tab_prop = new ilTablePropertiesStorage();
356 
357  return $tab_prop->getProperty($this->getId(), $ilUser->getId(), $type);
358  }
359  }
360 
361 
369  protected function getCommentsAjaxLink($recordId) {
370  $ajax_hash = ilCommonActionDispatcherGUI::buildAjaxHash(1, $_GET['ref_id'], 'dcl', $this->parent_obj->obj_id, 'dcl', $recordId);
371 
372  return ilNoteGUI::getListCommentsJSCall($ajax_hash, '');
373  }
374 }
375 
376 ?>
Class ilDataCollectionField.
setFormName($a_formname)
Set Form name.
__construct($a_parent_obj, $a_parent_cmd="", $a_template_context="")
Constructor.
Class ilDataCollectionRecordListGUI.
getListCommentsJSCall($a_hash, $a_update_code=null)
Get list comments js call.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setStyle($a_element, $a_style)
static hasTableValidViewDefinition(ilDataCollectionTable $table)
$_GET["client_id"]
setShowTemplates($a_value)
Toggle templates.
getStatus(ilDataCollectionRecord $record, ilDataCollectionField $field)
This adds the collumn for status.
static addFilterInputFieldToTable(ilDataCollectionField $field, ilTable2GUI &$table)
addFilterInputFieldToTable This function adds the according filter item to the table gui passed as ar...
_getImagePathForStatus($a_status)
Get image path for status.
Saves (mostly asynchronously) user properties of tables (e.g.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
Class ilDataCollectionRecord.
static getRecordFieldCache($record, $field)
setTopCommands($a_val)
Set top commands (display command buttons on top of table, too)
Class ilTable2GUI.
static buildAjaxHash($a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type=null, $a_sub_id=null)
Build ajax hash.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="")
Add a column to the header.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
getFilter()
Return array of fields that are currently stored in the filter.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setPrefix($a_prefix)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
writeFilterToSession()
Write filter values to session.
Class ilDataCollectionField.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="", $a_class="")
Build img tag.
global $ilUser
Definition: imgupload.php:15
global $lng
Definition: privfeed.php:40
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setEnableHeader($a_enableheader)
Set Enable Header.
fillRow($a_set)
Standard Version of Fill Row.
buildData()
Parse data from record objects to an array that is then set to this table with ::setData() ...
getCommentsAjaxLink($recordId)
Get the ajax link for displaying the comments in the right panel (to be wrapped in an onclick attr) ...
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
getId()
Get element id.
setEnableTitle($a_enabletitle)
Set Enable Title.
getStyle($a_element)