ILIAS  release_4-4 Revision
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 
24 {
25 
26  private $table;
27 
31  protected $object_data;
32  protected $numeric_fields;
33 
34  protected $filter = array();
35 
36  /*
37  * __construct
38  */
39  public function __construct(ilDataCollectionRecordListGUI $a_parent_obj, $a_parent_cmd, ilDataCollectionTable $table)
40  {
41  global $lng, $ilCtrl;
42 
43  $this->setPrefix("dcl_record_list");
44  $this->setFormName('record_list');
45  $this->setId("dcl_record_list" . $table->getId());
46  parent::__construct($a_parent_obj, $a_parent_cmd);
47  $this->table = $table;
48  $this->parent_obj = $a_parent_obj;
49  $this->setRowTemplate("tpl.record_list_row.html", "Modules/DataCollection");
50 
51  // Setup columns and sorting columns
52  $this->addColumn("", "_front", "15px");
53  $this->numeric_fields = array();
54  foreach($this->table->getVisibleFields() as $field)
55  {
56  $title = $field->getTitle();
57  $sort_field = $title;
58  $this->addColumn($title, $sort_field);
59  if($field->getLearningProgress()){
60  $this->addColumn($lng->txt("dcl_status"), "_status_".$field->getTitle());
61  }
62  if($field->getDatatypeId() == ilDataCollectionDatatype::INPUTFORMAT_NUMBER) {
63  $this->numeric_fields[] = $title;
64  }
65  }
66  $this->addColumn($lng->txt("actions"), "", "30px");
67 
68  $this->setTopCommands(true);
69  $this->setEnableHeader(true);
70  $this->setShowRowsSelector(true);
71  $this->setShowTemplates(true);
72  $this->setEnableHeader(true);
73  $this->setEnableTitle(true);
74  $this->setDefaultOrderDirection("asc");
75  $this->setDefaultOrderField('id');
76  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, "applyFilter"));
77  $this->initFilter();
78  $this->setStyle('table', $this->getStyle('table') . ' ' . 'dcl_record_list');
79  }
80 
85  public function getFilter() {
86  return $this->filter;
87  }
88 
89  public function setRecordData($data) {
90  $this->object_data = $data;
91  $this->buildData($data);
92  }
93 
94  /*
95  * fillHeaderExcel
96  */
97  public function fillHeaderExcel($worksheet, &$row)
98  {
99  $this->writeFilterToSession();
100  $this->initFilter();
101  $col = 0;
102 
103  foreach($this->table->getFields() as $field)
104  {
105  if($field->getExportable())
106  {
107  $worksheet->writeString($row, $col, $field->getTitle());
108  $col++;
109  }
110  }
111  }
112 
113  public function numericOrdering($field){
114  return in_array($field, $this->numeric_fields);
115  }
116 
120  private function buildData(){
121  global $ilCtrl, $lng;
122 
123  $data = array();
124  foreach($this->object_data as $record){
125  $record_data = array();
126  $record_data["_front"] = null;
127  // The record object is only needed if we are exporting the data, see fillRowExcel() method
128  $record_data['_record'] = ($ilCtrl->getCmd() == 'exportExcel') ? $record : null;
129 
130  foreach($this->table->getVisibleFields() as $field)
131  {
132  $title = $field->getTitle();
133  //Check Options of Displaying
134  $options = array();
135  $arr_properties = $field->getProperties();
137  $options['link']['display'] = true;
138  }
140  $options['link']['display'] = true;
141  }
142  $record_data[$title] = $record->getRecordFieldHTML($field->getId(), $options);
143 
144  // Additional column filled in ::fillRow() method, showing the learning progress
145  if ($field->getLearningProgress()) {
146  $record_data["_status_".$title] = $this->getStatus($record, $field);
147  }
148  }
149 
150  $ilCtrl->setParameterByClass("ildatacollectionfieldeditgui", "record_id", $record->getId());
151  $ilCtrl->setParameterByClass("ildatacollectionrecordviewgui", "record_id", $record->getId());
152  $ilCtrl->setParameterByClass("ildatacollectionrecordeditgui","record_id", $record->getId());
153 
154  include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
155 
157  {
158  $record_data["_front"] = $ilCtrl->getLinkTargetByClass("ildatacollectionrecordviewgui", 'renderRecord');
159  }
160 
161  $alist = new ilAdvancedSelectionListGUI();
162  $alist->setId($record->getId());
163  $alist->setListTitle($lng->txt("actions"));
164 
166  {
167  $alist->addItem($lng->txt('view'), 'view', $ilCtrl->getLinkTargetByClass("ildatacollectionrecordviewgui", 'renderRecord'));
168  }
169 
170  if($record->hasPermissionToEdit($this->parent_obj->parent_obj->ref_id))
171  {
172  $alist->addItem($lng->txt('edit'), 'edit', $ilCtrl->getLinkTargetByClass("ildatacollectionrecordeditgui", 'edit'));
173  }
174 
175  if($record->hasPermissionToDelete($this->parent_obj->parent_obj->ref_id))
176  {
177  $alist->addItem($lng->txt('delete'), 'delete', $ilCtrl->getLinkTargetByClass("ildatacollectionrecordeditgui", 'confirmDelete'));
178  }
179 
180  $record_data["_actions"] = $alist->getHTML();
181  $data[] = $record_data;
182  }
183  $this->setData($data);
184  }
185 
186 
187  /*
188  * fillRowExcel
189  */
190  public function fillRowExcel($worksheet, &$row, $record)
191  {
192  $col = 0;
193  foreach($this->table->getFields() as $field)
194  {
195  if($field->getExportable())
196  {
197  $worksheet->writeString($row, $col, $record["_record"]->getRecordFieldExportValue($field->getId()));
198  $col++;
199  }
200  }
201  }
202 
209  public function fillRow($record_data)
210  {
211  foreach($this->table->getVisibleFields() as $field)
212  {
213  $title = $field->getTitle();
214  $this->tpl->setCurrentBlock("field");
215  $content = $record_data[$title];
216  if ($content === false || $content === null) $content = ''; // SW - This ensures to display also zeros in the table...
217  $this->tpl->setVariable("CONTENT", $content);
218  $this->tpl->parseCurrentBlock();
219  if($field->getLearningProgress()){
220  $this->tpl->setCurrentBlock("field");
221  $this->tpl->setVariable("CONTENT", $record_data["_status_".$title]);
222  $this->tpl->parseCurrentBlock();
223  }
224  }
225 
226  if ($record_data["_front"])
227  {
228  $this->tpl->setVariable("VIEW_IMAGE_LINK", $record_data["_front"]);
229  $this->tpl->setVariable("VIEW_IMAGE_SRC", ilUtil::img(ilUtil::getImagePath("cmd_view_s.png")));
230  }
231  $this->tpl->setVariable("ACTIONS", $record_data["_actions"]);
232 
233  return true;
234  }
235 
241  private function getStatus(ilDataCollectionRecord $record, ilDataCollectionField $field){
242  $record_field = ilDataCollectionCache::getRecordFieldCache($record, $field);
243  $return = "";
244  if($status = $record_field->getStatus()){
245  $return = "<img src='".ilLearningProgressBaseGUI::_getImagePathForStatus($status->status)."'>";
246  }
247  return $return;
248  }
249 
250  /*
251  * initFilter
252  */
253  public function initFilter()
254  {
255  foreach($this->table->getFilterableFields() as $field) {
257  $input->readFromSession();
258  $value = $input->getValue();
259  if (is_array($value)) {
260  if ($value['from'] || $value['to']) {
261  $this->filter["filter_".$field->getId()] = $value;
262  }
263  } else {
264  if ($value != '') {
265  $this->filter["filter_".$field->getId()] = $value;
266  }
267  }
268  }
269  }
270 
271 }
272 
273 ?>
Class ilDataCollectionField.
setFormName($a_formname)
Set Form name.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setStyle($a_element, $a_style)
static img($a_src, $a_alt="", $a_width="", $a_height="", $a_border=0, $a_id="")
Build img tag.
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...
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.
if(!is_array($argv)) $options
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.
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.
global $lng
Definition: privfeed.php:40
__construct(ilDataCollectionRecordListGUI $a_parent_obj, $a_parent_cmd, ilDataCollectionTable $table)
setFormAction($a_form_action)
Set Form action parameter.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setEnableHeader($a_enableheader)
Set Enable Header.
buildData()
Parse data from record objects to an array that is then set to this table with ::setData() ...
setEnableTitle($a_enabletitle)
Set Enable Title.
getStyle($a_element)