ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSessionMaterialsTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('./Services/Table/classes/class.ilTable2GUI.php');
13{
15 protected $material_items;
16 protected $filter; // [array]
17
21 protected $ui;
22
26 protected $renderer;
27
28 public function __construct($a_parent_obj, $a_parent_cmd)
29 {
30 global $DIC;
31
32 $ilCtrl = $DIC['ilCtrl'];
33 $lng = $DIC['lng'];
34 $tree = $DIC['tree'];
35
36 $this->ui = $DIC->ui()->factory();
37 $this->renderer = $DIC->ui()->renderer();
38
39 $this->setId("sess_materials_" . $a_parent_obj->object->getId());
40
41 parent::__construct($a_parent_obj, $a_parent_cmd);
42
43 $this->parent_ref_id = $tree->getParentId($a_parent_obj->object->getRefId());
44 $this->parent_object_id = $a_parent_obj->object->getId();
45
46 //$this->setEnableNumInfo(false);
47 //$this->setLimit(100);
48 $this->setRowTemplate("tpl.session_materials_row.html", "Modules/Session");
49
50 $this->setFormName('materials');
51 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
52
53 $this->addColumn("", "f", 1);
54 $this->addColumn($lng->txt("crs_materials"), "object", "90%");
55 $this->addColumn($lng->txt("sess_is_assigned"), "active", 5);
56 //todo can I remove this?
57 $this->setSelectAllCheckbox('items');
58
59 $this->setFilterCommand("applyFilter");
60 $this->setResetCommand("resetFilter");
61
62 $this->initFilter();
63 $this->lng->loadLanguageModule('sess');
64 }
65
69 public function getDataFromDb()
70 {
71 global $DIC;
72
73 $tree = $DIC['tree'];
74 $objDefinition = $DIC['objDefinition'];
75
76
77 $nodes = $tree->getSubTree($tree->getNodeData($this->parent_ref_id));
78 $materials = array();
79
80 foreach ($nodes as $node) {
81 // No side blocks here
82 if ($node['child'] == $this->parent_ref_id ||
83 $objDefinition->isSideBlock($node['type']) ||
84 in_array($node['type'], array('sess', 'itgr', 'rolf'))) {
85 continue;
86 }
87
88 if ($node['type'] == 'rolf') {
89 continue;
90 }
91
92 if (!empty($this->getMaterialItems())) {
93 $node["sorthash"] = (int) (!in_array($node['ref_id'], $this->getMaterialItems())) . $node["title"];
94 }
95 $materials[] = $node;
96 }
97
98 $materials = ilUtil::sortArray($materials, "sorthash", "ASC");
99
100 if (!empty($this->filter)) {
101 $materials = $this->filterData($materials);
102 }
103 return $materials;
104 }
105
111 public function filterData($a_data)
112 {
113 $data_filtered = $a_data;
114
115 //Filter by title
116 if ($this->filter["title"]) {
117 foreach ($data_filtered as $key => $material) {
118 $title = $material["title"];
119 if (stripos($title, $this->filter["title"]) === false) {
120 unset($data_filtered[$key]);
121 }
122 }
123 }
124
125 //Filter by obj type
126 if ($this->filter['type']) {
127 foreach ($data_filtered as $key => $material) {
128 $type = $material["type"];
129 //types can be: file, exc
130 if ($type != $this->filter["type"]) {
131 unset($data_filtered[$key]);
132 }
133 }
134 }
135
136 //Filter by status
137 if ($this->filter["status"]) {
138 //items_ref = materials already assigned.
139 $assigned_items = new ilEventItems($this->parent_object_id);
140 $assigned_items = $assigned_items->getItems();
141
142 if ($this->filter["status"] == "assigned") {
143 foreach ($data_filtered as $key => $material) {
144 if (!in_array($material["ref_id"], $assigned_items)) {
145 unset($data_filtered[$key]);
146 }
147 }
148 } elseif ($this->filter["status"] == "notassigned") {
149 foreach ($data_filtered as $key => $material) {
150 if (in_array($material["ref_id"], $assigned_items)) {
151 unset($data_filtered[$key]);
152 }
153 }
154 }
155 }
156
157 return $data_filtered;
158 }
159
160 public function setMaterials($a_materials)
161 {
162 $this->setData($a_materials);
163 }
164
168 protected function fillRow($a_set)
169 {
170 $this->tpl->setVariable('TYPE_IMG', ilObject::_getIcon('', 'tiny', $a_set['type']));
171 $this->tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $a_set['type']));
172
173 $this->tpl->setVariable("VAL_POSTNAME", "items");
174 $this->tpl->setVariable("VAL_ID", $a_set['ref_id']);
175
176 $this->tpl->setVariable("COLL_TITLE", $a_set['title']);
177
178 if (strlen($a_set['description'])) {
179 $this->tpl->setVariable("COLL_DESC", $a_set['description']);
180 }
181 if (in_array($a_set['ref_id'], $this->getMaterialItems())) {
182 $ass_glyph = $this->ui->glyph()->apply();
183 $this->tpl->setVariable("ASSIGNED_IMG_OK", $this->renderer->render($ass_glyph));
184 }
185
186
187 include_once('./Services/Tree/classes/class.ilPathGUI.php');
188 $path = new ilPathGUI();
189 $path->enableDisplayCut(true);
190 $path->enableTextOnly(false);
191 $this->tpl->setVariable("COLL_PATH", $path->getPath($this->getContainerRefId(), $a_set['ref_id']));
192 }
193
198 public function setMaterialItems($a_set)
199 {
200 $this->material_items = $a_set;
201 }
202
207 public function getMaterialItems()
208 {
210 }
211
216 public function setContainerRefId($a_set)
217 {
218 $this->container_ref_id = $a_set;
219 }
220
225 public function getContainerRefId()
226 {
228 }
229
234 public function typesAvailable()
235 {
236 $items = $this->getDataFromDb();
237
238 $all_types = array();
239 foreach ($items as $item) {
240 array_push($all_types, $item["type"]);
241 }
242 return array_values(array_unique($all_types));
243 }
244
248 public function initFilter()
249 {
250 // title
251 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
252 $ti->setMaxLength(64);
253 $ti->setSize(20);
254 $this->addFilterItem($ti);
255 $ti->readFromSession(); // get currenty value from session (always after addFilterItem())
256 $this->filter["title"] = $ti->getValue();
257
258 // types
259 //todo remove banned types if necessary.
260 $filter_types = $this->typesAvailable();
261 $types = array();
262 $types[0] = $this->lng->txt('sess_filter_all_types');
263 foreach ($filter_types as $type) {
264 $types["$type"] = $this->lng->txt("obj_" . $type);
265 }
266
267 $select = new ilSelectInputGUI($this->lng->txt("type"), "type");
268 $select->setOptions($types);
269 $this->addFilterItem($select);
270 $select->readFromSession();
271 $this->filter["type"] = $select->getValue();
272
273 // status
274 $status = array();
275 $status[0] = "-";
276 $status["notassigned"] = $this->lng->txt("sess_filter_not_assigned");
277 $status["assigned"] = $this->lng->txt("assigned");
278
279 $select_status = new ilSelectInputGUI($this->lng->txt("assigned"), "status");
280 $select_status->setOptions($status);
281 $this->addFilterItem($select_status);
282 $select_status->readFromSession();
283 $this->filter['status'] = $select_status->getValue();
284 }
285}
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
class ilEvent
Creates a path for a start and endnode.
This class represents a selection list property in a property form.
setContainerRefId($a_set)
Set Mcontainer ref id.
__construct($a_parent_obj, $a_parent_cmd)
Constructor.
getDataFromDb()
Get data and put it into an array.
fillRow($a_set)
Fill a single data row.
filterData($a_data)
Apply the filters to the data.
typesAvailable()
Get object types available in this specific session.
Class ilTable2GUI.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
setData($a_data)
set table data @access public
setResetCommand($a_val, $a_caption=null)
Set reset filter command.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
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.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setFilterCommand($a_val, $a_caption=null)
Set filter command.
This class represents a text property in a property form.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
$key
Definition: croninfo.php:18
global $ilCtrl
Definition: ilias.php:18
$type
global $DIC
Definition: saml.php:7