ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCmiXapiDelModel.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 public const DB_TABLE_NAME = 'cmix_settings';
31 public const DB_USERS_TABLE_NAME = 'cmix_users';
32
33 public const DB_DEL_OBJ = 'cmix_del_object';
34 public const DB_DEL_USERS = 'cmix_del_user';
35
36 private \ILIAS\DI\Container $dic;
37
39
40 private static ?ilCmiXapiDelModel $instance = null;
41
42 protected ilLogger $log;
43
44 public function __construct()
45 {
46 global $DIC;
47 $this->dic = $DIC;
48 $this->db = $this->dic->database();
49 $this->log = ilLoggerFactory::getLogger('cmix');
50 //
51 }
52
53 public static function init(): ilCmiXapiDelModel
54 {
55 return self::$instance ?? self::$instance = new self();
56 }
57
58 public function getXapiObjIdForUser(int $userId): ?array
59 {
60 $data = null;
61 $where = $this->db->quote($userId, 'integer');
62 $result = $this->db->query("SELECT obj_id FROM " . self::DB_USERS_TABLE_NAME . " WHERE usr_id = " . $where);
63 while($row = $this->db->fetchAssoc($result)) {
64 if(is_null($data)) {
65 $data = [];
66 }
67 $data[] = $row['obj_id'];
68 }
69 return $data;
70 }
71
72 public function setXapiUserAsDeleted(int $userId): bool
73 {
74 $values = [
75 'usr_id' => ['integer', $userId],
76 'added' => ['timestamp', date('Y-m-d H:i:s')]
77 ];
78 $this->db->insert(self::DB_DEL_USERS, $values);
79 return true;
80 }
81
82 public function setUserAsUpdated(int $usrId)
83 {
84 $this->db->update(self::DB_DEL_USERS, [
85 'updated' => ['timestamp', date('Y-m-d H:i:s')]
86 ], [
87 'usr_id' => ['integer', $usrId]
88 ]);
89 }
90
91 public function resetUpdatedXapiUser(int $usrId)
92 {
93 $this->db->update(self::DB_DEL_USERS, [
94 'updated' => ['timestamp', null]
95 ], [
96 'usr_id' => ['integer', $usrId]
97 ]);
98 }
99
100
101
102 public function getXapiObjectsByDeletedUsers(): array
103 {
104 $data = [];
105 $result = $this->db->query("SELECT obj.obj_id, obj.lrs_type_id, obj.activity_id, usr.usr_id, usr.usr_ident, del.added FROM " .
106 self::DB_TABLE_NAME . " obj, " .
107 self::DB_USERS_TABLE_NAME . " usr, " .
108 self::DB_DEL_USERS . " del " .
109 #" INNER JOIN " . self::DB_DEL_USERS . " del ON usr.usr_id = xdel.usr_id" .
110 " WHERE usr.usr_id = del.usr_id AND obj.obj_id = usr.obj_id AND del.updated IS NULL");
111 while($row = $this->db->fetchAssoc($result)) {
112 if(is_null($data)) {
113 $data = [];
114 }
115 $data[] = $row;
116 }
117 return $data;
118 }
119
120 public function getXapiObjectsByUser(int $userId): array
121 {
122 $data = [];
123 $result = $this->db->query("SELECT obj.obj_id, obj.lrs_type_id, obj.activity_id FROM " .
124 self::DB_TABLE_NAME . " obj, " .
125 self::DB_USERS_TABLE_NAME . " usr" .
126 #" INNER JOIN " . self::DB_DEL_USERS . " del ON usr.usr_id = xdel.usr_id" .
127 " WHERE usr.usr_id = " . $this->db->quote($userId, 'integer') . " AND obj.obj_id = usr.obj_id");
128 while($row = $this->db->fetchAssoc($result)) {
129 if(is_null($data)) {
130 $data = [];
131 }
132 $data[] = $row;
133 }
134 return $data;
135 }
136
137 public function getNewDeletedUsers()
138 {
139 $data = array();
140
141 $result = $this->db->query("SELECT * FROM " . self::DB_DEL_USERS . " WHERE updated IS NULL");
142 while($row = $this->db->fetchAssoc($result)) {
143 $data[] = $row;
144 }
145 return $data;
146 }
147
148 public function deleteUserEntry($usrId)
149 {
150 $this->db->manipulateF(
151 'DELETE FROM ' . self::DB_DEL_USERS . ' WHERE usr_id = %s',
152 ['integer'],
153 [$usrId]
154 );
155 }
156
157 // XXCF OBJECTS
158
159 public function getXapiObjectData(int $objId)
160 {
161 $data = null;
162 $where = $this->db->quote($objId, 'integer');
163 $result = $this->db->query("SELECT lrs_type_id, activity_id, delete_data FROM " . self::DB_TABLE_NAME . " WHERE obj_id = " . $where);
164 while($row = $this->db->fetchAssoc($result)) {
165 $data = $row;
166 }
167 return $data;
168 }
169
170 public function getAllXapiDelObjectData(): array
171 {
172 $data = array();
173
174 $result = $this->db->query("SELECT * FROM " . self::DB_DEL_OBJ . " WHERE 1");
175 while($row = $this->db->fetchAssoc($result)) {
176 $data[] = $row;
177 }
178 return $data;
179 }
180
181 public function getNewDeletedXapiObjects()
182 {
183 $data = array();
184
185 $result = $this->db->query("SELECT * FROM " . self::DB_DEL_OBJ . " WHERE updated IS NULL");
186 while($row = $this->db->fetchAssoc($result)) {
187 $data[] = $row;
188 }
189 return $data;
190 }
191
193 {
194 $this->db->manipulateF(
195 'DELETE FROM ' . self::DB_DEL_OBJ . ' WHERE obj_id = %s',
196 ['integer'],
197 [$objId]
198 );
199 }
200
201 public function setXapiObjAsDeleted(int $objId, int $typeId, string $actId): void
202 {
203 $values = [
204 'obj_id' => ['integer', $objId],
205 'type_id' => ['integer', $typeId],
206 'activity_id' => ['string', $actId],
207 'added' => ['timestamp', date('Y-m-d H:i:s')]
208 ];
209 $this->db->insert(self::DB_DEL_OBJ, $values);
210
211 if(!$this->dic->cron()->manager()->isJobActive('xapi_deletion_cron')) {
213 $xapiDelete->delete();
214 }
215 }
216
217 public function setXapiObjAsUpdated(int $objId)
218 {
219
220 $this->db->update(self::DB_DEL_OBJ, [
221 'updated' => ['timestamp', date('Y-m-d H:i:s')]
222 ], [
223 'obj_id' => ['integer', $objId]
224 ]);
225 }
226
227 public function resetUpdatedXapiObj(int $objId)
228 {
229
230 $this->db->update(self::DB_DEL_OBJ, [
231 'updated' => ['timestamp', null]
232 ], [
233 'obj_id' => ['integer', $objId]
234 ]);
235 }
236
237 public function removeCmixUsersForObject(int $objId): void
238 {
239 $this->db->manipulateF(
240 'DELETE FROM cmix_users WHERE obj_id = %s',
241 ['integer'],
242 [$objId]
243 );
244 $this->log->debug('cmix_users deleted for objId=' . (string) $objId);
245
246 }
247
248}
Class ilCmiXapiDelModel.
ILIAS DI Container $dic
setXapiObjAsDeleted(int $objId, int $typeId, string $actId)
static ilCmiXapiDelModel $instance
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Interface ilDBInterface.
$typeId
Definition: ltiregstart.php:34
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:57