ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.SkillProfileCompletionDBRepository.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Skill\Profile;
22
24
31{
32 protected \ilDBInterface $db;
34
35 public function __construct(
36 ?\ilDBInterface $db = null,
38 ) {
39 global $DIC;
40
41 $this->db = ($db) ?: $DIC->database();
42 $this->factory_service = ($factory_service) ?: $DIC->skills()->internal()->factory();
43 }
44
49 public function getEntries(int $user_id, int $profile_id): array
50 {
52
53 $set = $ilDB->query(
54 "SELECT * FROM skl_profile_completion " .
55 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer") .
56 " AND user_id = " . $ilDB->quote($user_id, "integer")
57 );
58 $entries = [];
59 while ($rec = $ilDB->fetchAssoc($set)) {
60 $entries[] = $this->getFromRecord($rec);
61 }
62
63 return $entries;
64 }
65
66 protected function getFromRecord(array $rec): SkillProfileCompletion
67 {
68 $rec["profile_id"] = (int) $rec["profile_id"];
69 $rec["user_id"] = (int) $rec["user_id"];
70 $rec["fulfilled"] = (bool) $rec["fulfilled"];
71
72 return $this->factory_service->profile()->profileCompletion(
73 $rec["profile_id"],
74 $rec["user_id"],
75 $rec["date"],
76 $rec["fulfilled"]
77 );
78 }
79
83 public function addFulfilmentEntry(int $user_id, int $profile_id): void
84 {
86
87 $set = $ilDB->query(
88 "SELECT * FROM skl_profile_completion " .
89 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer") .
90 " AND user_id = " . $ilDB->quote($user_id, "integer") .
91 " ORDER BY date DESC" .
92 " LIMIT 1"
93 );
94
95 $entry = null;
96 while ($rec = $ilDB->fetchAssoc($set)) {
97 $entry = $rec["fulfilled"];
98 }
99
100 if ($entry == 0) {
101 $now = \ilUtil::now();
102 $ilDB->manipulate("INSERT INTO skl_profile_completion " .
103 "(profile_id, user_id, date, fulfilled) VALUES (" .
104 $ilDB->quote($profile_id, "integer") . "," .
105 $ilDB->quote($user_id, "integer") . "," .
106 $ilDB->quote($now, "timestamp") . "," .
107 $ilDB->quote(1, "integer") .
108 ")");
109 }
110 }
111
115 public function addNonFulfilmentEntry(int $user_id, int $profile_id): void
116 {
118
119 $set = $ilDB->query(
120 "SELECT * FROM skl_profile_completion " .
121 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer") .
122 " AND user_id = " . $ilDB->quote($user_id, "integer") .
123 " ORDER BY date DESC" .
124 " LIMIT 1"
125 );
126
127 $entry = null;
128 while ($rec = $ilDB->fetchAssoc($set)) {
129 $entry = $rec["fulfilled"];
130 }
131
132 if (is_null($entry) || $entry == 1) {
133 $now = \ilUtil::now();
134 $ilDB->manipulate("INSERT INTO skl_profile_completion " .
135 "(profile_id, user_id, date, fulfilled) VALUES (" .
136 $ilDB->quote($profile_id, "integer") . "," .
137 $ilDB->quote($user_id, "integer") . "," .
138 $ilDB->quote($now, "timestamp") . "," .
139 $ilDB->quote(0, "integer") .
140 ")");
141 }
142 }
143
148 public function getFulfilledEntriesForUser(int $user_id): array
149 {
151
152 $set = $ilDB->query(
153 "SELECT * FROM skl_profile_completion " .
154 " WHERE user_id = " . $ilDB->quote($user_id, "integer") .
155 " AND fulfilled = 1"
156 );
157 $entries = [];
158 while ($rec = $ilDB->fetchAssoc($set)) {
159 $entries[] = $this->getFromRecord($rec);
160 }
161
162 return $entries;
163 }
164
169 public function getAllEntriesForUser(int $user_id): array
170 {
172
173 $set = $ilDB->query(
174 "SELECT * FROM skl_profile_completion " .
175 " WHERE user_id = " . $ilDB->quote($user_id, "integer")
176 );
177 $entries = [];
178 while ($rec = $ilDB->fetchAssoc($set)) {
179 $entries[] = $this->getFromRecord($rec);
180 }
181
182 return $entries;
183 }
184
189 public function getAllEntriesForProfile(int $profile_id): array
190 {
192
193 $set = $ilDB->query(
194 "SELECT * FROM skl_profile_completion " .
195 " WHERE profile_id = " . $ilDB->quote($profile_id, "integer")
196 );
197 $entries = [];
198 while ($rec = $ilDB->fetchAssoc($set)) {
199 $entries[] = $this->getFromRecord($rec);
200 }
201
202 return $entries;
203 }
204
208 public function deleteEntriesForProfile(int $profile_id): void
209 {
211
212 $ilDB->manipulate(
213 "DELETE FROM skl_profile_completion WHERE "
214 . " profile_id = " . $ilDB->quote($profile_id, "integer")
215 );
216 }
217
221 public function deleteEntriesForUser(int $user_id): void
222 {
224
225 $ilDB->manipulate(
226 "DELETE FROM skl_profile_completion WHERE "
227 . " user_id = " . $ilDB->quote($user_id, "integer")
228 );
229 }
230}
getAllEntriesForProfile(int $profile_id)
Get all completion entries for a single profile.
getEntries(int $user_id, int $profile_id)
Get profile completion entries for given user-profile-combination.
deleteEntriesForUser(int $user_id)
Delete all profile completion entries for a user.
deleteEntriesForProfile(int $profile_id)
Delete all profile completion entries for a profile.
getFulfilledEntriesForUser(int $user_id)
Get all fulfilled profile completion entries for a user.
getAllEntriesForUser(int $user_id)
Get all profile completion entries for a user.
__construct(?\ilDBInterface $db=null, ?Service\SkillInternalFactoryService $factory_service=null)
addFulfilmentEntry(int $user_id, int $profile_id)
Add profile fulfilment entry to given user-profile-combination.
addNonFulfilmentEntry(int $user_id, int $profile_id)
Add profile non-fulfilment entry to given user-profile-combination.
static now()
Return current timestamp in Y-m-d H:i:s format.
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26