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