ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilBadgeAssignment Class Reference

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

+ Collaboration diagram for ilBadgeAssignment:

Public Member Functions

 __construct (int $a_badge_id=null, int $a_user_id=null)
 
 getBadgeId ()
 
 getUserId ()
 
 getTimestamp ()
 
 setAwardedBy (int $a_id)
 
 getAwardedBy ()
 
 setPosition (?int $a_value)
 
 getPosition ()
 
 store ()
 
 delete ()
 
 deleteStaticFiles ()
 

Static Public Member Functions

static getNewCounter (int $a_user_id)
 
static getLatestTimestamp (int $a_user_id)
 
static getInstancesByUserId (int $a_user_id)
 
static getInstancesByBadgeId (int $a_badge_id)
 
static getInstancesByParentId (int $a_parent_obj_id)
 
static getAssignedUsers (int $a_badge_id)
 
static exists (int $a_badge_id, int $a_user_id)
 
static deleteByUserId (int $a_user_id)
 
static deleteByBadgeId (int $a_badge_id)
 
static deleteByParentId (int $a_parent_obj_id)
 
static updatePositions (int $a_user_id, array $a_positions)
 
static getBadgesForUser (int $a_user_id, int $a_ts_from, int $a_ts_to)
 
static clearBadgeCache (int $a_user_id)
 

Protected Member Functions

 setBadgeId (int $a_value)
 
 setUserId (int $a_value)
 
 setTimestamp (int $a_value)
 
 importDBRow (array $a_row)
 
 read (int $a_badge_id, int $a_user_id)
 
 getPropertiesForStorage ()
 

Protected Attributes

ilDBInterface $db
 
int $badge_id = 0
 
int $user_id = 0
 
int $tstamp = 0
 
int $awarded_by = 0
 
int $pos = null
 
bool $stored = false
 

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 Class ilBadgeAssignment

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 24 of file class.ilBadgeAssignment.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadgeAssignment::__construct ( int  $a_badge_id = null,
int  $a_user_id = null 
)

Definition at line 34 of file class.ilBadgeAssignment.php.

References $DIC, read(), setBadgeId(), and setUserId().

37  {
38  global $DIC;
39 
40  $this->db = $DIC->database();
41  if ($a_badge_id &&
42  $a_user_id) {
43  $this->setBadgeId($a_badge_id);
44  $this->setUserId($a_user_id);
45 
46  $this->read($a_badge_id, $a_user_id);
47  }
48  }
read(int $a_badge_id, int $a_user_id)
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ clearBadgeCache()

static ilBadgeAssignment::clearBadgeCache ( int  $a_user_id)
static

Definition at line 416 of file class.ilBadgeAssignment.php.

Referenced by ilBadgeProfileGUI\saveSettings().

418  : void {
419  foreach (self::getInstancesByUserId($a_user_id) as $ass) {
420  $ass->deleteStaticFiles();
421  }
422  }
+ Here is the caller graph for this function:

◆ delete()

ilBadgeAssignment::delete ( )

Definition at line 320 of file class.ilBadgeAssignment.php.

References $db, $ilDB, deleteStaticFiles(), getBadgeId(), and getUserId().

320  : void
321  {
322  $ilDB = $this->db;
323 
324  if (!$this->getBadgeId() ||
325  !$this->getUserId()) {
326  return;
327  }
328 
329  $this->deleteStaticFiles();
330 
331  $ilDB->manipulate("DELETE FROM badge_user_badge" .
332  " WHERE badge_id = " . $ilDB->quote($this->getBadgeId(), "integer") .
333  " AND user_id = " . $ilDB->quote($this->getUserId(), "integer"));
334  }
+ Here is the call graph for this function:

◆ deleteByBadgeId()

static ilBadgeAssignment::deleteByBadgeId ( int  $a_badge_id)
static

Definition at line 343 of file class.ilBadgeAssignment.php.

Referenced by ilBadge\delete().

343  : void
344  {
345  foreach (self::getInstancesByBadgeId($a_badge_id) as $ass) {
346  $ass->delete();
347  }
348  }
+ Here is the caller graph for this function:

◆ deleteByParentId()

static ilBadgeAssignment::deleteByParentId ( int  $a_parent_obj_id)
static

