ILIAS  release_8 Revision v8.24
class.ilSessionMaterialsTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
30{
33 protected ilCtrl $ctrl;
34 protected ilLanguage $lng;
35 protected ilTree $tree;
37 protected int $container_ref_id = 0;
38 protected array $material_items = [];
39 protected array $filter = [];
40 protected int $parent_ref_id = 0;
41 protected int $parent_object_id = 0;
42
43 public function __construct(object $a_parent_obj, string $a_parent_cmd)
44 {
45 global $DIC;
46
47 $this->ctrl = $DIC->ctrl();
48 $this->lng = $DIC->language();
49 $this->tree = $DIC->repositoryTree();
50 $this->objDefinition = $DIC['objDefinition'];
51 $this->ui = $DIC->ui()->factory();
52 $this->renderer = $DIC->ui()->renderer();
53
54 $this->setId("sess_materials_" . $a_parent_obj->getCurrentObject()->getId());
55
56 parent::__construct($a_parent_obj, $a_parent_cmd);
57
58 $this->parent_ref_id = $this->tree->getParentId($a_parent_obj->getCurrentObject()->getRefId());
59 $this->parent_object_id = $a_parent_obj->getCurrentObject()->getId();
60
61 //$this->setEnableNumInfo(false);
62 //$this->setLimit(100);
63 $this->setRowTemplate("tpl.session_materials_row.html", "Modules/Session");
64
65 $this->setFormName('materials');
66 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
67
68 $this->addColumn("", "f", "1");
69 $this->addColumn($this->lng->txt("crs_materials"), "title", "90%");
70 $this->addColumn($this->lng->txt("sess_is_assigned"), "sorthash", "5");
71 //todo can I remove this?
72 $this->setSelectAllCheckbox('items');
73
74 $this->setFilterCommand("applyFilter");
75 $this->setResetCommand("resetFilter");
76
77 $this->initFilter();
78 $this->lng->loadLanguageModule('sess');
79 }
80
81 public function setMaterialItems(array $a_set): void
82 {
83 $this->material_items = $a_set;
84 }
85
86 public function getMaterialItems(): array
87 {
89 }
90
91 public function setContainerRefId(int $a_set): void
92 {
93 $this->container_ref_id = $a_set;
94 }
95
96 public function getContainerRefId(): int
97 {
99 }
100
101 public function getDataFromDb(): array
102 {
105
106 $materials = [];
107
108 $already_assigned_ref_ids = [];
109 foreach ($this->getMaterialItems() as $ref_id) {
110 $already_assigned_ref_ids[] = $ref_id;
111 $node = $tree->getNodeData($ref_id);
112 $node["sorthash"] = '0' . $node["title"];
113 $materials[] = $tree->getNodeData($ref_id);
114 }
115
116 foreach ($tree->getSubTree($tree->getNodeData($this->parent_ref_id)) as $node) {
117 if (in_array($node['ref_id'], $already_assigned_ref_ids)) {
118 continue;
119 }
120
121 // No side blocks here
122 if ($node['child'] == $this->parent_ref_id ||
123 $objDefinition->isSideBlock($node['type']) ||
124 in_array($node['type'], array('sess', 'itgr', 'rolf'))) {
125 continue;
126 }
127
128 if (!empty($already_assigned_ref_ids)) {
129 $node["sorthash"] = '0' . $node["title"];
130 }
131
132 $materials[] = $node;
133 }
134
135 $materials = ilArrayUtil::sortArray($materials, "sorthash", "ASC");
136
137 if (!empty($this->filter)) {
138 $materials = $this->filterData($materials);
139 }
140 return $materials;
141 }
142
143 public function filterData(array $a_data): array
144 {
145 $data_filtered = $a_data;
146
147 //Filter by title
148 if (isset($this->filter["title"]) && $this->filter['title'] !== '') {
149 foreach ($data_filtered as $key => $material) {
150 $title = $material["title"];
151 if (stripos($title, $this->filter["title"]) === false) {
152 unset($data_filtered[$key]);
153 }
154 }
155 }
156
157 //Filter by obj type
158 if (isset($this->filter['type']) && $this->filter['type'] !== '') {
159 foreach ($data_filtered as $key => $material) {
160 $type = $material["type"];
161 //types can be: file, exc
162 if ($type != $this->filter["type"]) {
163 unset($data_filtered[$key]);
164 }
165 }
166 }
167
168 //Filter by status
169 if (isset($this->filter["status"]) && $this->filter['status'] !== '') {
170 //items_ref = materials already assigned.
171 $assigned_items = new ilEventItems($this->parent_object_id);
172 $assigned_items = $assigned_items->getItems();
173
174 if ($this->filter["status"] == "assigned") {
175 foreach ($data_filtered as $key => $material) {
176 if (!in_array($material["ref_id"], $assigned_items)) {
177 unset($data_filtered[$key]);
178 }
179 }
180 } elseif ($this->filter["status"] == "notassigned") {
181 foreach ($data_filtered as $key => $material) {
182 if (in_array($material["ref_id"], $assigned_items)) {
183 unset($data_filtered[$key]);
184 }
185 }
186 }
187 }
188
189 return $data_filtered;
190 }
191
192 public function setMaterials(array $a_materials): void
193 {
194 $this->setData($a_materials);
195 }
196
197 protected function fillRow(array $a_set): void
198 {
199 $this->tpl->setVariable('TYPE_IMG', ilObject::_getIcon(0, 'tiny', $a_set['type']));
200 $this->tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $a_set['type']));
201
202 $this->tpl->setVariable("VAL_POSTNAME", "items");
203 $this->tpl->setVariable("VAL_ID", $a_set['ref_id']);
204
205 $this->tpl->setVariable("COLL_TITLE", $a_set['title']);
206
207 if (strlen((string) $a_set['description'])) {
208 $this->tpl->setVariable("COLL_DESC", (string) $a_set['description']);
209 }
210 if (in_array($a_set['ref_id'], $this->getMaterialItems())) {
211 $ass_glyph = $this->ui->symbol()->icon()->custom(
212 ilUtil::getImagePath("icon_ok.svg"),
213 $this->lng->txt("assigned")
214 );
215 $this->tpl->setVariable("ASSIGNED_IMG_OK", $this->renderer->render($ass_glyph));
216 }
217
218 $path = new ilPathGUI();
219 $path->enableDisplayCut(false);
220 $path->enableTextOnly(false);
221 $path->enableHideLeaf(false);
222 $this->tpl->setVariable("COLL_PATH", $path->getPath($this->getContainerRefId(), (int) $a_set['ref_id']));
223 }
224
228 public function typesAvailable(): array
229 {
230 $items = $this->getDataFromDb();
231
232 $all_types = [];
233 foreach ($items as $item) {
234 $all_types[] = $item["type"];
235 }
236 return array_values(array_unique($all_types));
237 }
238
239 public function initFilter(): void
240 {
241 // title
242 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
243 $ti->setMaxLength(64);
244 $ti->setSize(20);
245 $this->addFilterItem($ti);
246 $ti->readFromSession(); // get currenty value from session (always after addFilterItem())
247 $this->filter["title"] = $ti->getValue();
248
249 // types
250 //todo remove banned types if necessary.
251 $filter_types = $this->typesAvailable();
252 $types = [];
253 $types[0] = $this->lng->txt('sess_filter_all_types');
254 foreach ($filter_types as $type) {
255 $types["$type"] = $this->lng->txt("obj_" . $type);
256 }
257
258 $select = new ilSelectInputGUI($this->lng->txt("type"), "type");
259 $select->setOptions($types);
260 $this->addFilterItem($select);
261 $select->readFromSession();
262 $this->filter["type"] = $select->getValue();
263
264 // status
265 $status = [];
266 $status[0] = "-";
267 $status["notassigned"] = $this->lng->txt("sess_filter_not_assigned");
268 $status["assigned"] = $this->lng->txt("assigned");
269
270 $select_status = new ilSelectInputGUI($this->lng->txt("assigned"), "status");
271 $select_status->setOptions($status);
272 $this->addFilterItem($select_status);
273 $select_status->readFromSession();
274 $this->filter['status'] = $select_status->getValue();
275 }
276}
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
parses the objects.xml it handles the xml-description of all ilias objects
isSideBlock(string $obj_name)
Check, whether object type is a side block.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
Creates a path for a start and endnode.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(object $a_parent_obj, string $a_parent_cmd)
typesAvailable()
Get object types available in this specific session.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFilterCommand(string $a_val, string $a_caption="")
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setFormName(string $a_name="")
setFormAction(string $a_form_action, bool $a_multipart=false)
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)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setResetCommand(string $a_val, string $a_caption="")
setData(array $a_data)
Set table data.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$type