ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilOrgUnitRecursiveUserAssignmentTableGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
5
13{
15 private static $permission_view_lp_recursive = [];
16
24 protected $ctrl;
28 protected $parent_obj;
29
30
38 public function __construct(BaseCommands $parent_obj, string $parent_cmd, ilOrgUnitPosition $position)
39 {
40 global $DIC;
41
42 $this->parent_obj = $parent_obj;
43 $this->ilOrgUnitPosition = $position;
44 $this->ctrl = $DIC->ctrl();
45 $this->setPrefix("il_orgu_" . $position->getId());
46 $this->setFormName('il_orgu_' . $position->getId());
47 $this->setId("il_orgu_" . $position->getId());
48 $this->orgu_ref_id = filter_input(INPUT_GET, "ref_id", FILTER_SANITIZE_NUMBER_INT);
50
51 $this->setFormAction($this->ctrl->getFormAction($parent_obj));
52 $this->setTableHeaders();
53 $this->setTopCommands(true);
54 $this->setEnableHeader(true);
55 $this->setShowRowsSelector(true);
56 $this->setShowTemplates(false);
57 $this->setEnableHeader(true);
58 $this->setEnableTitle(true);
59 $this->setTitle($position->getTitle());
60 $this->setRowTemplate("tpl.staff_row.html", "Modules/OrgUnit");
61 $this->setData($this->loadData());
62 }
63
64
65 protected function setTableHeaders()
66 {
67 $this->addColumn($this->lng->txt("login"), "login");
68 $this->addColumn($this->lng->txt("firstname"), "first_name");
69 $this->addColumn($this->lng->txt("lastname"), "last_name");
70 $this->addColumn($this->lng->txt("obj_orgu"), "orgus");
71 $this->addColumn($this->lng->txt("action"));
72 }
73
77 public function loadData()
78 {
79 global $DIC;
80 $access = $DIC['ilAccess'];
81 $orgu_tree = ilObjOrgUnitTree::_getInstance();
82 $data = [];
83 // maybe any parent gives us recursive permission
84 (int) $root = (int) ilObjOrgUnit::getRootOrgRefId();
85 $parent = (int) $orgu_tree->getParent($this->orgu_ref_id);
86
87 while ($parent !== $root) {
89 self::$permission_access_staff_recursive = array_merge(
90 self::$permission_access_staff_recursive,
91 $orgu_tree->getAllChildren($parent)
92 );
93 }
94 $parent = (int) $orgu_tree->getParent($parent);
95 }
96
97 foreach ($orgu_tree->getAllChildren($this->orgu_ref_id) as $ref_id) {
98 $recursive = in_array($ref_id, self::$permission_access_staff_recursive);
99 if (!$recursive) {
100 // ok, so no permission from above, lets check local permissions
102 // update recursive permissions
103
104 self::$permission_access_staff_recursive = array_merge(
105 self::$permission_access_staff_recursive,
106 $orgu_tree->getAllChildren($ref_id)
107 );
108 } elseif (!ilObjOrgUnitAccess::_checkAccessStaff($ref_id)) {
109 // skip orgus in which one may not view the staff
110 continue;
111 }
112 }
113 $permission_view_lp = $this->mayViewLPIn($ref_id, $access, $orgu_tree);
114 foreach ($orgu_tree->getAssignements($ref_id, $this->ilOrgUnitPosition) as $usr_id) {
115 $usr_id = (int) $usr_id;
116 if (!array_key_exists($usr_id, $data)) {
117 $user = new ilObjUser($usr_id);
118 $set["login"] = $user->getLogin();
119 $set["first_name"] = $user->getFirstname();
120 $set["last_name"] = $user->getLastname();
121 $set["user_id"] = $user_id;
122 $set["orgu_assignments"] = [];
123 $set['view_lp'] = false;
124 $set['user_id'] = $usr_id;
125 $data[$usr_id] = $set;
126 }
127 $data[$usr_id]['orgu_assignments'][] = ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id));
128 $data[$usr_id]['view_lp'] = $permission_view_lp || $data[$usr_id]['view_lp'];
129 }
130 }
131
132 return $data;
133 }
134
135
136
137
141 private function mayViewLPIn($ref_id, ilAccess $access, ilObjOrgUnitTree $orgu_tree)
142 {
143 if ($access->checkAccess("view_learning_progress", "", $ref_id)) { // admission by local
144 return true;
145 }
146 $current = (int) $ref_id;
147 $root = (int) ilObjOrgUnit::getRootOrgRefId();
148 $checked_children = [];
149 while ($current !== $root) {
150 if (!array_key_exists($current, self::$permission_view_lp_recursive)) {
151 self::$permission_view_lp_recursive[$current]
152 = $access->checkAccess("view_learning_progress_rec", "", $current);
153 }
154 if (self::$permission_view_lp_recursive[$current]) {
155 // if an orgu may be viewed recursively, same holds for all of its children. lets cache this.
156 foreach ($checked_children as $child) {
157 self::$permission_view_lp_recursive[$child] = true;
158 }
159
160 return true;
161 }
162 $checked_children[] = $current;
163 $current = (int) $orgu_tree->getParent($current);
164 }
165
166 return false;
167 }
168
169
173 public function fillRow($set)
174 {
175 global $DIC;
176
177 $lng = $DIC['lng'];
178 $ilAccess = $DIC['ilAccess'];
179 $this->tpl->setVariable("LOGIN", $set["login"]);
180 $this->tpl->setVariable("FIRST_NAME", $set["first_name"]);
181 $this->tpl->setVariable("LAST_NAME", $set["last_name"]);
182 $orgus = $set['orgu_assignments'];
183 sort($orgus);
184 $this->tpl->setVariable("ORG_UNITS", implode(',', $orgus));
185 $this->ctrl->setParameterByClass(ilOrgUnitUserAssignmentGUI::class, 'usr_id', $set["user_id"]);
186 $this->ctrl->setParameterByClass(ilOrgUnitUserAssignmentGUI::class, 'position_id', $this->ilOrgUnitPosition->getId());
187 $selection = new ilAdvancedSelectionListGUI();
188 $selection->setListTitle($lng->txt("Actions"));
189 $selection->setId("selection_list_user_lp_" . $set["user_id"]);
190 if ($set['view_lp']
193 ) {
194 $selection->addItem($lng->txt("show_learning_progress"), "show_learning_progress", $this->ctrl->getLinkTargetByClass(array(
195 ilAdministrationGUI::class,
196 ilObjOrgUnitGUI::class,
197 ilLearningProgressGUI::class,
198 ), ""));
199 }
200 if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) {
201 $this->addActions($selection);
202 }
203 $this->tpl->setVariable("ACTIONS", $selection->getHTML());
204 }
205
206
210 protected function addActions(&$selection)
211 {
212 $selection->addItem(
213 $this->lng->txt("remove"),
214 "delete_from_employees",
215 $this->ctrl->getLinkTargetByClass(ilOrgUnitUserAssignmentGUI::class, ilOrgUnitUserAssignmentGUI::CMD_CONFIRM)
216 );
217 }
218}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
checkAccess($a_permission, $a_cmd, $a_ref_id, $a_type="", $a_obj_id="", $a_tree_id="")
check access for an object (provide $a_type and $a_obj_id if available for better performance)
User interface class for advanced drop-down selection lists.
static _checkAccessStaffRec($ref_id)
static _checkAccessStaff($ref_id)
Class ilObjOrgUnitTree Implements a singleton pattern for caching.
static getRootOrgRefId()
static _enabledLearningProgress()
check wether learing progress is enabled or not
static _enabledUserRelatedData()
check wether user related tracking is enabled or not
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
mayViewLPIn($ref_id, ilAccess $access, ilObjOrgUnitTree $orgu_tree)
__construct(BaseCommands $parent_obj, string $parent_cmd, ilOrgUnitPosition $position)
ilOrgUnitUserAssignmentTableGUI constructor.
Class ilTable2GUI.
setTopCommands($a_val)
Set top commands (display command buttons on top of table, too)
setEnableHeader($a_enableheader)
Set Enable Header.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setPrefix($a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
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.
setShowTemplates($a_value)
Toggle templates.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc