ILIAS  release_8 Revision v8.24
class.ilObjWikiAccess.php
Go to the documentation of this file.
1<?php
2
23{
24 protected ilObjUser $user;
25 protected ilLanguage $lng;
28
29 public function __construct()
30 {
31 global $DIC;
32
33 $this->user = $DIC->user();
34 $this->lng = $DIC->language();
35 $this->rbacsystem = $DIC->rbac()->system();
36 $this->access = $DIC->access();
37 }
38
39
40 public static function _getCommands(): array
41 {
42 $commands = array(
43 array("permission" => "read", "cmd" => "view", "lang_var" => "show",
44 "default" => true),
45 array("permission" => "write", "cmd" => "editSettings", "lang_var" => "settings")
46 );
47
48 return $commands;
49 }
50
51 public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
52 {
56 $ilAccess = $this->access;
57
58 if (is_null($user_id)) {
59 $user_id = $ilUser->getId();
60 }
61
62 switch ($cmd) {
63 case "view":
64
65 if (!self::_lookupOnline($obj_id)
66 && !$rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id)) {
67 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
68 return false;
69 }
70 break;
71
72 // for permission query feature
73 case "infoScreen":
74 if (!self::_lookupOnline($obj_id)) {
75 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
76 } else {
77 $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_MESSAGE, $lng->txt("online"));
78 }
79 break;
80
81 }
82 switch ($permission) {
83 case "read":
84 case "visible":
85 if (!self::_lookupOnline($obj_id) &&
86 (!$rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id))) {
87 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
88 return false;
89 }
90
91 $info = ilExcRepoObjAssignment::getInstance()->getAccessInfo($ref_id, $user_id);
92 if (!$info->isGranted()) {
93 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, implode(" / ", $info->getNotGrantedReasons()));
94 return false;
95 }
96 break;
97 }
98
99 return true;
100 }
101
102 public static function _checkGoto(string $target): bool
103 {
104 global $DIC;
105
106 $ilAccess = $DIC->access();
107 // echo "-".$target."-"; exit;
108 $t_arr = explode("_", $target);
109
110 if ($t_arr[0] !== "wiki" || (((int) $t_arr[1]) <= 0) && $t_arr[1] !== "wpage") {
111 return false;
112 }
113
114 if ($t_arr[1] === "wpage") {
115 $wpg_id = (int) $t_arr[2];
116 $w_id = ilWikiPage::lookupWikiId($wpg_id);
117 if ((int) ($t_arr[3] ?? 0) > 0) {
118 $refs = array((int) $t_arr[3]);
119 } else {
120 $refs = ilObject::_getAllReferences($w_id);
121 }
122 foreach ($refs as $r) {
123 if ($ilAccess->checkAccess("read", "", (int) $r) ||
124 $ilAccess->checkAccess("visible", "", (int) $r)) {
125 return true;
126 }
127 }
128 } elseif ($ilAccess->checkAccess("read", "", (int) $t_arr[1]) ||
129 $ilAccess->checkAccess("visible", "", (int) $t_arr[1])) {
130 return true;
131 }
132 return false;
133 }
134
135 public static function _lookupOnline(int $a_id): bool
136 {
137 global $DIC;
138
139 $ilDB = $DIC->database();
140
141 $q = "SELECT * FROM il_wiki_data WHERE id = " .
142 $ilDB->quote($a_id, "integer");
143 $wk_set = $ilDB->query($q);
144 $wk_rec = $ilDB->fetchAssoc($wk_set);
145
146 return (bool) $wk_rec["is_online"];
147 }
148
153 public static function _lookupOnlineStatus(array $a_ids): array
154 {
155 global $DIC;
156
157 $ilDB = $DIC->database();
158
159 $q = "SELECT id, is_online FROM il_wiki_data WHERE " .
160 $ilDB->in("id", $a_ids, false, "integer");
161 $lm_set = $ilDB->query($q);
162 $status = [];
163 while ($r = $ilDB->fetchAssoc($lm_set)) {
164 $status[$r["id"]] = (bool) $r["is_online"];
165 }
166 return $status;
167 }
168
169
173 public static function _lookupPublicFiles(int $a_id): bool
174 {
175 global $DIC;
176
177 $ilDB = $DIC->database();
178
179 $q = "SELECT * FROM il_wiki_data WHERE id = " .
180 $ilDB->quote($a_id, "integer");
181 $wk_set = $ilDB->query($q);
182 $wk_rec = $ilDB->fetchAssoc($wk_set);
183
184 return (bool) $wk_rec["public_files"];
185 }
186}
language handling
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupOnlineStatus(array $a_ids)
see legacyOnlineFilter in ilContainer
ilAccessHandler $access
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
Checks whether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcc...
static _lookupPublicFiles(int $a_id)
Check wether files should be public.
static _lookupOnline(int $a_id)
static _getCommands()
get commands
static _checkGoto(string $target)
check whether goto script will succeed
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getAllReferences(int $id)
get all reference ids for object ID
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
checkAccessOfUser(int $a_user_id, string $a_operations, int $a_ref_id, string $a_type="")
static lookupWikiId(int $a_page_id)
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
$lm_set