ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMailingList.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 final public const int MODE_ADDRESSBOOK = 1;
28 final public const int MODE_TEMPORARY = 2;
29
30 private int $user_id;
31 private string $title = '';
32 private ?string $description = '';
33 private string $createdate;
34 private ?string $changedate = null;
35 private readonly ilDBInterface $db;
36
37 private int $mode;
38 private bool $exists = false;
39
40 public function __construct(ilObjUser $user, private int $mail_id = 0)
41 {
42 global $DIC;
43
44 $this->db = $DIC['ilDB'];
45 $this->user_id = $user->getId();
46
47 $this->setMode(self::MODE_ADDRESSBOOK);
48
49 $this->read();
50 }
51
52 public function insert(): bool
53 {
54 $nextId = $this->db->nextId('addressbook_mlist');
55 $this->db->manipulateF(
56 '
57 INSERT INTO addressbook_mlist
58 ( ml_id,
59 user_id,
60 title,
61 description,
62 createdate,
63 changedate,
64 lmode
65 )
66 VALUES(%s, %s, %s, %s, %s, %s, %s)',
67 [
68 'integer',
69 'integer',
70 'text',
71 'text',
72 'timestamp',
73 'timestamp',
74 'integer'
75 ],
76 [
77 $nextId,
78 $this->getUserId(),
79 $this->getTitle(),
80 $this->getDescription(),
81 $this->getCreatedate(),
82 null,
83 $this->getMode()
84 ]
85 );
86
87 $this->mail_id = $nextId;
88 $this->exists = true;
89
90 return true;
91 }
92
93 public function update(): bool
94 {
95 if ($this->mail_id && $this->user_id) {
96 $this->db->manipulateF(
97 '
98 UPDATE addressbook_mlist
99 SET title = %s,
100 description = %s,
101 changedate = %s,
102 lmode = %s
103 WHERE ml_id = %s
104 AND user_id = %s',
105 [
106 'text',
107 'text',
108 'timestamp',
109 'integer',
110 'integer',
111 'integer'
112 ],
113 [
114 $this->getTitle(),
115 $this->getDescription(),
116 $this->getChangedate(),
117 $this->getMode(),
118 $this->getId(),
119 $this->getUserId()
120 ]
121 );
122
123 return true;
124 }
125
126 return false;
127 }
128
129 public function delete(): bool
130 {
131 if ($this->mail_id && $this->user_id) {
132 $this->deassignAllEntries();
133
134 $this->db->manipulateF(
135 'DELETE FROM addressbook_mlist WHERE ml_id = %s AND user_id = %s',
136 ['integer', 'integer'],
137 [$this->getId(), $this->getUserId()]
138 );
139 $this->exists = false;
140
141 return true;
142 }
143
144 return false;
145 }
146
147 private function read(): void
148 {
149 if ($this->getId() && $this->getUserId()) {
150 $res = $this->db->queryF(
151 'SELECT * FROM addressbook_mlist WHERE ml_id = %s AND user_id =%s',
152 ['integer', 'integer'],
153 [$this->getId(), $this->getUserId()]
154 );
155
156 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
157
158 if (is_object($row)) {
159 $this->setId((int) $row->ml_id);
160 $this->setUserId((int) $row->user_id);
161 $this->setTitle($row->title);
162 $this->setDescription($row->description);
163 $this->setCreatedate($row->createdate);
164 $this->setChangedate($row->changedate);
165 $this->setMode((int) $row->lmode);
166 $this->exists = true;
167 }
168 }
169 }
170
174 public function getAssignedEntries(): array
175 {
176 $res = $this->db->queryF(
177 'SELECT a_id, usr_data.usr_id FROM addressbook_mlist_ass ' .
178 'INNER JOIN usr_data ON usr_data.usr_id = addressbook_mlist_ass.usr_id WHERE ml_id = %s',
179 ['integer'],
180 [$this->getId()]
181 );
182
183 $entries = [];
184 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
185 $entries[(int) $row->a_id] = [
186 'a_id' => (int) $row->a_id,
187 'usr_id' => (int) $row->usr_id
188 ];
189 }
190
191 return $entries;
192 }
193
194
195 public function assignUser(int $usr_id = 0): bool
196 {
197 $nextId = $this->db->nextId('addressbook_mlist_ass');
198 $this->db->manipulateF(
199 'INSERT INTO addressbook_mlist_ass (a_id, ml_id, usr_id) VALUES(%s, %s, %s)',
200 ['integer', 'integer', 'integer'],
201 [$nextId, $this->getId(), $usr_id]
202 );
203 return true;
204 }
205
206
207 public function deleteEntry(int $a_id = 0): bool
208 {
209 $this->db->manipulateF(
210 'DELETE FROM addressbook_mlist_ass WHERE a_id = %s',
211 ['integer'],
212 [$a_id]
213 );
214 return true;
215 }
216
217
218 public function deassignAllEntries(): bool
219 {
220 $this->db->manipulateF(
221 'DELETE FROM addressbook_mlist_ass WHERE ml_id = %s',
222 ['integer'],
223 [$this->getId()]
224 );
225 return true;
226 }
227
228 public function setId(int $a_mail_id = 0): void
229 {
230 $this->mail_id = $a_mail_id;
231 }
232
233 public function getId(): int
234 {
235 return $this->mail_id;
236 }
237
238 public function setUserId(int $a_user_id = 0): void
239 {
240 $this->user_id = $a_user_id;
241 }
242
243 public function getUserId(): int
244 {
245 return $this->user_id;
246 }
247
248 public function setTitle(string $a_title = ''): void
249 {
250 $this->title = $a_title;
251 }
252
253 public function getTitle(): string
254 {
255 return $this->title;
256 }
257
258 public function setDescription(?string $a_description = ''): void
259 {
260 $this->description = $a_description;
261 }
262
263 public function getDescription(): ?string
264 {
265 return $this->description;
266 }
267
268 public function setCreatedate(string $_createdate): void
269 {
270 $this->createdate = $_createdate;
271 }
272
273 public function getCreatedate(): string
274 {
275 return $this->createdate;
276 }
277
278 public function setChangedate(?string $a_changedate): void
279 {
280 $this->changedate = $a_changedate;
281 }
282
283 public function getChangedate(): ?string
284 {
285 return $this->changedate;
286 }
287
288 public function setMode(int $a_mode): void
289 {
290 if (in_array($a_mode, [self::MODE_ADDRESSBOOK, self::MODE_TEMPORARY], true)) {
291 $this->mode = $a_mode;
292 }
293 }
294
295 public function getMode(): int
296 {
297 return $this->mode;
298 }
299 public function doesExist(): bool
300 {
301 return $this->exists;
302 }
303}
assignUser(int $usr_id=0)
__construct(ilObjUser $user, private int $mail_id=0)
setTitle(string $a_title='')
setMode(int $a_mode)
setCreatedate(string $_createdate)
readonly ilDBInterface $db
final const int MODE_TEMPORARY
setChangedate(?string $a_changedate)
deleteEntry(int $a_id=0)
setDescription(?string $a_description='')
setUserId(int $a_user_id=0)
final const int MODE_ADDRESSBOOK
setId(int $a_mail_id=0)
User class.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26