ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilBadgeWAC Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilBadgeWAC:
+ Collaboration diagram for ilBadgeWAC:

Public Member Functions

 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

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Member Function Documentation

◆ canBeDelivered()

ilBadgeWAC::canBeDelivered ( ilWACPath  $ilWACPath)

Implements ilWACCheckingClass.

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

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

21  : bool
22  {
23  global $DIC;
24 
25  if (strpos($ilWACPath->getPath(), '..') !== false) {
26  return false;
27  }
28 
29  if (!preg_match('@ilBadge\/(\d+\/)*?badge(tmpl)?_(\d+)\/@ui', $ilWACPath->getPath())) {
30  return false;
31  }
32 
33  $obj_id = array_keys(ilObject::_getObjectsByType('bdga'))[0] ?? null;
34  $admin_ref_id = null;
35  if ($obj_id > 0) {
36  $admin_ref_id = array_values(ilObject::_getAllReferences($obj_id))[0] ?? null;
37  }
38 
39  $has_global_badge_administration_access = (
40  $admin_ref_id > 0 &&
41  $DIC->rbac()->system()->checkAccessOfUser($DIC->user()->getId(), 'read', $admin_ref_id)
42  );
43 
44  if (preg_match('@\/badgetmpl_(\d+)\/@ui', $ilWACPath->getPath())) {
45  // Badge template images must only be accessible for accounts with `read` permission on the badge administration node
46  return $has_global_badge_administration_access;
47  }
48 
49  if (preg_match('@\/badge_(\d+)\/@ui', $ilWACPath->getPath(), $matches)) {
50  if ($has_global_badge_administration_access) {
51  return true;
52  }
53 
54  $badge_id = (int) $matches[1];
55 
56  return (
57  $this->isAssignedBadge($DIC, $badge_id) ||
58  $this->isAssignedBadgeOfPublishedUserProfile($DIC, $badge_id) ||
59  $this->hasAccessToBadgeParentIdNode($DIC, $badge_id, $has_global_badge_administration_access)
60  );
61  }
62 
63  return false;
64  }
static _getObjectsByType(string $obj_type="", ?int $owner=null)
static _getAllReferences(int $id)
get all reference ids for object ID
hasAccessToBadgeParentIdNode(\ILIAS\DI\Container $DIC, int $badge_id, bool $has_global_badge_administration_access)
isAssignedBadge(\ILIAS\DI\Container $DIC, int $badge_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
isAssignedBadgeOfPublishedUserProfile(\ILIAS\DI\Container $DIC, int $badge_id)
global $DIC
Definition: shib_login.php:26
+ 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 66 of file class.ilBadgeWAC.php.

References ilObject\_getAllReferences(), ilBadgeHandler\getInstance(), ILIAS\Repository\int(), null, and SYSTEM_FOLDER_ID.

Referenced by canBeDelivered().

70  : bool {
71  // If the acting user still does not have access, check if the image is used in an object badge type
72  $badge = new ilBadge($badge_id);
73  if ($badge->getParentId() > 0) {
74  return false;
75  }
76 
77  $badge_handler = ilBadgeHandler::getInstance();
78  if (!$badge_handler->isObjectActive((int) $badge->getParentId())) {
79  return false;
80  }
81 
82  $context_ref_id = array_values(ilObject::_getAllReferences((int) $badge->getParentId()))[0] ?? null;
83  if (!($context_ref_id > 0)) {
84  return false;
85  }
86 
87  $context_ref_id = (int) $context_ref_id;
88  if ($DIC->repositoryTree()->isGrandChild((int) SYSTEM_FOLDER_ID, $context_ref_id)) {
89  $has_access = $has_global_badge_administration_access;
90  } else {
91  $has_access = $DIC->access()->checkAccessOfUser(
92  $DIC->user()->getId(),
93  'write',
94  '',
95  $context_ref_id
96  );
97  }
98 
99  return $has_access;
100  }
static _getAllReferences(int $id)
get all reference ids for object ID
const SYSTEM_FOLDER_ID
Definition: constants.php:35
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isAssignedBadge()

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

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

References ilBadgeAssignment\getInstancesByUserId().

Referenced by canBeDelivered().

102  : bool
103  {
104  // First, check all badge assignments of the current user for a match
105  $badges_of_user = ilBadgeAssignment::getInstancesByUserId($DIC->user()->getId());
106  foreach ($badges_of_user as $user_badge) {
107  if ((int) $user_badge->getBadgeId() === $badge_id) {
108  return true;
109  }
110  }
111 
112  return false;
113  }
static getInstancesByUserId(int $a_user_id)
global $DIC
Definition: shib_login.php:26
+ 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 115 of file class.ilBadgeWAC.php.

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

Referenced by canBeDelivered().

115  : bool
116  {
117  // It seems the badge is not assigned to the curent user, so check if the profile of the badge user is made visible
118  $assignments = ilBadgeAssignment::getInstancesByBadgeId($badge_id);
119  foreach ($assignments as $assignment) {
120  if (!$assignment->getPosition()) {
121  continue;
122  }
123 
124  $user = ilObjectFactory::getInstanceByObjId((int) $assignment->getUserId(), false);
125  if (!$user instanceof ilObjUser) {
126  continue;
127  }
128 
129  $profile_visibility = $user->getPref('public_profile');
130  if ($profile_visibility === 'g' || ($profile_visibility === 'y' && !$DIC->user()->isAnonymous())) {
131  return true;
132  }
133  }
134 
135  return false;
136  }
static getInstancesByBadgeId(int $a_badge_id)
global $DIC
Definition: shib_login.php:26
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ 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: