ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilOrgUnitExplorerGUI.php
Go to the documentation of this file.
1 <?php
2 
19 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
20 
22 
29 {
30  protected const ORGU = "orgu";
31  protected array $stay_with_command = array('', 'render', 'view', 'infoScreen', 'showStaff', 'performPaste', 'cut');
32  protected ?ilTree $tree = null;
38 
46  public function __construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree, \ilAccessHandler $access = null)
47  {
48  global $DIC;
49  parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree);
50  $this->setAjax(true);
51  $this->setTypeWhiteList(array(self::ORGU));
52  $this->tree->initLangCode();
53  $this->access = $DIC->access();
54  $this->settings = $DIC->settings();
55  $this->http_post = $DIC->http()->wrapper()->post();
56  $this->http_query = $DIC->http()->wrapper()->query();
57  $this->refinery = $DIC["refinery"];
58  }
59 
65  public function getNodeContent($a_node): string
66  {
67  $node = $this->getNodeArrayRepresentation($a_node);
68 
69  if ($node['title'] === '__OrgUnitAdministration') {
70  $node['title'] = $this->lng->txt('objs_orgu');
71  }
72  if ((int) $node['child'] === (int) $_GET['ref_id']) {
73  return "<span class='ilExp2NodeContent ilHighlighted'>" . $node['title'] . '</span>';
74  }
75 
76  return ilUtil::secureString($node['title']);
77  }
78 
79  public function getRootNode(): array
80  {
81  return $this->getTree()->getNodeData(ilObjOrgUnit::getRootOrgRefId());
82  }
83 
90  public function getNodeIcon($a_node): string
91  {
92  $node = $this->getNodeArrayRepresentation($a_node);
93 
94  $obj_id = 0;
95  if ($this->settings->get('custom_icons')) {
96  $icons_cache = ilObjOrgUnit::getIconsCache();
97  $obj_id = ilObject::_lookupObjId($node["child"]);
98  if (isset($icons_cache[$obj_id])) {
99  return $icons_cache[$obj_id];
100  }
101  }
102 
103  return ilObject::_getIcon($obj_id, "tiny", $node["type"]);
104  }
105 
110  public function getNodeHref($a_node): string
111  {
112  $node = $this->getNodeArrayRepresentation($a_node);
113 
114  if ($this->select_postvar) {
115  return '#';
116  }
117 
118  if ($this->ctrl->getCmd() === 'performPaste') {
119  $this->ctrl->setParameterByClass(ilObjOrgUnitGUI::class, 'target_node', $node['child']);
120  }
121  $array = $this->ctrl->getParameterArrayByClass(ilObjOrgUnitGUI::class);
122  $temp = $array['ref_id'];
123 
124  $this->ctrl->setParameterByClass(ilObjOrgUnitGUI::class, 'ref_id', $node['child']);
125  $this->ctrl->setParameterByClass(ilObjPluginDispatchGUI::class, 'ref_id', $node['child']);
126 
127  $link_target = ($node['type'] === self::ORGU) ? $this->getLinkTarget() : $this->getPluginLinkTarget();
128  $this->ctrl->setParameterByClass(ilObjOrgUnitGUI::class, 'ref_id', $temp);
129  return $link_target;
130  }
131 
132  protected function getLinkTarget(): string
133  {
134  if ($this->ctrl->getCmdClass() === strtolower(ilObjOrgUnitGUI::class) && in_array(
135  $this->ctrl->getCmd(),
137  true
138  )) {
139  return $this->ctrl->getLinkTargetByClass(
140  array(ilAdministrationGUI::class, $this->ctrl->getCmdClass()),
141  $this->ctrl->getCmd()
142  );
143  }
144 
145  return $this->ctrl->getLinkTargetByClass(array(ilAdministrationGUI::class, ilObjOrgUnitGUI::class), 'view');
146  }
147 
151  protected function getPluginLinkTarget(): string
152  {
153  return $this->ctrl->getLinkTargetByClass(ilObjPluginDispatchGUI::class, 'forward');
154  }
155 
160  public function isNodeClickable($a_node): bool
161  {
162  $node = $this->getNodeArrayRepresentation($a_node);
163 
164  $node = $this->getNodeArrayRepresentation($a_node);
165 
166  if ($this->access->checkAccess('read', '', $node['ref_id'])) {
167  return true;
168  }
169 
170  return false;
171  }
172 
173 
178  public function isNodeSelectable($a_node): bool
179  {
181  if ($this->http_post->has("id")) {
182  // Node selected via multiselect in "manage".
183  $selected_nodes = $this->http_post->retrieve(
184  "id",
185  $r->kindlyTo()->listOf($r->kindlyTo()->int()),
186  );
187  } elseif ($this->http_query->has("item_ref_id")) {
188  // Node selected via "move"-action.
189  $selected_nodes = $this->http_query->retrieve(
190  "item_ref_id",
191  $r->kindlyTo()->listOf($r->kindlyTo()->int()),
192  );
193  } else {
194  // No node selected.
195  return true;
196  }
197 
198  $node = $this->getNodeArrayRepresentation($a_node);
199  foreach ($selected_nodes as $sn) {
200  // Can't insert into itself.
201  if ($node["child"] == $sn) {
202  return false;
203  }
204  // Can't insert below itself.
205  if ($this->tree->isGrandChild($sn, $node["child"])) {
206  return false;
207  }
208  }
209  return true;
210  }
211 
216  private function getNodeArrayRepresentation($a_node): array
217  {
218  if (is_object($a_node)) {
219  return (array) $a_node;
220  }
221 
222  return $a_node;
223  }
224 
225  public function getChildsOfNode($a_parent_node_id): array
226  {
227  $children = parent::getChildsOfNode($a_parent_node_id);
228  return $this->filterChildrenByPermission($children);
229  }
230 
231  protected function filterChildrenByPermission(array $children): array
232  {
233  return array_filter(
234  $children,
235  function ($child) {
236  return $this->access->checkAccess("visible", "", $child["ref_id"]);
237  }
238  );
239  }
240 }
ILIAS HTTP Wrapper RequestWrapper $http_query
static getIconsCache()
Returns an array that maps from OrgUnit object IDs to its icon defined by the assigned OrgUnit type...
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static secureString(string $a_str, bool $a_strip_html=true, string $a_allow="")
setTypeWhiteList(array $a_val)
Set type white list.
getNodeContent($a_node)
Get content of a node.
getNodeIcon($a_node)
Get node icon.
ILIAS Refinery Factory $refinery
static _lookupObjId(int $ref_id)
__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree, \ilAccessHandler $access=null)
global $DIC
Definition: shib_login.php:25
ILIAS HTTP Wrapper RequestWrapper $http_post
$_GET['cmd']
Definition: lti.php:26
static getRootOrgRefId()
filterChildrenByPermission(array $children)
Explorer class that works on tree objects (Services/Tree)
__construct(Container $dic, ilPlugin $plugin)
Interface for mapping data-structures to the Tree.
$r