31 protected ?
int $pos =
null;
35 ?
int $a_badge_id =
null,
36 ?
int $a_user_id =
null
40 $this->db =
$DIC->database();
46 $this->
read($a_badge_id, $a_user_id);
58 $noti_repo = new \ILIAS\Badge\Notification\BadgeNotificationPrefRepository($user);
60 $last = $noti_repo->getLastCheckedTimestamp();
65 $last = time() - (24 * 60 * 60);
70 "SELECT count(*) cnt FROM badge_user_badge " .
71 " WHERE user_id = %s AND tstamp >= %s",
72 [
"integer",
"integer"],
76 return (
int) $rec[
"cnt"];
86 $db =
$DIC->database();
89 "SELECT max(tstamp) maxts FROM badge_user_badge " .
90 " WHERE user_id = %s",
95 return (
int) $rec[
"maxts"];
110 $set =
$ilDB->query(
"SELECT * FROM badge_user_badge" .
111 " WHERE user_id = " .
$ilDB->quote($a_user_id,
"integer") .
113 while ($row =
$ilDB->fetchAssoc($set)) {
115 $obj->importDBRow($row);
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)) {
138 $obj->importDBRow($row);
157 $badge_ids = array();
159 $badge_ids[] = $badge->getId();
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)) {
166 $obj->importDBRow($row);
182 foreach (self::getInstancesByBadgeId($a_badge_id) as $ass) {
183 $res[] = $ass->getUserId();
193 $obj = new self($a_badge_id, $a_user_id);
204 $this->badge_id = $a_value;
209 return $this->badge_id;
214 $this->user_id = $a_value;
224 $this->tstamp = $a_value;
229 return $this->tstamp;
234 $this->awarded_by = $a_id;
239 return $this->awarded_by;
244 $this->pos = $a_value;
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"]);
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);
288 "tstamp" => [
"integer", $this->stored ? $this->getTimestamp() : time()],
289 "awarded_by" => [
"integer", $this->getAwardedBy()],
290 "pos" => [
"integer", $this->getPosition()]
298 if (!$this->getBadgeId() ||
299 !$this->getUserId()) {
304 "badge_id" => array(
"integer", $this->getBadgeId()),
305 "user_id" => array(
"integer", $this->getUserId())
307 $fields = $this->getPropertiesForStorage();
309 if (!$this->stored) {
310 $ilDB->insert(
"badge_user_badge", $fields + $keys);
312 $ilDB->update(
"badge_user_badge", $fields, $keys);
316 public function delete():
void
320 if (!$this->getBadgeId() ||
321 !$this->getUserId()) {
325 $this->deleteStaticFiles();
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"));
334 foreach (self::getInstancesByUserId($a_user_id) as $ass) {
341 foreach (self::getInstancesByBadgeId($a_badge_id) as $ass) {
348 foreach (self::getInstancesByParentId($a_parent_obj_id) as $ass) {
358 foreach (self::getInstancesByUserId($a_user_id) as $ass) {
359 $badge =
new ilBadge($ass->getBadgeId());
360 $existing[$badge->getId()] = array($badge->getTitle(), $ass);
364 foreach ($a_positions as $title) {
365 foreach ($existing as
$id => $item) {
366 if ($title == $item[0]) {
367 $item[1]->setPosition(++$new_pos);
369 unset($existing[
$id]);
385 $db =
$DIC->database();
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)
406 array_map(
"unlink", glob(
$path));
412 foreach (self::getInstancesByUserId($a_user_id) as $ass) {
413 $ass->deleteStaticFiles();
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNewCounter(int $a_user_id)
setTimestamp(int $a_value)
static clearBadgeCache(int $a_user_id)
static deleteByUserId(int $a_user_id)
static deleteByBadgeId(int $a_badge_id)
static getInstancesByBadgeId(int $a_badge_id)
static getAssignedUsers(int $a_badge_id)
getPropertiesForStorage()
read(int $a_badge_id, int $a_user_id)
static updatePositions(int $a_user_id, array $a_positions)
static getInstancesByUserId(int $a_user_id)
static getInstancesByParentId(int $a_parent_obj_id)
static exists(int $a_badge_id, int $a_user_id)
__construct(?int $a_badge_id=null, ?int $a_user_id=null)
static deleteByParentId(int $a_parent_obj_id)
importDBRow(array $a_row)
setPosition(?int $a_value)
static getLatestTimestamp(int $a_user_id)
static getBadgesForUser(int $a_user_id, int $a_ts_from, int $a_ts_to)
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)