ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilOrgUnitRecursiveUserAssignmentTableGUI.php
Go to the documentation of this file.
1 <?php
18 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
19 
21 
28 {
29  private static array $permission_access_staff_recursive = [];
30  private static array $permission_view_lp_recursive = [];
32 
34  {
35  global $DIC;
36 
37  $this->parent_obj = $parent_obj;
38  $this->ilOrgUnitPosition = $position;
39  $this->ctrl = $DIC->ctrl();
40  $this->setPrefix("il_orgu_" . $position->getId());
41  $this->setFormName('il_orgu_' . $position->getId());
42  $this->setId("il_orgu_" . $position->getId());
43  $this->orgu_ref_id = filter_input(INPUT_GET, "ref_id", FILTER_SANITIZE_NUMBER_INT);
44  parent::__construct($parent_obj, $parent_cmd);
45 
46  $this->setFormAction($this->ctrl->getFormAction($parent_obj));
47  $this->setTableHeaders();
48  $this->setTopCommands(true);
49  $this->setEnableHeader(true);
50  $this->setShowRowsSelector(true);
51  $this->setShowTemplates(false);
52  $this->setEnableHeader(true);
53  $this->setEnableTitle(true);
54  $this->setTitle($position->getTitle());
55  $this->setRowTemplate("tpl.staff_row.html", "Modules/OrgUnit");
56  $this->setData($this->loadData());
57  }
58 
59  protected function setTableHeaders(): void
60  {
61  $this->addColumn($this->lng->txt("login"), "login");
62  $this->addColumn($this->lng->txt("firstname"), "first_name");
63  $this->addColumn($this->lng->txt("lastname"), "last_name");
64  $this->addColumn($this->lng->txt("obj_orgu"), "orgus");
65  $this->addColumn($this->lng->txt("action"));
66  }
67 
68 
69  public function loadData(): array
70  {
71  global $DIC;
72  $access = $DIC['ilAccess'];
73  $orgu_tree = ilObjOrgUnitTree::_getInstance();
74  $data = [];
75  // maybe any parent gives us recursive permission
76  (int) $root = (int) ilObjOrgUnit::getRootOrgRefId();
77  $parent = (int) $orgu_tree->getParent($this->orgu_ref_id);
78 
79  while ($parent !== $root) {
81  array_merge(
82  self::$permission_access_staff_recursive,
83  $orgu_tree->getAllChildren($parent)
84  );
85  }
86  $parent = (int) $orgu_tree->getParent($parent);
87  }
88 
89  foreach ($orgu_tree->getAllChildren($this->orgu_ref_id) as $ref_id) {
90  $recursive = in_array($ref_id, self::$permission_access_staff_recursive);
91  if (!$recursive) {
92  // ok, so no permission from above, lets check local permissions
94  // update recursive permissions
95  array_merge(
96  self::$permission_access_staff_recursive,
97  $orgu_tree->getAllChildren($ref_id)
98  );
100  // skip orgus in which one may not view the staff
101  continue;
102  }
103  }
104  $permission_view_lp = $this->mayViewLPIn($ref_id, $access, $orgu_tree);
105  foreach ($orgu_tree->getAssignements($ref_id, $this->ilOrgUnitPosition) as $usr_id) {
106  $usr_id = (int) $usr_id;
107  if (!array_key_exists($usr_id, $data)) {
108  $user = new ilObjUser($usr_id);
109  $set = [
110  'login' => $user->getLogin(),
111  'first_name' => $user->getFirstname(),
112  'last_name' => $user->getLastname(),
113  'user_id' => $usr_id,
114  'active' => $user->getActive(),
115  'orgu_assignments' => [],
116  'view_lp' => false
117  ];
118  $data[$usr_id] = $set;
119  } else {
120  $data[$usr_id]["active"] = \ilObjUser::_lookupActive($usr_id);
121  }
122  $data[$usr_id]['orgu_assignments'][] = ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id));
123  $data[$usr_id]['view_lp'] = $permission_view_lp || $data[$usr_id]['view_lp'];
124  }
125  }
126 
127  return $data;
128  }
129 
130  private function mayViewLPIn(int $ref_id, ilAccess $access, ilObjOrgUnitTree $orgu_tree): bool
131  {
132  if ($access->checkAccess("view_learning_progress", "", $ref_id)) { // admission by local
133  return true;
134  }
135  $current = $ref_id;
137  $checked_children = [];
138  while ($current !== $root) {
139  if (!array_key_exists($current, self::$permission_view_lp_recursive)) {
140  self::$permission_view_lp_recursive[$current]
141  = $access->checkAccess("view_learning_progress_rec", "", $current);
142  }
143  if (self::$permission_view_lp_recursive[$current]) {
144  // if an orgu may be viewed recursively, same holds for all of its children. lets cache this.
145  foreach ($checked_children as $child) {
146  self::$permission_view_lp_recursive[$child] = true;
147  }
148 
149  return true;
150  }
151  $checked_children[] = $current;
152  $current = (int) $orgu_tree->getParent($current);
153  }
154 
155  return false;
156  }
157 
158  public function fillRow(array $a_set): void
159  {
160  global $DIC;
161 
162  $lng = $DIC['lng'];
163  $ilAccess = $DIC['ilAccess'];
164  $this->tpl->setVariable("LOGIN", $a_set["login"]);
165  $this->tpl->setVariable("FIRST_NAME", $a_set["first_name"]);
166  $this->tpl->setVariable("LAST_NAME", $a_set["last_name"]);
167  if($a_set["active"] === false) {
168  $this->tpl->setVariable("INACTIVE", $this->lng->txt('usr_account_inactive'));
169  }
170 
171  $orgus = $a_set['orgu_assignments'];
172  sort($orgus);
173  $this->tpl->setVariable("ORG_UNITS", implode(',', $orgus));
174  $this->ctrl->setParameterByClass(ilOrgUnitUserAssignmentGUI::class, 'usr_id', $a_set["user_id"]);
175  $this->ctrl->setParameterByClass(
176  ilOrgUnitUserAssignmentGUI::class,
177  'position_id',
178  $this->ilOrgUnitPosition->getId()
179  );
180  $selection = new ilAdvancedSelectionListGUI();
181  $selection->setListTitle($lng->txt("Actions"));
182  $selection->setId("selection_list_user_lp_" . $a_set["user_id"]);
183  if ($a_set['view_lp']
186  ) {
187  $selection->addItem(
188  $lng->txt("show_learning_progress"),
189  "show_learning_progress",
190  $this->ctrl->getLinkTargetByClass(array(
191  ilAdministrationGUI::class,
192  ilObjOrgUnitGUI::class,
193  ilLearningProgressGUI::class,
194  ), "")
195  );
196  }
197  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) {
198  $this->addActions($selection);
199  }
200  $this->tpl->setVariable("ACTIONS", $selection->getHTML());
201  }
202 
203  protected function addActions(ilAdvancedSelectionListGUI $selection): void
204  {
205  $selection->addItem($this->lng->txt("remove"), "delete_from_employees", $this->ctrl->getLinkTargetByClass(ilOrgUnitUserAssignmentGUI::class, ilOrgUnitUserAssignmentGUI::CMD_CONFIRM_RECURSIVE));
206  }
207 }
setData(array $a_data)
static _checkAccessStaffRec(int $ref_id)
setTopCommands(bool $a_val)
mayViewLPIn(int $ref_id, ilAccess $access, ilObjOrgUnitTree $orgu_tree)
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...
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
setShowTemplates(bool $a_value)
__construct(BaseCommands $parent_obj, string $parent_cmd, ilOrgUnitPosition $position)
setFormName(string $a_name="")
addItem(string $a_title, string $a_value="", string $a_link="", string $a_img="", string $a_alt="", string $a_frame="", string $a_html="", bool $a_prevent_background_click=false, string $a_onclick="", string $a_ttip="", string $a_tt_my="right center", string $a_tt_at="left center", bool $a_tt_use_htmlspecialchars=true, array $a_data=array())
ilLanguage $lng
setId(string $a_val)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
$ref_id
Definition: ltiauth.php:67
static _lookupTitle(int $obj_id)
$_GET['client_id']
Definition: saml1-acs.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
static _checkAccessStaff(int $ref_id)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
static getRootOrgRefId()
__construct(Container $dic, ilPlugin $plugin)
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)
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance) ...
setEnableHeader(bool $a_enableheader)
static _lookupActive(int $a_usr_id)
setPrefix(string $a_prefix)