ILIAS  release_8 Revision v8.24
class.SkillProfileRoleDBRepository.php
Go to the documentation of this file.
1<?php
2
20namespace ILIAS\Skill\Profile;
21
23{
24 protected \ilDBInterface $db;
25 protected \ilLanguage $lng;
26 protected \ilRbacReview $review;
27
28 public function __construct(\ilDBInterface $db = null)
29 {
30 global $DIC;
31
32 $this->db = ($db) ?: $DIC->database();
33 $this->lng = $DIC->language();
34 $this->review = $DIC->rbac()->review();
35 }
36
37 public function deleteProfileRoles(int $profile_id): void
38 {
40
41 $ilDB->manipulate(
42 "DELETE FROM skl_profile_role WHERE " .
43 " profile_id = " . $ilDB->quote($profile_id, "integer")
44 );
45 }
46
47 public function getAssignedRoles(int $profile_id): array
48 {
52
53 $set = $ilDB->query(
54 "SELECT * FROM skl_profile_role " .
55 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer")
56 );
57 $roles = [];
58 while ($rec = $ilDB->fetchAssoc($set)) {
59 $rec["role_id"] = (int) $rec["role_id"];
61 $type = $lng->txt("role");
62 // get object of role
64 // get title of object if course or group
65 $obj_title = "";
66 $obj_type = "";
67 if (\ilObject::_lookupType($obj_id) == "crs" || \ilObject::_lookupType($obj_id) == "grp") {
68 $obj_title = \ilObject::_lookupTitle($obj_id);
69 $obj_type = \ilObject::_lookupType($obj_id);
70 }
71
72 $roles[] = [
73 "type" => $type,
74 "name" => $name,
75 "id" => $rec["role_id"],
76 "object_title" => $obj_title,
77 "object_type" => $obj_type,
78 "object_id" => $obj_id
79 ];
80 }
81
82 return $roles;
83 }
84
85 public function addRoleToProfile(int $profile_id, int $role_id): void
86 {
88
89 $ilDB->replace(
90 "skl_profile_role",
91 array("profile_id" => array("integer", $profile_id),
92 "role_id" => array("integer", $role_id),
93 ),
94 []
95 );
96 }
97
98 public function removeRoleFromProfile(int $profile_id, int $role_id): void
99 {
101
102 $ilDB->manipulate(
103 "DELETE FROM skl_profile_role WHERE " .
104 " profile_id = " . $ilDB->quote($profile_id, "integer") .
105 " AND role_id = " . $ilDB->quote($role_id, "integer")
106 );
107 }
108
109 public function removeRoleFromAllProfiles(int $role_id): void
110 {
112
113 $ilDB->manipulate(
114 "DELETE FROM skl_profile_role WHERE " .
115 " role_id = " . $ilDB->quote($role_id, "integer")
116 );
117 }
118
119 public function getAllProfilesOfRole(int $role_id): array
120 {
122
123 $profiles = [];
124 $set = $ilDB->query(
125 "SELECT p.id, p.title, p.description, p.image_id FROM skl_profile_role r JOIN skl_profile p " .
126 " ON (r.profile_id = p.id) " .
127 " WHERE r.role_id = " . $ilDB->quote($role_id, "integer") .
128 " ORDER BY p.title ASC"
129 );
130 while ($rec = $ilDB->fetchAssoc($set)) {
131 $rec['id'] = (int) $rec['id'];
132 $profiles[] = $rec;
133 }
134 return $profiles;
135 }
136
137 public function getGlobalProfilesOfRole(int $role_id): array
138 {
140
141 $profiles = [];
142 $set = $ilDB->query(
143 "SELECT p.id, p.title, p.description, p.image_id FROM skl_profile_role r JOIN skl_profile p " .
144 " ON (r.profile_id = p.id) " .
145 " WHERE r.role_id = " . $ilDB->quote($role_id, "integer") .
146 " AND p.ref_id = 0" .
147 " ORDER BY p.title ASC"
148 );
149 while ($rec = $ilDB->fetchAssoc($set)) {
150 $rec['id'] = (int) $rec['id'];
151 $profiles[] = $rec;
152 }
153
154 return $profiles;
155 }
156
157 public function getLocalProfilesOfRole(int $role_id, int $ref_id): array
158 {
160
161 $profiles = [];
162 $set = $ilDB->query(
163 "SELECT p.id, p.title, p.description, p.image_id FROM skl_profile_role r JOIN skl_profile p " .
164 " ON (r.profile_id = p.id) " .
165 " WHERE r.role_id = " . $ilDB->quote($role_id, "integer") .
166 " AND p.ref_id = " . $ilDB->quote($ref_id, "integer") .
167 " ORDER BY p.title ASC"
168 );
169 while ($rec = $ilDB->fetchAssoc($set)) {
170 $rec['id'] = (int) $rec['id'];
171 $profiles[] = $rec;
172 }
173 return $profiles;
174 }
175
176 public function countRoles(int $profile_id): int
177 {
179
180 $set = $ilDB->query(
181 "SELECT count(*) rcnt FROM skl_profile_role " .
182 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer")
183 );
184 $rec = $ilDB->fetchAssoc($set);
185 return (int) $rec["rcnt"];
186 }
187}
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...
static _getTranslation(string $a_role_title)
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
getObjectReferenceOfRole(int $a_role_id)
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$ref_id
Definition: ltiauth.php:67
if($format !==null) $name
Definition: metadata.php:247
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type