ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMailingLists.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private readonly ilDBInterface $db;
28 private ?ilMailingList $ml = null;
29
30 public function __construct(private readonly ilObjUser $user)
31 {
32 global $DIC;
33
34 $this->db = $DIC['ilDB'];
35 }
36
37 public function isOwner(int $a_ml_id, int $a_usr_id): bool
38 {
39 $res = $this->db->queryF(
40 'SELECT EXISTS(SELECT 1 FROM addressbook_mlist WHERE ml_id = %s AND user_id = %s) cnt',
41 ['integer', 'integer'],
42 [$a_ml_id, $a_usr_id]
43 );
44 $row = $this->db->fetchAssoc($res);
45
46 return is_array($row) && (int) $row['cnt'] === 1;
47 }
48
49 public function get(int $id = 0): ilMailingList
50 {
51 return new ilMailingList($this->user, $id);
52 }
53
58 public function getSelected(array $a_ids = []): array
59 {
60 $entries = [];
61
62 foreach ($a_ids as $id) {
63 $entries[] = new ilMailingList($this->user, $id);
64 }
65
66 return $entries;
67 }
68
69 public function hasAny(): bool
70 {
71 $res = $this->db->queryF(
72 'SELECT EXISTS(SELECT 1 FROM addressbook_mlist WHERE user_id = %s) cnt',
73 ['integer'],
74 [$this->user->getId()]
75 );
76 $row = $this->db->fetchAssoc($res);
77
78 return (is_array($row) && (int) $row['cnt'] === 1);
79 }
80
84 public function getAll(): array
85 {
86 $res = $this->db->queryF(
87 'SELECT * FROM addressbook_mlist WHERE user_id = %s',
88 ['integer'],
89 [$this->user->getId()]
90 );
91
92 $entries = [];
93
94 $counter = 0;
95 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
96 $tmpObj = new ilMailingList($this->user, 0);
97 $tmpObj->setId((int) $row->ml_id);
98 $tmpObj->setUserId((int) $row->user_id);
99 $tmpObj->setTitle($row->title);
100 $tmpObj->setDescription($row->description);
101 $tmpObj->setCreatedate($row->createdate);
102 $tmpObj->setChangedate($row->changedate);
103 $tmpObj->setMode((int) $row->lmode);
104
105 $entries[$counter] = $tmpObj;
106
107 unset($tmpObj);
108
109 ++$counter;
110 }
111
112 return $entries;
113 }
114
115 public function mailingListExists(string $a_list_name): bool
116 {
117 $ml_id = (int) substr($a_list_name, strrpos($a_list_name, '_') + 1);
118 if (!is_numeric($ml_id) || $ml_id <= 0) {
119 return false;
120 }
121
122 $this->setCurrentMailingList($ml_id);
123
124 return $this->getCurrentMailingList()->doesExist();
125 }
126
127 public function setCurrentMailingList(int $id = 0): void
128 {
129 $this->ml = $this->get($id);
130 }
131
132
134 {
135 return $this->ml;
136 }
137
138 public function deleteTemporaryLists(): void
139 {
140 foreach ($this->getAll() as $mlist) {
141 if ($mlist->getMode() === ilMailingList::MODE_TEMPORARY) {
142 $mlist->delete();
143 }
144 }
145 }
146
147 public function deleteLists(): void
148 {
149 $this->db->manipulateF(
150 'DELETE ass FROM addressbook_mlist_ass ass INNER JOIN addressbook_mlist list ON ass.ml_id = list.ml_id WHERE list.user_id = %s',
151 ['integer'],
152 [$this->user->getId()]
153 );
154 $this->db->manipulateF(
155 'DELETE FROM addressbook_mlist WHERE user_id = %s',
156 ['integer'],
157 [$this->user->getId()]
158 );
159 }
160
161 public function deleteAssignments(): void
162 {
163 $this->db->manipulate(
164 'DELETE FROM addressbook_mlist_ass WHERE usr_id = ' . $this->db->quote($this->user->getId(), 'integer')
165 );
166 }
167}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
final const int MODE_TEMPORARY
__construct(private readonly ilObjUser $user)
getSelected(array $a_ids=[])
mailingListExists(string $a_list_name)
setCurrentMailingList(int $id=0)
readonly ilDBInterface $db
isOwner(int $a_ml_id, int $a_usr_id)
User class.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26
$counter