ILIAS  release_8 Revision v8.24
class.SkillProfileUserDBRepository.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
27 public function __construct(\ilDBInterface $db = null)
28 {
29 global $DIC;
30
31 $this->db = ($db) ?: $DIC->database();
32 $this->lng = $DIC->language();
33 }
34
35 public function getAssignedUsers(int $profile_id): array
36 {
39
40 $set = $ilDB->query(
41 "SELECT * FROM skl_profile_user " .
42 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer")
43 );
44 $users = [];
45 while ($rec = $ilDB->fetchAssoc($set)) {
46 $rec["user_id"] = (int) $rec["user_id"];
47 $name = \ilUserUtil::getNamePresentation($rec["user_id"]);
48 $type = $lng->txt("user");
49 $users[] = [
50 "type" => $type,
51 "name" => $name,
52 "id" => $rec["user_id"],
53 "object_title" => ""
54 ];
55 }
56 return $users;
57 }
58
59 public function addUserToProfile(int $profile_id, int $user_id): void
60 {
62
63 $ilDB->replace(
64 "skl_profile_user",
65 array("profile_id" => array("integer", $profile_id),
66 "user_id" => array("integer", $user_id),
67 ),
68 []
69 );
70 }
71
72 public function removeUserFromProfile(int $profile_id, int $user_id): void
73 {
75
76 $ilDB->manipulate(
77 "DELETE FROM skl_profile_user WHERE " .
78 " profile_id = " . $ilDB->quote($profile_id, "integer") .
79 " AND user_id = " . $ilDB->quote($user_id, "integer")
80 );
81 }
82
83 public function removeUserFromAllProfiles(int $user_id): void
84 {
86
87 $ilDB->manipulate(
88 "DELETE FROM skl_profile_user WHERE " .
89 " user_id = " . $ilDB->quote($user_id, "integer")
90 );
91 }
92
93 public function deleteProfileUsers(int $profile_id): void
94 {
96
97 $ilDB->manipulate(
98 "DELETE FROM skl_profile_user WHERE " .
99 " profile_id = " . $ilDB->quote($profile_id, "integer")
100 );
101 }
102
103 public function getProfilesOfUser(int $user_id): array
104 {
106
107 $user_profiles = [];
108 $set = $ilDB->query(
109 "SELECT p.id, p.title, p.description, p.image_id FROM skl_profile_user u JOIN skl_profile p " .
110 " ON (u.profile_id = p.id) " .
111 " WHERE user_id = " . $ilDB->quote($user_id, "integer") .
112 " ORDER BY p.title ASC"
113 );
114 while ($rec = $ilDB->fetchAssoc($set)) {
115 $rec['id'] = (int) $rec['id'];
116 $user_profiles[] = $rec;
117 }
118
119 return $user_profiles;
120 }
121
122 public function countUsers(int $profile_id): int
123 {
125
126 $set = $ilDB->query(
127 "SELECT count(*) ucnt FROM skl_profile_user " .
128 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer")
129 );
130 $rec = $ilDB->fetchAssoc($set);
131 return (int) $rec["ucnt"];
132 }
133}
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 getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
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