ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilOrgUnitStaffTableGUI.php
Go to the documentation of this file.
1<?php
18/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
19
26{
27 protected \ilTabsGUI $tabs;
28 protected \ILIAS\HTTP\Services $http;
29 protected \ILIAS\Refinery\Factory $refinery;
30 private bool $recursive = false;
32 private string $staff = "employee";
33
34 public function __construct(
36 string $parent_cmd,
37 string $staff = "employee",
38 bool $recursive = false,
39 string $template_context = ""
40 ) {
41 global $DIC;
42 $this->ctrl = $DIC->ctrl();
43 $this->tabs = $DIC->tabs();
44 $this->lng = $DIC->language();
45 $this->http = $DIC->http();
46 $this->refinery = $DIC->refinery();
47
48 $this->setPrefix("il_orgu_" . $staff);
49 $this->setFormName('il_orgu_' . $staff);
50 $this->setId("il_orgu_" . $staff);
51
52 parent::__construct($parent_obj, $parent_cmd, $template_context);
53
54 $this->setFormAction($this->ctrl->getFormAction($parent_obj));
55 $this->setStaff($staff);
56 $this->recursive = $recursive;
57 $this->setTableHeaders();
58 $this->setTopCommands(true);
59 $this->setEnableHeader(true);
60 $this->setShowRowsSelector(true);
61 $this->setShowTemplates(false);
62 $this->setEnableHeader(true);
63 $this->setDefaultOrderField("role");
64 $this->setEnableTitle(true);
65 $this->setTitle($this->lng->txt("Staff"));
66 $this->setRowTemplate("tpl.staff_row.html", "Modules/OrgUnit");
67 }
68
69 private function setTableHeaders(): void
70 {
71 $this->addColumn($this->lng->txt("firstname"), "first_name");
72 $this->addColumn($this->lng->txt("lastname"), "last_name");
73 if ($this->recursive) {
74 $this->addColumn($this->lng->txt('obj_orgu'), 'org_units');
75 }
76 $this->addColumn($this->lng->txt("action"));
77 }
78
79 public function parseData(): void
80 {
81 if ($this->staff === "employee") {
82 $data = $this->parseRows(ilObjOrgUnitTree::_getInstance()->getEmployees($this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->to()->int()), $this->recursive));
83 } elseif ($this->staff === "superior") {
84 $data = $this->parseRows(ilObjOrgUnitTree::_getInstance()->getSuperiors($this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->to()->int()), $this->recursive));
85 } else {
86 throw new \RuntimeException("The ilOrgUnitStaffTableGUI's staff variable has to be either 'employee' or 'superior'");
87 }
88
89 $this->setData($data);
90 }
91
92 private function parseRows(array $user_ids): array
93 {
94 $data = array();
95 foreach ($user_ids as $user_id) {
96 $data[] = $this->getRowForUser($user_id);
97 }
98
99 return $data;
100 }
101
105 public function setStaff(string $staff): void
106 {
107 $this->staff = $staff;
108 }
109
113 public function getStaff(): string
114 {
115 return $this->staff;
116 }
117
118 protected function getRowForUser(int $user_id): array
119 {
120 $user = new ilObjUser($user_id);
121 $set = [];
122 $set["first_name"] = $user->getFirstname();
123 $set["last_name"] = $user->getLastname();
124 $set["user_object"] = $user;
125 $set["user_id"] = $user_id;
126 if ($this->recursive) {
127 $set["org_units"] = ilObjOrgUnitTree::_getInstance()->getOrgUnitOfUser($user_id);
128 }
129 return $set;
130 }
131
132 public function fillRow(array $a_set): void
133 {
134 global $DIC;
135 $ilUser = $DIC['ilUser'];
136 $ilAccess = $DIC['ilAccess'];
137 $lng = $DIC['lng'];
138 $ilAccess = $DIC['ilAccess'];
139 $this->tpl->setVariable("FIRST_NAME", $a_set["first_name"]);
140 $this->tpl->setVariable("LAST_NAME", $a_set["last_name"]);
141 if ($this->recursive) {
142 $orgUnitsTitles = array_values(ilObjOrgUnitTree::_getInstance()->getTitles($a_set['org_units']));
143 $this->tpl->setVariable("ORG_UNITS", implode(', ', $orgUnitsTitles));
144 }
145 $this->ctrl->setParameterByClass("illearningprogressgui", "obj_id", $a_set["user_id"]);
146 $this->ctrl->setParameterByClass("ilobjorgunitgui", "obj_id", $a_set["user_id"]);
147 $selection = new ilAdvancedSelectionListGUI();
148 $selection->setListTitle($lng->txt("Actions"));
149 $selection->setId("selection_list_user_lp_" . $a_set["user_id"]);
150
151 if ($ilAccess->checkAccess(
152 "view_learning_progress",
153 "",
154 $_GET["ref_id"]
157 ) {
158 $selection->addItem(
159 $lng->txt("show_learning_progress"),
160 "show_learning_progress",
161 $this->ctrl->getLinkTargetByClass(array("ilAdministrationGUI",
162 "ilObjOrgUnitGUI",
163 "ilLearningProgressGUI"
164 ), "")
165 );
166 }
167 if ($ilAccess->checkAccess("write", "", $_GET["ref_id"]) && !$this->recursive) {
168 if ($this->staff === "employee") {
169 $selection->addItem(
170 $this->lng->txt("remove"),
171 "delete_from_employees",
172 $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "confirmRemoveFromEmployees")
173 );
174 $selection->addItem(
175 $this->lng->txt("change_to_superior"),
176 "change_to_superior",
177 $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "fromEmployeeToSuperior")
178 );
179 }
180 if ($this->staff === "superior") {
181 $selection->addItem(
182 $this->lng->txt("remove"),
183 "delete_from_superiors",
184 $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "confirmRemoveFromSuperiors")
185 );
186 $selection->addItem(
187 $this->lng->txt("change_to_employee"),
188 "change_to_employee",
189 $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "fromSuperiorToEmployee")
190 );
191 }
192 }
193 $this->tpl->setVariable("ACTIONS", $selection->getHTML());
194 }
195
199 public function setRecursive(bool $recursive): void
200 {
201 $this->recursive = $recursive;
202 }
203}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
User class.
Class ilObjectGUI Basic methods of all Output classes.
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(ilObjectGUI $parent_obj, string $parent_cmd, string $staff="employee", bool $recursive=false, string $template_context="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableTitle(bool $a_enabletitle)
setFormName(string $a_name="")
setShowTemplates(bool $a_value)
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
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)
setEnableHeader(bool $a_enableheader)
setDefaultOrderField(string $a_defaultorderfield)
setTopCommands(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
ilLanguage $lng
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$_GET['client_id']
Definition: saml1-acs.php:21