ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator 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: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ clearBadgeCache()

static ilBadgeAssignment::clearBadgeCache ( int  $a_user_id)
static

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

Referenced by ilBadgeProfileGUI\saveSettings().

411  : void {
412  foreach (self::getInstancesByUserId($a_user_id) as $ass) {
413  $ass->deleteStaticFiles();
414  }
415  }
+ Here is the caller graph for this function:

◆ delete()

ilBadgeAssignment::delete ( )

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

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

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

◆ deleteByBadgeId()

static ilBadgeAssignment::deleteByBadgeId ( int  $a_badge_id)
static

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

Referenced by ilBadge\delete().

339  : void
340  {
341  foreach (self::getInstancesByBadgeId($a_badge_id) as $ass) {
342  $ass->delete();
343  }
344  }
+ Here is the caller graph for this function:

◆ deleteByParentId()

static ilBadgeAssignment::deleteByParentId ( int  $a_parent_obj_id)
static

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

346  : void
347  {
348  foreach (self::getInstancesByParentId($a_parent_obj_id) as $ass) {
349  $ass->delete();
350  }
351  }

◆ deleteByUserId()

static ilBadgeAssignment::deleteByUserId ( int  $a_user_id)
static

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

Referenced by ilObjUser\delete().

332  : void
333  {
334  foreach (self::getInstancesByUserId($a_user_id) as $ass) {
335  $ass->delete();
336  }
337  }
+ Here is the caller graph for this function:

◆ deleteStaticFiles()

ilBadgeAssignment::deleteStaticFiles ( )

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

References $path, and ilBadgeHandler\getInstance().

Referenced by delete().

401  : void
402  {
403  // remove instance files
404  $path = ilBadgeHandler::getInstance()->getInstancePath($this);
405  $path = str_replace(".json", ".*", $path);
406  array_map("unlink", glob($path));
407  }
$path
Definition: ltiservices.php:29
+ 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 189 of file class.ilBadgeAssignment.php.

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

192  : bool {
193  $obj = new self($a_badge_id, $a_user_id);
194  return $obj->stored;
195  }
+ Here is the caller graph for this function:

◆ getAssignedUsers()

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

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

References $res.

Referenced by ilBadgeManagementGUI\confirmDeassignBadge().

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

◆ getAwardedBy()

ilBadgeAssignment::getAwardedBy ( )

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

References $awarded_by.

Referenced by getPropertiesForStorage().

237  : int
238  {
239  return $this->awarded_by;
240  }
+ Here is the caller graph for this function:

◆ getBadgeId()

ilBadgeAssignment::getBadgeId ( )

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

References $badge_id.

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

207  : int
208  {
209  return $this->badge_id;
210  }
+ 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
Returns
array[]

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

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

Referenced by ilBadgeLearningHistoryProvider\getEntries().

382  : array {
383  global $DIC;
384 
385  $db = $DIC->database();
386 
387  $set = $db->queryF(
388  "SELECT bdg.parent_id, ub.tstamp, bdg.title FROM badge_user_badge ub JOIN badge_badge bdg" .
389  " ON (ub.badge_id = bdg.id) " .
390  " WHERE ub.user_id = %s AND ub.tstamp >= %s AND ub.tstamp <= %s",
391  array("integer","integer","integer"),
392  array($a_user_id, $a_ts_from, $a_ts_to)
393  );
394  $res = [];
395  while ($rec = $db->fetchAssoc($set)) {
396  $res[] = $rec;
397  }
398  return $res;
399  }
$res
Definition: ltiservices.php:66
fetchAssoc(ilDBStatement $statement)
global $DIC
Definition: shib_login.php:22
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
Returns
self[]

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

References $DIC, $ilDB, and $res.

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

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

◆ getInstancesByParentId()

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

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

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

Referenced by ILIAS\Badge\ilBadgeUserTableGUI\__construct().

150  : array {
151  global $DIC;
152 
153  $ilDB = $DIC->database();
154 
155  $res = array();
156 
157  $badge_ids = array();
158  foreach (ilBadge::getInstancesByParentId($a_parent_obj_id) as $badge) {
159  $badge_ids[] = $badge->getId();
160  }
161  if (count($badge_ids)) {
162  $set = $ilDB->query("SELECT * FROM badge_user_badge" .
163  " WHERE " . $ilDB->in("badge_id", $badge_ids, "", "integer"));
164  while ($row = $ilDB->fetchAssoc($set)) {
165  $obj = new self();
166  $obj->importDBRow($row);
167  $res[] = $obj;
168  }
169  }
170 
171  return $res;
172  }
$res
Definition: ltiservices.php:66
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
global $DIC
Definition: shib_login.php:22
+ 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
Returns
self[]

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

References $DIC, $ilDB, and $res.

Referenced by ilPublicUserProfileGUI\getEmbeddable(), ilBadgePersonalTableGUI\getRecords(), ilBadgeWAC\isAssignedBadge(), and ilPersonalProfileGUI\showPublicProfileFields().

103  : array {
104  global $DIC;
105 
106  $ilDB = $DIC->database();
107 
108  $res = array();
109 
110  $set = $ilDB->query("SELECT * FROM badge_user_badge" .
111  " WHERE user_id = " . $ilDB->quote($a_user_id, "integer") .
112  " ORDER BY pos");
113  while ($row = $ilDB->fetchAssoc($set)) {
114  $obj = new self();
115  $obj->importDBRow($row);
116  $res[] = $obj;
117  }
118 
119  return $res;
120  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22
+ 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: shib_login.php:22
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: shib_login.php:22
queryF(string $query, array $types, array $values)
+ Here is the call graph for this function:

◆ getPosition()

ilBadgeAssignment::getPosition ( )

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

References $pos.

Referenced by getPropertiesForStorage(), and ILIAS\Badge\Tile\profileButton().

247  : ?int
248  {
249  return $this->pos;
250  }
+ Here is the caller graph for this function:

◆ getPropertiesForStorage()

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

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

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

Referenced by store().

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

◆ getTimestamp()

ilBadgeAssignment::getTimestamp ( )

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

References $tstamp.

Referenced by ILIAS\Badge\Tile\addAssignment(), and getPropertiesForStorage().

227  : int
228  {
229  return $this->tstamp;
230  }
+ Here is the caller graph for this function:

◆ getUserId()

ilBadgeAssignment::getUserId ( )

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

References $user_id.

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

217  : int
218  {
219  return $this->user_id;
220  }
+ Here is the caller graph for this function:

◆ importDBRow()

ilBadgeAssignment::importDBRow ( array  $a_row)
protected

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

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

Referenced by read().

257  : void
258  {
259  $this->stored = true;
260  $this->setBadgeId((int) $a_row["badge_id"]);
261  $this->setUserId((int) $a_row["user_id"]);
262  $this->setTimestamp((int) $a_row["tstamp"]);
263  $this->setAwardedBy((int) $a_row["awarded_by"]);
264  $this->setPosition($a_row["pos"]);
265  }
+ 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 267 of file class.ilBadgeAssignment.php.

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

Referenced by __construct().

270  : void {
271  $ilDB = $this->db;
272 
273  $set = $ilDB->query("SELECT * FROM badge_user_badge" .
274  " WHERE badge_id = " . $ilDB->quote($a_badge_id, "integer") .
275  " AND user_id = " . $ilDB->quote($a_user_id, "integer"));
276  $row = $ilDB->fetchAssoc($set);
277  if ($row && $row["user_id"]) {
278  $this->importDBRow($row);
279  }
280  }
+ 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 232 of file class.ilBadgeAssignment.php.

Referenced by importDBRow().

232  : void
233  {
234  $this->awarded_by = $a_id;
235  }
+ Here is the caller graph for this function:

◆ setBadgeId()

ilBadgeAssignment::setBadgeId ( int  $a_value)
protected

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

Referenced by __construct(), and importDBRow().

202  : void
203  {
204  $this->badge_id = $a_value;
205  }
+ Here is the caller graph for this function:

◆ setPosition()

ilBadgeAssignment::setPosition ( ?int  $a_value)

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

Referenced by importDBRow().

242  : void
243  {
244  $this->pos = $a_value;
245  }
+ Here is the caller graph for this function:

◆ setTimestamp()

ilBadgeAssignment::setTimestamp ( int  $a_value)
protected

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

Referenced by importDBRow().

222  : void
223  {
224  $this->tstamp = $a_value;
225  }
+ Here is the caller graph for this function:

◆ setUserId()

ilBadgeAssignment::setUserId ( int  $a_value)
protected

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

Referenced by __construct(), and importDBRow().

212  : void
213  {
214  $this->user_id = $a_value;
215  }
+ Here is the caller graph for this function:

◆ store()

ilBadgeAssignment::store ( )

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

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

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

◆ updatePositions()

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

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

References $id.

Referenced by ilPersonalProfileGUI\savePublicProfile().

356  : void {
357  $existing = array();
358  foreach (self::getInstancesByUserId($a_user_id) as $ass) {
359  $badge = new ilBadge($ass->getBadgeId());
360  $existing[$badge->getId()] = array($badge->getTitle(), $ass);
361  }
362 
363  $new_pos = 0;
364  foreach ($a_positions as $title) {
365  foreach ($existing as $id => $item) {
366  if ($title == $item[0]) {
367  $item[1]->setPosition(++$new_pos);
368  $item[1]->store();
369  unset($existing[$id]);
370  }
371  }
372  }
373  }
$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: