ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSessionMaterialsTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
32 protected ilCtrl $ctrl;
33 protected ilLanguage $lng;
34 protected ilTree $tree;
36 protected int $container_ref_id = 0;
37 protected array $material_items = [];
38 protected array $filter = [];
39 protected int $parent_ref_id = 0;
40 protected int $parent_object_id = 0;
41
42 public function __construct(object $a_parent_obj, string $a_parent_cmd)
43 {
44 global $DIC;
45
46 $this->ctrl = $DIC->ctrl();
47 $this->lng = $DIC->language();
48 $this->tree = $DIC->repositoryTree();
49 $this->objDefinition = $DIC['objDefinition'];
50 $this->ui = $DIC->ui()->factory();
51 $this->renderer = $DIC->ui()->renderer();
52
53 $this->setId("sess_materials_" . $a_parent_obj->getCurrentObject()->getId());
54
55 parent::__construct($a_parent_obj, $a_parent_cmd);
56
57 $this->parent_ref_id = $this->tree->getParentId($a_parent_obj->getCurrentObject()->getRefId());
58 $this->parent_object_id = $a_parent_obj->getCurrentObject()->getId();
59
60 $this->setRowTemplate("tpl.session_materials_row.html", "components/ILIAS/Session");
61 $this->setFormName('materials');
62 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
63
64 $this->addColumn("", "f", "1");
65 $this->addColumn($this->lng->txt("crs_materials"), "title", "90%");
66 $this->addColumn($this->lng->txt("sess_is_assigned"), "active", "5");
67 $this->setSelectAllCheckbox('items');
68
69 $this->setFilterCommand("applyFilter");
70 $this->setResetCommand("resetFilter");
71 $this->setExternalSorting(true);
72 $this->setExternalSegmentation(true);
73 $this->setDefaultOrderDirection('desc');
74 $this->setDefaultOrderField('active');
75
76 $this->initFilter();
77 $this->determineOffsetAndOrder(true);
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['active'] = 1;
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 $node['active'] = 0;
129 $materials[] = $node;
130 }
131
132 // stable sort by assignment
133 $materials = ilArrayUtil::stableSortArray($materials, 'title', 'asc');
134 $materials = ilArrayUtil::stableSortArray($materials, $this->getOrderField(), $this->getOrderDirection());
135 if (!empty($this->filter)) {
136 $materials = $this->filterData($materials);
137 }
138 return $materials;
139 }
140
141 public function filterData(array $a_data): array
142 {
143 $data_filtered = $a_data;
144
145 //Filter by title
146 if (isset($this->filter["title"]) && $this->filter['title'] !== '') {
147 foreach ($data_filtered as $key => $material) {
148 $title = $material["title"];
149 if (stripos($title, $this->filter["title"]) === false) {
150 unset($data_filtered[$key]);
151 }
152 }
153 }
154
155 //Filter by obj type
156 if (isset($this->filter['type']) && $this->filter['type'] !== '') {
157 foreach ($data_filtered as $key => $material) {
158 $type = $material["type"];
159 //types can be: file, exc
160 if ($type != $this->filter["type"]) {
161 unset($data_filtered[$key]);
162 }
163 }
164 }
165
166 //Filter by status
167 if (isset($this->filter["status"]) && $this->filter['status'] !== '') {
168 //items_ref = materials already assigned.
169 $assigned_items = new ilEventItems($this->parent_object_id);
170 $assigned_items = $assigned_items->getItems();
171
172 if ($this->filter["status"] == "assigned") {
173 foreach ($data_filtered as $key => $material) {
174 if (!in_array($material["ref_id"], $assigned_items)) {
175 unset($data_filtered[$key]);
176 }
177 }
178 } elseif ($this->filter["status"] == "notassigned") {
179 foreach ($data_filtered as $key => $material) {
180 if (in_array($material["ref_id"], $assigned_items)) {
181 unset($data_filtered[$key]);
182 }
183 }
184 }
185 }
186
187 return $data_filtered;
188 }
189
190 public function setMaterials(array $a_materials): void
191 {
192 $this->setData($a_materials);
193 }
194
195 protected function fillRow(array $a_set): void
196 {
197 $this->tpl->setVariable('TYPE_IMG', ilObject::_getIcon(0, 'tiny', $a_set['type']));
198 $this->tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $a_set['type']));
199
200 $this->tpl->setVariable("VAL_POSTNAME", "items");
201 $this->tpl->setVariable("VAL_ID", $a_set['ref_id']);
202
203 $this->tpl->setVariable("COLL_TITLE", $a_set['title']);
204
205 if (strlen((string) $a_set['description'])) {
206 $this->tpl->setVariable("COLL_DESC", (string) $a_set['description']);
207 }
208 if (in_array($a_set['ref_id'], $this->getMaterialItems())) {
209 $ass_glyph = $this->ui->symbol()->icon()->custom(
210 ilUtil::getImagePath("standard/icon_ok.svg"),
211 $this->lng->txt("assigned")
212 );
213 $this->tpl->setVariable("ASSIGNED_IMG_OK", $this->renderer->render($ass_glyph));
214 }
215
216 $path = new ilPathGUI();
217 $path->enableDisplayCut(false);
218 $path->enableTextOnly(false);
219 $path->enableHideLeaf(false);
220 $this->tpl->setVariable("COLL_PATH", $path->getPath($this->getContainerRefId(), (int) $a_set['ref_id']));
221 }
222
226 public function typesAvailable(): array
227 {
228 $items = $this->getDataFromDb();
229
230 $all_types = [];
231 foreach ($items as $item) {
232 $all_types[] = $item["type"];
233 }
234 return array_values(array_unique($all_types));
235 }
236
237 public function initFilter(): void
238 {
239 // title
240 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
241 $ti->setMaxLength(64);
242 $ti->setSize(20);
243 $this->addFilterItem($ti);
244 $ti->readFromSession(); // get currenty value from session (always after addFilterItem())
245 $this->filter["title"] = $ti->getValue();
246
247 // types
248 //todo remove banned types if necessary.
249 $filter_types = $this->typesAvailable();
250 $types = [];
251 $types[0] = $this->lng->txt('sess_filter_all_types');
252 foreach ($filter_types as $type) {
253 $types["$type"] = $this->lng->txt("obj_" . $type);
254 }
255
256 $select = new ilSelectInputGUI($this->lng->txt("type"), "type");
257 $select->setOptions($types);
258 $this->addFilterItem($select);
259 $select->readFromSession();
260 $this->filter["type"] = $select->getValue();
261
262 // status
263 $status = [];
264 $status[0] = "-";
265 $status["notassigned"] = $this->lng->txt("sess_filter_not_assigned");
266 $status["assigned"] = $this->lng->txt("assigned");
267
268 $select_status = new ilSelectInputGUI($this->lng->txt("assigned"), "status");
269 $select_status->setOptions($status);
270 $this->addFilterItem($select_status);
271 $select_status->readFromSession();
272 $this->filter['status'] = $select_status->getValue();
273 }
274}
renderer()
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
Class ilCtrl provides processing control methods.
class ilEventItems
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.
This class represents a selection list property in a property form.
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="")
determineOffsetAndOrder(bool $a_omit_offset=false)
setExternalSegmentation(bool $a_val)
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)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setResetCommand(string $a_val, string $a_caption="")
setData(array $a_data)
Set table data.
This class represents a text property in a property form.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
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 $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26