Definition at line 350 of file class.ilBadgeAssignment.php.

350  : void
351  {
352  foreach (self::getInstancesByParentId($a_parent_obj_id) as $ass) {
353  $ass->delete();
354  }
355  }

◆ deleteByUserId()

static ilBadgeAssignment::deleteByUserId ( int  $a_user_id)
static

Definition at line 336 of file class.ilBadgeAssignment.php.

Referenced by ilObjUser\delete().

336  : void
337  {
338  foreach (self::getInstancesByUserId($a_user_id) as $ass) {
339  $ass->delete();
340  }
341  }
+ Here is the caller graph for this function:

◆ deleteStaticFiles()

ilBadgeAssignment::deleteStaticFiles ( )

Definition at line 408 of file class.ilBadgeAssignment.php.

References $path, and ilBadgeHandler\getInstance().

Referenced by delete().

408  : void
409  {
410  // remove instance files
411  $path = ilBadgeHandler::getInstance()->getInstancePath($this);
412  $path = str_replace(".json", ".*", $path);
413  array_map("unlink", glob($path));
414  }
$path
Definition: ltiservices.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exists()

static ilBadgeAssignment::exists ( int  $a_badge_id,
int  $a_user_id 
)
static

Definition at line 193 of file class.ilBadgeAssignment.php.

Referenced by ilBadgeManagementGUI\assignBadge(), ilBadgeHandler\sendNotification(), and ilBadgeHandler\triggerEvaluation().

196  : bool {
197  $obj = new self($a_badge_id, $a_user_id);
198  return $obj->stored;
199  }
+ Here is the caller graph for this function:

◆ getAssignedUsers()

static ilBadgeAssignment::getAssignedUsers ( int  $a_badge_id)
static
Parameters
int$a_badge_id
Returns
int[]

Definition at line 181 of file class.ilBadgeAssignment.php.

References $res.

Referenced by ilBadgeManagementGUI\confirmDeassignBadge().

183  : array {
184  $res = [];
185 
186  foreach (self::getInstancesByBadgeId($a_badge_id) as $ass) {
187  $res[] = $ass->getUserId();
188  }
189 
190  return $res;
191  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getAwardedBy()

ilBadgeAssignment::getAwardedBy ( )

Definition at line 241 of file class.ilBadgeAssignment.php.

References $awarded_by.

Referenced by getPropertiesForStorage().

241  : int
242  {
243  return $this->awarded_by;
244  }
+ Here is the caller graph for this function:

◆ getBadgeId()

ilBadgeAssignment::getBadgeId ( )

Definition at line 211 of file class.ilBadgeAssignment.php.

References $badge_id.

Referenced by delete(), ilBadgeHandler\getInstancePath(), and store().

211  : int
212  {
213  return $this->badge_id;
214  }
+ Here is the caller graph for this function:

◆ getBadgesForUser()

static ilBadgeAssignment::getBadgesForUser ( int  $a_user_id,
int  $a_ts_from,
int  $a_ts_to 
)
static
Parameters
int$a_user_id
int$a_ts_from
int$a_ts_to
Returns
array[]

Definition at line 385 of file class.ilBadgeAssignment.php.

References $DIC, $res, ilDBInterface\fetchAssoc(), and ilDBInterface\queryF().

Referenced by ilBadgeLearningHistoryProvider\getEntries().

389  : array {
390  global $DIC;
391 
392  $db = $DIC->database();
393 
394  $set = $db->queryF(
395  "SELECT bdg.parent_id, ub.tstamp, bdg.title FROM badge_user_badge ub JOIN badge_badge bdg" .
396  " ON (ub.badge_id = bdg.id) " .
397  " WHERE ub.user_id = %s AND ub.tstamp >= %s AND ub.tstamp <= %s",
398  array("integer","integer","integer"),
399  array($a_user_id, $a_ts_from, $a_ts_to)
400  );
401  $res = [];
402  while ($rec = $db->fetchAssoc($set)) {
403  $res[] = $rec;
404  }
405  return $res;
406  }
$res
Definition: ltiservices.php:69
fetchAssoc(ilDBStatement $statement)
global $DIC
Definition: feed.php:28
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstancesByBadgeId()

static ilBadgeAssignment::getInstancesByBadgeId ( int  $a_badge_id)
static
Parameters
int$a_badge_id
Returns
self[]

Definition at line 127 of file class.ilBadgeAssignment.php.

References $DIC, $ilDB, and $res.

Referenced by ilBadgeManagementGUI\confirmDeleteBadges(), ilObjBadgeAdministrationGUI\confirmDeleteObjectBadges(), and ilBadgeWAC\isAssignedBadgeOfPublishedUserProfile().

129  : array {
130  global $DIC;
131 
132  $ilDB = $DIC->database();
133 
134  $res = array();
135 
136  $set = $ilDB->query("SELECT * FROM badge_user_badge" .
137  " WHERE badge_id = " . $ilDB->quote($a_badge_id, "integer"));
138  while ($row = $ilDB->fetchAssoc($set)) {
139  $obj = new self();
140  $obj->importDBRow($row);
141  $res[] = $obj;
142  }
143 
144  return $res;
145  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getInstancesByParentId()

static ilBadgeAssignment::getInstancesByParentId ( int  $a_parent_obj_id)
static
Parameters
int$a_parent_obj_id
Returns
self[]

Definition at line 151 of file class.ilBadgeAssignment.php.

References $DIC, $ilDB, $res, and ilBadge\getInstancesByParentId().

Referenced by ilBadgeUserTableGUI\getItems().

153  : array {
154  global $DIC;
155 
156  $ilDB = $DIC->database();
157 
158  $res = array();
159 
160  $badge_ids = array();
161  foreach (ilBadge::getInstancesByParentId($a_parent_obj_id) as $badge) {
162  $badge_ids[] = $badge->getId();
163  }
164  if (count($badge_ids)) {
165  $set = $ilDB->query("SELECT * FROM badge_user_badge" .
166  " WHERE " . $ilDB->in("badge_id", $badge_ids, "", "integer"));
167  while ($row = $ilDB->fetchAssoc($set)) {
168  $obj = new self();
169  $obj->importDBRow($row);
170  $res[] = $obj;
171  }
172  }
173 
174  return $res;
175  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInstancesByUserId()

static ilBadgeAssignment::getInstancesByUserId ( int  $a_user_id)
static
Parameters
int$a_user_id
Returns
self[]

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

References $DIC, $ilDB, and $res.

Referenced by ilPublicUserProfileGUI\getEmbeddable(), ilBadgePersonalTableGUI\getItems(), ilBadgeWAC\isAssignedBadge(), ilBadgeProfileGUI\listBadges(), and ilPersonalProfileGUI\showPublicProfileFields().

104  : array {
105  global $DIC;
106 
107  $ilDB = $DIC->database();
108 
109  $res = array();
110 
111  $set = $ilDB->query("SELECT * FROM badge_user_badge" .
112  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
113  " ORDER BY pos");
114  while ($row = $ilDB->fetchAssoc($set)) {
115  $obj = new self();
116  $obj->importDBRow($row);
117  $res[] = $obj;
118  }
119 
120  return $res;
121  }
$res
Definition: ltiservices.php:69
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ getLatestTimestamp()

static ilBadgeAssignment::getLatestTimestamp ( int  $a_user_id)
static

Definition at line 81 of file class.ilBadgeAssignment.php.

References $DIC, ilDBInterface\fetchAssoc(), and ilDBInterface\queryF().

83  : int {
84  global $DIC;
85 
86  $db = $DIC->database();
87 
88  $set = $db->queryF(
89  "SELECT max(tstamp) maxts FROM badge_user_badge " .
90  " WHERE user_id = %s",
91  ["integer"],
92  [$a_user_id]
93  );
94  $rec = $db->fetchAssoc($set);
95  return (int) $rec["maxts"];
96  }
fetchAssoc(ilDBStatement $statement)
global $DIC
Definition: feed.php:28
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ getNewCounter()

static ilBadgeAssignment::getNewCounter ( int  $a_user_id)
static

Definition at line 50 of file class.ilBadgeAssignment.php.

References $DIC, ilDBInterface\fetchAssoc(), and ilDBInterface\queryF().

52  : int {
53  global $DIC;
54 
55  $db = $DIC->database();
56 
57  $user = new ilObjUser($a_user_id);
58  $noti_repo = new \ILIAS\Badge\Notification\BadgeNotificationPrefRepository($user);
59 
60  $last = $noti_repo->getLastCheckedTimestamp();
61 
62 
63  // if no last check exists, we use last 24 hours
64  if ($last === 0) {
65  $last = time() - (24 * 60 * 60);
66  }
67 
68  if ($last > 0) {
69  $set = $db->queryF(
70  "SELECT count(*) cnt FROM badge_user_badge " .
71  " WHERE user_id = %s AND tstamp >= %s",
72  ["integer", "integer"],
73  [$a_user_id, $last]
74  );
75  $rec = $db->fetchAssoc($set);
76  return (int) $rec["cnt"];
77  }
78  return 0;
79  }
fetchAssoc(ilDBStatement $statement)
global $DIC
Definition: feed.php:28
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ getPosition()

ilBadgeAssignment::getPosition ( )

Definition at line 251 of file class.ilBadgeAssignment.php.

References $pos.

Referenced by getPropertiesForStorage().

251  : ?int
252  {
253  return $this->pos;
254  }
+ Here is the caller graph for this function:

◆ getPropertiesForStorage()

ilBadgeAssignment::getPropertiesForStorage ( )
protected
Returns
array<string, array>

Definition at line 289 of file class.ilBadgeAssignment.php.

References getAwardedBy(), getPosition(), and getTimestamp().

Referenced by store().

289  : array
290  {
291  return [
292  "tstamp" => ["integer", $this->stored ? $this->getTimestamp() : time()],
293  "awarded_by" => ["integer", $this->getAwardedBy()],
294  "pos" => ["integer", $this->getPosition()]
295  ];
296  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTimestamp()

ilBadgeAssignment::getTimestamp ( )

Definition at line 231 of file class.ilBadgeAssignment.php.

References $tstamp.

Referenced by getPropertiesForStorage().

231  : int
232  {
233  return $this->tstamp;
234  }
+ Here is the caller graph for this function:

◆ getUserId()

ilBadgeAssignment::getUserId ( )

Definition at line 221 of file class.ilBadgeAssignment.php.

References $user_id.

Referenced by delete(), ilBadgeHandler\getInstancePath(), and store().

221  : int
222  {
223  return $this->user_id;
224  }
+ Here is the caller graph for this function:

◆ importDBRow()

ilBadgeAssignment::importDBRow ( array  $a_row)
protected

Definition at line 261 of file class.ilBadgeAssignment.php.

References setAwardedBy(), setBadgeId(), setPosition(), setTimestamp(), and setUserId().

Referenced by read().

261  : void
262  {
263  $this->stored = true;
264  $this->setBadgeId((int) $a_row["badge_id"]);
265  $this->setUserId((int) $a_row["user_id"]);
266  $this->setTimestamp((int) $a_row["tstamp"]);
267  $this->setAwardedBy((int) $a_row["awarded_by"]);
268  $this->setPosition($a_row["pos"]);
269  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilBadgeAssignment::read ( int  $a_badge_id,
int  $a_user_id 
)
protected

Definition at line 271 of file class.ilBadgeAssignment.php.

References $db, $ilDB, and importDBRow().

Referenced by __construct().

274  : void {
275  $ilDB = $this->db;
276 
277  $set = $ilDB->query("SELECT * FROM badge_user_badge" .
278  " WHERE badge_id = " . $ilDB->quote($a_badge_id, "integer") .
279  " AND user_id = " . $ilDB->quote($a_user_id, "integer"));
280  $row = $ilDB->fetchAssoc($set);
281  if ($row && $row["user_id"]) {
282  $this->importDBRow($row);
283  }
284  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAwardedBy()

ilBadgeAssignment::setAwardedBy ( int  $a_id)

Definition at line 236 of file class.ilBadgeAssignment.php.

Referenced by importDBRow().

236  : void
237  {
238  $this->awarded_by = $a_id;
239  }
+ Here is the caller graph for this function:

◆ setBadgeId()

ilBadgeAssignment::setBadgeId ( int  $a_value)
protected

Definition at line 206 of file class.ilBadgeAssignment.php.

Referenced by __construct(), and importDBRow().

206  : void
207  {
208  $this->badge_id = $a_value;
209  }
+ Here is the caller graph for this function:

◆ setPosition()

ilBadgeAssignment::setPosition ( ?int  $a_value)

Definition at line 246 of file class.ilBadgeAssignment.php.

Referenced by importDBRow().

246  : void
247  {
248  $this->pos = $a_value;
249  }
+ Here is the caller graph for this function:

◆ setTimestamp()

ilBadgeAssignment::setTimestamp ( int  $a_value)
protected

Definition at line 226 of file class.ilBadgeAssignment.php.

Referenced by importDBRow().

226  : void
227  {
228  $this->tstamp = $a_value;
229  }
+ Here is the caller graph for this function:

◆ setUserId()

ilBadgeAssignment::setUserId ( int  $a_value)
protected

Definition at line 216 of file class.ilBadgeAssignment.php.

Referenced by __construct(), and importDBRow().

216  : void
217  {
218  $this->user_id = $a_value;
219  }
+ Here is the caller graph for this function:

◆ store()

ilBadgeAssignment::store ( )

Definition at line 298 of file class.ilBadgeAssignment.php.

References $db, $ilDB, $keys, getBadgeId(), getPropertiesForStorage(), and getUserId().

Referenced by ilBadgeHandler\triggerEvaluation().

298  : void
299  {
300  $ilDB = $this->db;
301 
302  if (!$this->getBadgeId() ||
303  !$this->getUserId()) {
304  return;
305  }
306 
307  $keys = array(
308  "badge_id" => array("integer", $this->getBadgeId()),
309  "user_id" => array("integer", $this->getUserId())
310  );
311  $fields = $this->getPropertiesForStorage();
312 
313  if (!$this->stored) {
314  $ilDB->insert("badge_user_badge", $fields + $keys);
315  } else {
316  $ilDB->update("badge_user_badge", $fields, $keys);
317  }
318  }
$keys
Definition: metadata.php:204
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updatePositions()

static ilBadgeAssignment::updatePositions ( int  $a_user_id,
array  $a_positions 
)
static

Definition at line 357 of file class.ilBadgeAssignment.php.

References $id.

Referenced by ilPersonalProfileGUI\savePublicProfile().

360  : void {
361  $existing = array();
362  foreach (self::getInstancesByUserId($a_user_id) as $ass) {
363  $badge = new ilBadge($ass->getBadgeId());
364  $existing[$badge->getId()] = array($badge->getTitle(), $ass);
365  }
366 
367  $new_pos = 0;
368  foreach ($a_positions as $title) {
369  foreach ($existing as $id => $item) {
370  if ($title == $item[0]) {
371  $item[1]->setPosition(++$new_pos);
372  $item[1]->store();
373  unset($existing[$id]);
374  }
375  }
376  }
377  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

Field Documentation

◆ $awarded_by

int ilBadgeAssignment::$awarded_by = 0
protected

Definition at line 30 of file class.ilBadgeAssignment.php.

Referenced by getAwardedBy().

◆ $badge_id

int ilBadgeAssignment::$badge_id = 0
protected

Definition at line 27 of file class.ilBadgeAssignment.php.

Referenced by getBadgeId().

◆ $db

ilDBInterface ilBadgeAssignment::$db
protected

Definition at line 26 of file class.ilBadgeAssignment.php.

Referenced by delete(), read(), and store().

◆ $pos

int ilBadgeAssignment::$pos = null
protected

Definition at line 31 of file class.ilBadgeAssignment.php.

Referenced by getPosition().

◆ $stored

bool ilBadgeAssignment::$stored = false
protected

Definition at line 32 of file class.ilBadgeAssignment.php.

◆ $tstamp

int ilBadgeAssignment::$tstamp = 0
protected

Definition at line 29 of file class.ilBadgeAssignment.php.

Referenced by getTimestamp().

◆ $user_id

int ilBadgeAssignment::$user_id = 0
protected

Definition at line 28 of file class.ilBadgeAssignment.php.

Referenced by getUserId().


The documentation for this class was generated from the following file: