ILIAS  release_7 Revision v7.30-3-g800a261c036
ilBadgeWAC Class Reference
+ Inheritance diagram for ilBadgeWAC:
+ Collaboration diagram for ilBadgeWAC:

Public Member Functions

 canBeDelivered (ilWACPath $ilWACPath)
 
 canBeDelivered (ilWACPath $ilWACPath)
 

Private Member Functions

 hasAccessToBadgeParentIdNode (\ILIAS\DI\Container $DIC, int $badge_id, bool $has_global_badge_administration_access)
 
 isAssignedBadge (\ILIAS\DI\Container $DIC, int $badge_id)
 
 isAssignedBadgeOfPublishedUserProfile (\ILIAS\DI\Container $DIC, int $badge_id)
 

Detailed Description

Definition at line 14 of file class.ilBadgeWAC.php.

Member Function Documentation

◆ canBeDelivered()

ilBadgeWAC::canBeDelivered ( ilWACPath  $ilWACPath)
Parameters
ilWACPath$ilWACPath
Returns
bool

Implements ilWACCheckingClass.

Definition at line 16 of file class.ilBadgeWAC.php.

17 {
18 global $DIC;
19
20 if (strpos($ilWACPath->getPath(), '..') !== false) {
21 return false;
22 }
23
24 if (!preg_match('@ilBadge\/(\d+\/)*?badge(tmpl)?_(\d+)\/@ui', $ilWACPath->getPath())) {
25 return false;
26 }
27
28 $obj_id = array_keys(ilObject::_getObjectsByType('bdga'))[0] ?? null;
29 $admin_ref_id = null;
30 if ($obj_id > 0) {
31 $admin_ref_id = array_values(ilObject::_getAllReferences($obj_id))[0] ?? null;
32 }
33
34 $has_global_badge_administration_access = (
35 $admin_ref_id > 0 &&
36 $DIC->rbac()->system()->checkAccessOfUser($DIC->user()->getId(), 'read', $admin_ref_id)
37 );
38
39 if (preg_match('@\/badgetmpl_(\d+)\/@ui', $ilWACPath->getPath())) {
40 // Badge template images must only be accessible for accounts with `read` permission on the badge administration node
41 return $has_global_badge_administration_access;
42 }
43
44 if (preg_match('@\/badge_(\d+)\/@ui', $ilWACPath->getPath(), $matches)) {
45 if ($has_global_badge_administration_access) {
46 return true;
47 }
48
49 $badge_id = (int) $matches[1];
50
51 return (
52 $this->isAssignedBadge($DIC, $badge_id) ||
53 $this->isAssignedBadgeOfPublishedUserProfile($DIC, $badge_id) ||
54 $this->hasAccessToBadgeParentIdNode($DIC, $badge_id, $has_global_badge_administration_access)
55 );
56 }
57
58 return false;
59 }
isAssignedBadgeOfPublishedUserProfile(\ILIAS\DI\Container $DIC, int $badge_id)
hasAccessToBadgeParentIdNode(\ILIAS\DI\Container $DIC, int $badge_id, bool $has_global_badge_administration_access)
isAssignedBadge(\ILIAS\DI\Container $DIC, int $badge_id)
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _getAllReferences($a_id)
get all reference ids of object
global $DIC
Definition: goto.php:24

References $DIC, ilObject\_getAllReferences(), ilObject\_getObjectsByType(), ilWACPath\getPath(), hasAccessToBadgeParentIdNode(), isAssignedBadge(), and isAssignedBadgeOfPublishedUserProfile().

+ Here is the call graph for this function:

◆ hasAccessToBadgeParentIdNode()

ilBadgeWAC::hasAccessToBadgeParentIdNode ( \ILIAS\DI\Container  $DIC,
int  $badge_id,
bool  $has_global_badge_administration_access 
)
private

Definition at line 61 of file class.ilBadgeWAC.php.

65 : bool {
66 // If the acting user still does not have access, check if the image is used in an object badge type
67 $badge = new ilBadge($badge_id);
68 if ($badge->getParentId() > 0) {
69 return false;
70 }
71
72 $badge_handler = ilBadgeHandler::getInstance();
73 if (!$badge_handler->isObjectActive((int) $badge->getParentId())) {
74 return false;
75 }
76
77 $context_ref_id = array_values(ilObject::_getAllReferences((int) $badge->getParentId()))[0] ?? null;
78 if (!($context_ref_id > 0)) {
79 return false;
80 }
81
82 $context_ref_id = (int) $context_ref_id;
83 if ($DIC->repositoryTree()->isGrandChild((int) SYSTEM_FOLDER_ID, $context_ref_id)) {
84 $has_access = $has_global_badge_administration_access;
85 } else {
86 $has_access = $DIC->access()->checkAccessOfUser(
87 $DIC->user()->getId(),
88 'write',
89 '',
90 $context_ref_id
91 );
92 }
93
94 return $has_access;
95 }
static getInstance()
Constructor.
Class ilBadge.
const SYSTEM_FOLDER_ID
Definition: constants.php:33

Referenced by canBeDelivered().

+ Here is the caller graph for this function:

◆ isAssignedBadge()

ilBadgeWAC::isAssignedBadge ( \ILIAS\DI\Container  $DIC,
int  $badge_id 
)
private

Definition at line 97 of file class.ilBadgeWAC.php.

97 : bool
98 {
99 // First, check all badge assignments of the current user for a match
100 $badges_of_user = ilBadgeAssignment::getInstancesByUserId($DIC->user()->getId());
101 foreach ($badges_of_user as $user_badge) {
102 if ((int) $user_badge->getBadgeId() === $badge_id) {
103 return true;
104 }
105 }
106
107 return false;
108 }
static getInstancesByUserId($a_user_id)

References $DIC, and ilBadgeAssignment\getInstancesByUserId().

Referenced by canBeDelivered().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAssignedBadgeOfPublishedUserProfile()

ilBadgeWAC::isAssignedBadgeOfPublishedUserProfile ( \ILIAS\DI\Container  $DIC,
int  $badge_id 
)
private

Definition at line 110 of file class.ilBadgeWAC.php.

110 : bool
111 {
112 // It seems the badge is not assigned to the curent user, so check if the profile of the badge user is made visible
113 $assignments = ilBadgeAssignment::getInstancesByBadgeId($badge_id);
114 foreach ($assignments as $assignment) {
115 if (!$assignment->getPosition()) {
116 continue;
117 }
118
119 $user = ilObjectFactory::getInstanceByObjId((int) $assignment->getUserId(), false);
120 if (!$user instanceof ilObjUser) {
121 continue;
122 }
123
124 $profile_visibility = $user->getPref('public_profile');
125 if ($profile_visibility === 'g' || ($profile_visibility === 'y' && !$DIC->user()->isAnonymous())) {
126 return true;
127 }
128 }
129
130 return false;
131 }
static getInstancesByBadgeId($a_badge_id)
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id

References $DIC, ilObjectFactory\getInstanceByObjId(), and ilBadgeAssignment\getInstancesByBadgeId().

Referenced by canBeDelivered().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: