ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
class.ilDclNotification.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  private const string TABLE_NAME = 'il_dcl_notification';
24 
25  public function __construct(private readonly ILDBInterface $db)
26  {
27  }
28 
29  public function has(ilObjDataCollection $obj, int $user_id, ilDclNotificationType $type): bool
30  {
31  return null !== $this->db->fetchAssoc($this->db->queryF(
32  'SELECT 1 FROM ' . $this::TABLE_NAME . ' WHERE obj_id = %s AND usr_id = %s AND setting = %s LIMIT 1',
34  [$obj->getId(), $user_id, $type->value]
35  ));
36  }
37 
38  public function add(ilObjDataCollection $obj, ilObjUser $user, ilDclNotificationType $type): void
39  {
40  if (!$this->has($obj, $user->getId(), $type)) {
41  $this->db->insert('il_dcl_notification', [
42  'obj_id' => [ilDBConstants::T_INTEGER, $obj->getId()],
43  'usr_id' => [ilDBConstants::T_INTEGER, $user->getId()],
44  'setting' => [ilDBConstants::T_INTEGER, $type->value]
45  ]);
46  }
47  }
48 
49  public function delete(ilObjDataCollection $obj, ilObjUser $user, ilDclNotificationType $type): void
50  {
51  $this->db->manipulateF(
52  'DELETE FROM ' . $this::TABLE_NAME . ' WHERE obj_id = %s AND usr_id = %s AND setting = %s',
54  [$obj->getId(), $user->getId(), $type->value]
55  );
56  }
57 
58  public function clear(ilObjDataCollection $obj, ilObjUser $user): void
59  {
60  $this->db->manipulateF(
61  'DELETE FROM ' . $this::TABLE_NAME . ' WHERE obj_id = %s AND usr_id = %s',
63  [$obj->getId(), $user->getId()]
64  );
65  }
66 
67  public function deleteForObject(ilObjDataCollection $obj): void
68  {
69  $this->db->manipulateF(
70  'DELETE FROM ' . $this::TABLE_NAME . ' WHERE obj_id = %s',
72  [$obj->getId()]
73  );
74  }
75 
76  public function deleteForUser(int $user_id): void
77  {
78  $this->db->manipulateF(
79  'DELETE FROM ' . $this::TABLE_NAME . ' WHERE usr_id = %s',
81  [$user_id]
82  );
83  }
84 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
add(ilObjDataCollection $obj, ilObjUser $user, ilDclNotificationType $type)
clear(ilObjDataCollection $obj, ilObjUser $user)
__construct(private readonly ILDBInterface $db)
deleteForObject(ilObjDataCollection $obj)
has(ilObjDataCollection $obj, int $user_id, ilDclNotificationType $type)