ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilSessionMaterialsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
30 {
31  protected ILIAS\UI\Factory $ui;
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->setRowTemplate("tpl.session_materials_row.html", "Modules/Session");
62  $this->setFormName('materials');
63  $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
64 
65  $this->addColumn("", "f", "1");
66  $this->addColumn($this->lng->txt("crs_materials"), "title", "90%");
67  $this->addColumn($this->lng->txt("sess_is_assigned"), "active", "5");
68  $this->setSelectAllCheckbox('items');
69 
70  $this->setFilterCommand("applyFilter");
71  $this->setResetCommand("resetFilter");
72  $this->setExternalSorting(true);
73  $this->setExternalSegmentation(true);
74  $this->setDefaultOrderDirection('desc');
75  $this->setDefaultOrderField('active');
76 
77  $this->initFilter();
78  $this->determineOffsetAndOrder(true);
79  $this->lng->loadLanguageModule('sess');
80  }
81 
82  public function setMaterialItems(array $a_set): void
83  {
84  $this->material_items = $a_set;
85  }
86 
87  public function getMaterialItems(): array
88  {
89  return $this->material_items;
90  }
91 
92  public function setContainerRefId(int $a_set): void
93  {
94  $this->container_ref_id = $a_set;
95  }
96 
97  public function getContainerRefId(): int
98  {
100  }
101 
102  public function getDataFromDb(): array
103  {
104  $tree = $this->tree;
105  $objDefinition = $this->objDefinition;
106 
107  $materials = [];
108 
109  $already_assigned_ref_ids = [];
110  foreach ($this->getMaterialItems() as $ref_id) {
111  $already_assigned_ref_ids[] = $ref_id;
112  $node = $tree->getNodeData($ref_id);
113  $node['active'] = 1;
114  $materials[] = $tree->getNodeData($ref_id);
115  }
116 
117  foreach ($tree->getSubTree($tree->getNodeData($this->parent_ref_id)) as $node) {
118  if (in_array($node['ref_id'], $already_assigned_ref_ids)) {
119  continue;
120  }
121 
122  // No side blocks here
123  if ($node['child'] == $this->parent_ref_id ||
124  $objDefinition->isSideBlock($node['type']) ||
125  in_array($node['type'], array('sess', 'itgr', 'rolf'))) {
126  continue;
127  }
128 
129  $node['active'] = 0;
130  $materials[] = $node;
131  }
132 
133  // stable sort by assignment
134  $materials = ilArrayUtil::stableSortArray($materials, 'title', 'asc');
135  $materials = ilArrayUtil::stableSortArray($materials, $this->getOrderField(), $this->getOrderDirection());
136  if (!empty($this->filter)) {
137  $materials = $this->filterData($materials);
138  }
139  return $materials;
140  }
141 
142  public function filterData(array $a_data): array
143  {
144  $data_filtered = $a_data;
145 
146  //Filter by title
147  if (isset($this->filter["title"]) && $this->filter['title'] !== '') {
148  foreach ($data_filtered as $key => $material) {
149  $title = $material["title"];
150  if (stripos($title, $this->filter["title"]) === false) {
151  unset($data_filtered[$key]);
152  }
153  }
154  }
155 
156  //Filter by obj type
157  if (isset($this->filter['type']) && $this->filter['type'] !== '') {
158  foreach ($data_filtered as $key => $material) {
159  $type = $material["type"];
160  //types can be: file, exc
161  if ($type != $this->filter["type"]) {
162  unset($data_filtered[$key]);
163  }
164  }
165  }
166 
167  //Filter by status
168  if (isset($this->filter["status"]) && $this->filter['status'] !== '') {
169  //items_ref = materials already assigned.
170  $assigned_items = new ilEventItems($this->parent_object_id);
171  $assigned_items = $assigned_items->getItems();
172 
173  if ($this->filter["status"] == "assigned") {
174  foreach ($data_filtered as $key => $material) {
175  if (!in_array($material["ref_id"], $assigned_items)) {
176  unset($data_filtered[$key]);
177  }
178  }
179  } elseif ($this->filter["status"] == "notassigned") {
180  foreach ($data_filtered as $key => $material) {
181  if (in_array($material["ref_id"], $assigned_items)) {
182  unset($data_filtered[$key]);
183  }
184  }
185  }
186  }
187 
188  return $data_filtered;
189  }
190 
191  public function setMaterials(array $a_materials): void
192  {
193  $this->setData($a_materials);
194  }
195 
196  protected function fillRow(array $a_set): void
197  {
198  $this->tpl->setVariable('TYPE_IMG', ilObject::_getIcon(0, 'tiny', $a_set['type']));
199  $this->tpl->setVariable('IMG_ALT', $this->lng->txt('obj_' . $a_set['type']));
200 
201  $this->tpl->setVariable("VAL_POSTNAME", "items");
202  $this->tpl->setVariable("VAL_ID", $a_set['ref_id']);
203 
204  $this->tpl->setVariable("COLL_TITLE", $a_set['title']);
205 
206  if (strlen((string) $a_set['description'])) {
207  $this->tpl->setVariable("COLL_DESC", (string) $a_set['description']);
208  }
209  if (in_array($a_set['ref_id'], $this->getMaterialItems())) {
210  $ass_glyph = $this->ui->symbol()->icon()->custom(
211  ilUtil::getImagePath("standard/icon_ok.svg"),
212  $this->lng->txt("assigned")
213  );
214  $this->tpl->setVariable("ASSIGNED_IMG_OK", $this->renderer->render($ass_glyph));
215  }
216 
217  $path = new ilPathGUI();
218  $path->enableDisplayCut(false);
219  $path->enableTextOnly(false);
220  $path->enableHideLeaf(false);
221  $this->tpl->setVariable("COLL_PATH", $path->getPath($this->getContainerRefId(), (int) $a_set['ref_id']));
222  }
223 
227  public function typesAvailable(): array
228  {
229  $items = $this->getDataFromDb();
230 
231  $all_types = [];
232  foreach ($items as $item) {
233  $all_types[] = $item["type"];
234  }
235  return array_values(array_unique($all_types));
236  }
237 
238  public function initFilter(): void
239  {
240  // title
241  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
242  $ti->setMaxLength(64);
243  $ti->setSize(20);
244  $this->addFilterItem($ti);
245  $ti->readFromSession(); // get currenty value from session (always after addFilterItem())
246  $this->filter["title"] = $ti->getValue();
247 
248  // types
249  //todo remove banned types if necessary.
250  $filter_types = $this->typesAvailable();
251  $types = [];
252  $types[0] = $this->lng->txt('sess_filter_all_types');
253  foreach ($filter_types as $type) {
254  $types["$type"] = $this->lng->txt("obj_" . $type);
255  }
256 
257  $select = new ilSelectInputGUI($this->lng->txt("type"), "type");
258  $select->setOptions($types);
259  $this->addFilterItem($select);
260  $select->readFromSession();
261  $this->filter["type"] = $select->getValue();
262 
263  // status
264  $status = [];
265  $status[0] = "-";
266  $status["notassigned"] = $this->lng->txt("sess_filter_not_assigned");
267  $status["assigned"] = $this->lng->txt("assigned");
268 
269  $select_status = new ilSelectInputGUI($this->lng->txt("assigned"), "status");
270  $select_status->setOptions($status);
271  $this->addFilterItem($select_status);
272  $select_status->readFromSession();
273  $this->filter['status'] = $select_status->getValue();
274  }
275 }
__construct(object $a_parent_obj, string $a_parent_cmd)
setData(array $a_data)
Creates a path for a start and endnode.
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
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.
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setResetCommand(string $a_val, string $a_caption="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
setOptions(array $a_options)
setFormName(string $a_name="")
setId(string $a_val)
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
setExternalSorting(bool $a_val)
$ref_id
Definition: ltiauth.php:67
__construct(VocabulariesInterface $vocabularies)
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setFilterCommand(string $a_val, string $a_caption="")
string $key
Consumer key/client ID value.
Definition: System.php:193
setDefaultOrderDirection(string $a_defaultorderdirection)
isSideBlock(string $obj_name)
Check, whether object type is a side block.
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...
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)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
typesAvailable()
Get object types available in this specific session.
determineOffsetAndOrder(bool $a_omit_offset=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setExternalSegmentation(bool $a_val)