ILIAS  release_8 Revision v8.24
class.ilObjGlossaryAccess.php
Go to the documentation of this file.
1<?php
2
25{
26 protected ilObjUser $user;
27 protected ilLanguage $lng;
30
31 public function __construct()
32 {
33 global $DIC;
34
35 $this->user = $DIC->user();
36 $this->lng = $DIC->language();
37 $this->rbacsystem = $DIC->rbac()->system();
38 $this->access = $DIC->access();
39 }
40
41 public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
42 {
46 $ilAccess = $this->access;
47
48 if (is_null($user_id)) {
49 $user_id = $ilUser->getId();
50 }
51
52 switch ($permission) {
53 case "read":
54 if (!self::_lookupOnline($obj_id)
55 && !$rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id)) {
56 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
57 return false;
58 }
59 break;
60
61 case "visible":
62 if (!self::_lookupOnline($obj_id) &&
63 (!$rbacsystem->checkAccessOfUser($user_id, 'write', $ref_id))) {
64 $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
65 return false;
66 }
67 break;
68 }
69
70
71 return true;
72 }
73
74 public static function _getCommands(): array
75 {
76 $commands = array(
77 array("permission" => "read", "cmd" => "view", "lang_var" => "show",
78 "default" => true),
79 array("permission" => "write", "cmd" => "edit", "lang_var" => "edit_content"),
80 array("permission" => "edit_content", "cmd" => "edit", "lang_var" => "edit_content"), // #11099
81 array("permission" => "write", "cmd" => "properties", "lang_var" => "settings")
82 );
83
84 return $commands;
85 }
86
87 //
88 // access relevant methods
89 //
90
91 public static function _lookupOnline(int $a_id): bool
92 {
93 global $DIC;
94
95 $ilDB = $DIC->database();
96
97 $q = "SELECT * FROM glossary WHERE id = " .
98 $ilDB->quote($a_id, "integer");
99 $lm_set = $ilDB->query($q);
100 if ($lm_rec = $ilDB->fetchAssoc($lm_set)) {
101 return ilUtil::yn2tf($lm_rec["is_online"]);
102 }
103 return false;
104 }
105
106 public static function _lookupOnlineStatus(array $a_ids): array
107 {
108 global $DIC;
109
110 $ilDB = $DIC->database();
111
112 $q = "SELECT id, is_online FROM glossary WHERE " .
113 $ilDB->in("id", $a_ids, false, "integer");
114 $lm_set = $ilDB->query($q);
115 $status = [];
116 while ($r = $ilDB->fetchAssoc($lm_set)) {
117 $status[$r["id"]] = ilUtil::yn2tf($r["is_online"]);
118 }
119
120 return $status;
121 }
122
123
124 public static function _checkGoto(string $target): bool
125 {
126 global $DIC;
127
128 $ilAccess = $DIC->access();
129
130 $t_arr = explode("_", $target);
131
132 if (($t_arr[0] != "glo" && $t_arr[0] != "git") || ((int) $t_arr[1]) <= 0) {
133 return false;
134 }
135
136 if ($t_arr[0] == "glo") {
137 if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
138 $ilAccess->checkAccess("visible", "", $t_arr[1])) {
139 return true;
140 }
141 }
142
143 if ($t_arr[0] == "git") {
144 if ((int) ($t_arr[2] ?? 0) > 0) {
145 $ref_ids = array($t_arr[2]);
146 } else {
147 // determine learning object
148 $glo_id = ilGlossaryTerm::_lookGlossaryID((int) $t_arr[1]);
149 $ref_ids = ilObject::_getAllReferences($glo_id);
150 }
151 // check read permissions
152 foreach ($ref_ids as $ref_id) {
153 // Permission check
154 if ($ilAccess->checkAccess("read", "", $ref_id)) {
155 return true;
156 }
157 }
158 }
159
160 return false;
161 }
162}
static _lookGlossaryID(int $term_id)
get glossary id form term id
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupOnlineStatus(array $a_ids)
static _getCommands()
get commands
static _checkGoto(string $target)
check whether goto script will succeed
_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...
User class.
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 yn2tf(string $a_yn)
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