ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilOrgUnitRecursiveUserAssignmentTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
30 {
31  private static array $permission_access_staff_recursive = [];
32  private static array $permission_view_lp_recursive = [];
35  protected int $orgu_ref_id;
36 
37  public function __construct(
39  string $parent_cmd,
40  protected ilOrgUnitPosition $position
41  ) {
42  parent::__construct($parent_obj, $parent_cmd);
43 
45 
46  $to_int = $dic['refinery']->kindlyTo()->int();
47  $this->orgu_ref_id = $dic['query']->retrieve('ref_id', $to_int);
48 
49  $this->access = $dic['access'];
50  $this->dropdownbuilder = $dic['dropdownbuilder'];
51 
52  $this->setPrefix("il_orgu_" . $position->getId());
53  $this->setFormName('il_orgu_' . $position->getId());
54  $this->setId("il_orgu_" . $position->getId());
55  $this->setFormAction($this->ctrl->getFormAction($parent_obj));
56  $this->setTableHeaders();
57  $this->setTopCommands(true);
58  $this->setEnableHeader(true);
59  $this->setShowRowsSelector(true);
60  $this->setShowTemplates(false);
61  $this->setEnableHeader(true);
62  $this->setEnableTitle(true);
63  $this->setTitle($position->getTitle());
64  $this->setRowTemplate("tpl.staff_row.html", "Modules/OrgUnit");
65  $this->setData($this->loadData());
66  }
67 
68  protected function setTableHeaders(): void
69  {
70  $this->addColumn($this->lng->txt("login"), "login");
71  $this->addColumn($this->lng->txt("firstname"), "first_name");
72  $this->addColumn($this->lng->txt("lastname"), "last_name");
73  $this->addColumn($this->lng->txt("obj_orgu"), "orgus");
74  $this->addColumn($this->lng->txt("action"));
75  }
76 
77 
78  public function loadData(): array
79  {
80  global $DIC;
81  $access = $DIC['ilAccess'];
82  $orgu_tree = ilObjOrgUnitTree::_getInstance();
83  $data = [];
84  // maybe any parent gives us recursive permission
85  (int) $root = (int) ilObjOrgUnit::getRootOrgRefId();
86  $parent = (int) $orgu_tree->getParent($this->orgu_ref_id);
87 
88  while ($parent !== $root) {
90  array_merge(
91  self::$permission_access_staff_recursive,
92  $orgu_tree->getAllChildren($parent)
93  );
94  }
95  $parent = (int) $orgu_tree->getParent($parent);
96  }
97 
98  foreach ($orgu_tree->getAllChildren($this->orgu_ref_id) as $ref_id) {
99  $recursive = in_array($ref_id, self::$permission_access_staff_recursive);
100  if (!$recursive) {
101  // ok, so no permission from above, lets check local permissions
103  // update recursive permissions
104  array_merge(
105  self::$permission_access_staff_recursive,
106  $orgu_tree->getAllChildren($ref_id)
107  );
109  // skip orgus in which one may not view the staff
110  continue;
111  }
112  }
113  $permission_view_lp = $this->mayViewLPIn($ref_id, $orgu_tree);
114  foreach ($orgu_tree->getAssignedUsers([$ref_id], $this->position->getId()) as $usr_id) {
115  if (!array_key_exists($usr_id, $data)) {
116  $user = new ilObjUser($usr_id);
117  $set = [
118  'login' => $user->getLogin(),
119  'first_name' => $user->getFirstname(),
120  'last_name' => $user->getLastname(),
121  'user_id' => $usr_id,
122  'active' => $user->getActive(),
123  'orgu_assignments' => [],
124  'view_lp' => false
125  ];
126  $data[$usr_id] = $set;
127  } else {
128  $data[$usr_id]["active"] = \ilObjUser::_lookupActive($usr_id);
129  }
130  $data[$usr_id]['orgu_assignments'][] = ilObject::_lookupTitle(ilObject::_lookupObjId($ref_id));
131  $data[$usr_id]['view_lp'] = $permission_view_lp || $data[$usr_id]['view_lp'];
132  }
133  }
134 
135  return $data;
136  }
137 
138  private function mayViewLPIn(int $ref_id, ilObjOrgUnitTree $orgu_tree): bool
139  {
140  if ($this->access->checkAccess("view_learning_progress", "", $ref_id)) { // admission by local
141  return true;
142  }
143  $current = $ref_id;
145  $checked_children = [];
146  while ($current !== $root) {
147  if (!array_key_exists($current, self::$permission_view_lp_recursive)) {
148  self::$permission_view_lp_recursive[$current]
149  = $this->access->checkAccess("view_learning_progress_rec", "", $current);
150  }
151  if (self::$permission_view_lp_recursive[$current]) {
152  // if an orgu may be viewed recursively, same holds for all of its children. lets cache this.
153  foreach ($checked_children as $child) {
154  self::$permission_view_lp_recursive[$child] = true;
155  }
156 
157  return true;
158  }
159  $checked_children[] = $current;
160  $current = (int) $orgu_tree->getParent($current);
161  }
162 
163  return false;
164  }
165 
166  public function fillRow(array $a_set): void
167  {
168  $this->tpl->setVariable("LOGIN", $a_set["login"]);
169  $this->tpl->setVariable("FIRST_NAME", $a_set["first_name"]);
170  $this->tpl->setVariable("LAST_NAME", $a_set["last_name"]);
171  if($a_set["active"] === false) {
172  $this->tpl->setVariable("INACTIVE", $this->lng->txt('usr_account_inactive'));
173  }
174 
175  $orgus = $a_set['orgu_assignments'];
176  sort($orgus);
177  $this->tpl->setVariable("ORG_UNITS", implode(',', $orgus));
178 
179 
180  $this->ctrl->setParameterByClass(ilOrgUnitUserAssignmentGUI::class, 'usr_id', $a_set["user_id"]);
181  $this->ctrl->setParameterByClass(
182  ilOrgUnitUserAssignmentGUI::class,
183  'position_id',
184  $this->position->getId()
185  );
186 
187  $dropdownbuilder = $this->dropdownbuilder
188  ->withItem(
189  'show_learning_progress',
190  $this->ctrl->getLinkTargetByClass([
191  ilAdministrationGUI::class,
192  ilObjOrgUnitGUI::class,
193  ilLearningProgressGUI::class,
194  ], ""),
195  $a_set['view_lp']
198  )
199  ->withItem(
200  'remove',
201  $this->ctrl->getLinkTargetByClass(
202  ilOrgUnitUserAssignmentGUI::class,
204  ),
205  $this->access->checkAccess("write", "", $this->orgu_ref_id)
206  );
207  $this->tpl->setVariable("ACTIONS", $dropdownbuilder->get());
208  }
209 }
setData(array $a_data)
static _checkAccessStaffRec(int $ref_id)
setTopCommands(bool $a_val)
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
setShowTemplates(bool $a_value)
__construct(BaseCommands $parent_obj, string $parent_cmd, protected ilOrgUnitPosition $position)
withItem(string $label_lang_var, string $url, bool $condition=true)
setFormName(string $a_name="")
This is to construct/collect the entries (=Links) of a row&#39;s action-dropdown.
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
__construct(VocabulariesInterface $vocabularies)
static _lookupTitle(int $obj_id)
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()
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)
$dic
Definition: result.php:32
setEnableHeader(bool $a_enableheader)
static _lookupActive(int $a_usr_id)
setPrefix(string $a_prefix)