ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilMailbox Class Reference
+ Collaboration diagram for ilMailbox:

Public Member Functions

 __construct (protected int $usr_id)
 
 getRootFolder ()
 
 getInboxFolder ()
 
 getDraftsFolder ()
 
 getOutboxFolder ()
 
 getTrashFolder ()
 
 getSentFolder ()
 
 createDefaultFolder ()
 Creates all default folders for a user. More...
 
 addFolder (int $parent_folder_id, string $name)
 
 renameFolder (int $folder_id, string $name)
 
 deleteFolder (int $folder_id)
 
 getFolderData (int $folder_id)
 
 getParentFolderId (int $folder_id)
 
 getSubFolders ()
 
 setUsrId (int $usr_id)
 
 getUsrId ()
 
 delete ()
 
 updateMailsOfDeletedUser (string $name_to_show)
 Update existing mails. More...
 
 isOwnedFolder (int $folder_id)
 

Protected Member Functions

 folderNameExists (string $name)
 

Private Member Functions

 microMigrateOutboxFolder ()
 
 getFolderDataFromRow (array $row)
 

Private Attributes

readonly ilLanguage $lng
 
readonly ilDBInterface $db
 
readonly ilTree $mtree
 
array $default_folders
 
readonly string $table_mail_obj_data
 
readonly string $table_tree
 

Detailed Description

Definition at line 24 of file class.ilMailbox.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailbox::__construct ( protected int  $usr_id)

Definition at line 50 of file class.ilMailbox.php.

51 {
52 global $DIC;
53
54 if ($usr_id < 1) {
55 throw new InvalidArgumentException('Cannot create mailbox without user id');
56 }
57
58 $this->lng = $DIC->language();
59 $this->db = $DIC->database();
60 $this->table_mail_obj_data = 'mail_obj_data';
61 $this->table_tree = 'mail_tree';
62
63 $this->mtree = new ilTree($this->usr_id);
64 $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
65
66 $this->lng->loadLanguageModule('mail');
67 }
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
global $DIC
Definition: shib_login.php:26

References $DIC, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ addFolder()

ilMailbox::addFolder ( int  $parent_folder_id,
string  $name 
)

Definition at line 205 of file class.ilMailbox.php.

205 : int
206 {
207 if ($this->folderNameExists($name)) {
208 return 0;
209 }
210
211 $next_id = $this->db->nextId($this->table_mail_obj_data);
212 $this->db->manipulateF(
213 'INSERT INTO ' . $this->table_mail_obj_data .
214 ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
215 ['integer', 'integer', 'text', 'text'],
216 [$next_id, $this->usr_id, $name, 'user_folder']
217 );
218 $this->mtree->insertNode($next_id, $parent_folder_id);
219
220 return $next_id;
221 }
folderNameExists(string $name)

References folderNameExists().

+ Here is the call graph for this function:

◆ createDefaultFolder()

ilMailbox::createDefaultFolder ( )

Creates all default folders for a user.

This method should only be called when a user object is created.

Definition at line 182 of file class.ilMailbox.php.

182 : void
183 {
184 $root_folder_id = $this->db->nextId($this->table_mail_obj_data);
185 $this->db->manipulateF(
186 'INSERT INTO ' . $this->table_mail_obj_data .
187 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
188 ['integer', 'integer', 'text', 'text'],
189 [$root_folder_id, $this->usr_id, 'a_root', 'root']
190 );
191 $this->mtree->addTree($this->usr_id, $root_folder_id);
192
193 foreach ($this->default_folders as $key => $folder) {
194 $last_id = $this->db->nextId($this->table_mail_obj_data);
195 $this->db->manipulateF(
196 'INSERT INTO ' . $this->table_mail_obj_data .
197 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
198 ['integer', 'integer', 'text', 'text'],
199 [$last_id, $this->usr_id, $key, $folder]
200 );
201 $this->mtree->insertNode($last_id, $root_folder_id);
202 }
203 }

Referenced by microMigrateOutboxFolder().

+ Here is the caller graph for this function:

◆ delete()

ilMailbox::delete ( )

Definition at line 381 of file class.ilMailbox.php.

381 : void
382 {
383 $this->db->manipulateF(
384 'DELETE FROM mail_obj_data WHERE user_id = %s',
385 ['integer'],
386 [$this->usr_id]
387 );
388
389 $this->db->manipulateF(
390 'DELETE FROM mail_options WHERE user_id = %s',
391 ['integer'],
392 [$this->usr_id]
393 );
394
395 $this->db->manipulateF(
396 'DELETE FROM mail_saved WHERE user_id = %s',
397 ['integer'],
398 [$this->usr_id]
399 );
400
401 $this->db->manipulateF(
402 'DELETE FROM mail_tree WHERE tree = %s',
403 ['integer'],
404 [$this->usr_id]
405 );
406
407 $this->db->manipulateF(
408 'DELETE FROM mail_auto_responder WHERE sender_id = %s OR receiver_id = %s',
409 ['integer', 'integer'],
410 [$this->usr_id, $this->usr_id]
411 );
412
413 // Delete the user's files from filesystem:
414 // This has to be done before deleting the database entries in table 'mail'
415 $fdm = new ilFileDataMail($this->usr_id);
416 $fdm->onUserDelete();
417
418 // Delete mails of deleted user
419 $this->db->manipulateF(
420 'DELETE FROM mail WHERE user_id = %s',
421 ['integer'],
422 [$this->usr_id]
423 );
424 }

◆ deleteFolder()

ilMailbox::deleteFolder ( int  $folder_id)
Exceptions
ilInvalidTreeStructureException

Definition at line 253 of file class.ilMailbox.php.

253 : bool
254 {
255 $query = $this->db->queryF(
256 'SELECT obj_id, title FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
257 ['integer', 'integer'],
258 [$folder_id, $this->usr_id]
259 );
260 $row = $this->db->fetchAssoc($query);
261
262 if (!is_array($row) || array_key_exists($row['title'], $this->default_folders)) {
263 return false;
264 }
265
266 $mailer = new ilMail($this->usr_id);
267
268 $subtree = $this->mtree->getSubTree($this->mtree->getNodeData($folder_id));
269 $this->mtree->deleteTree($this->mtree->getNodeData($folder_id));
270
271 foreach ($subtree as $node) {
272 $node_id = (int) $node['obj_id'];
273
274 $mails = $mailer->getMailsOfFolder($node_id);
275
276 $mail_ids = [];
277 foreach ($mails as $mail) {
278 $mail_ids[] = (int) $mail['mail_id'];
279 }
280
281 $mailer->deleteMails($mail_ids);
282
283 $this->db->manipulateF(
284 'DELETE FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
285 ['integer', 'integer'],
286 [$node_id, $this->usr_id]
287 );
288 }
289
290 return true;
291 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ folderNameExists()

ilMailbox::folderNameExists ( string  $name)
protected

Definition at line 238 of file class.ilMailbox.php.

238 : bool
239 {
240 $res = $this->db->queryF(
241 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
242 ['integer', 'text'],
243 [$this->usr_id, $name]
244 );
245 $row = $this->db->fetchAssoc($res);
246
247 return is_array($row) && $row['obj_id'] > 0;
248 }
$res
Definition: ltiservices.php:69

References $res.

Referenced by addFolder(), and renameFolder().

+ Here is the caller graph for this function:

◆ getDraftsFolder()

ilMailbox::getDraftsFolder ( )

Definition at line 95 of file class.ilMailbox.php.

95 : int
96 {
97 $res = $this->db->queryF(
98 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
99 ['integer', 'text'],
100 [$this->usr_id, 'drafts']
101 );
102
103 $row = $this->db->fetchAssoc($res);
104
105 return (int) $row['obj_id'];
106 }

References $res.

Referenced by microMigrateOutboxFolder().

+ Here is the caller graph for this function:

◆ getFolderData()

ilMailbox::getFolderData ( int  $folder_id)

Definition at line 293 of file class.ilMailbox.php.

294 {
295 $res = $this->db->queryF(
296 'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND obj_id = %s',
297 ['integer', 'integer'],
298 [$this->usr_id, $folder_id]
299 );
300 $row = $this->db->fetchAssoc($res);
301
302 if (is_array($row)) {
303 return $this->getFolderDataFromRow($row);
304 }
305
306 return null;
307 }
getFolderDataFromRow(array $row)

References $res, and getFolderDataFromRow().

Referenced by isOwnedFolder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFolderDataFromRow()

ilMailbox::getFolderDataFromRow ( array  $row)
private

Definition at line 309 of file class.ilMailbox.php.

310 {
311 return new MailFolderData(
312 (int) $row['obj_id'],
313 (int) $row['user_id'],
314 MailFolderType::from($row['m_type']),
315 (string) ($row['m_type'] === MailFolderType::USER->value
316 ? $row['title']
317 : $this->lng->txt('mail_' . $row['title']))
318 );
319 }

References ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), ILIAS\Repository\lng(), and ILIAS\Test\Results\Toplist\USER.

Referenced by getFolderData(), and getSubFolders().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInboxFolder()

ilMailbox::getInboxFolder ( )

Definition at line 82 of file class.ilMailbox.php.

82 : int
83 {
84 $res = $this->db->queryF(
85 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
86 ['integer', 'text'],
87 [$this->usr_id, 'inbox']
88 );
89
90 $row = $this->db->fetchAssoc($res);
91
92 return (int) $row['obj_id'];
93 }

References $res.

◆ getOutboxFolder()

ilMailbox::getOutboxFolder ( )

Definition at line 108 of file class.ilMailbox.php.

108 : int
109 {
110 $res = $this->db->queryF(
111 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
113 [$this->usr_id, 'outbox']
114 );
115
116 $row = $this->db->fetchAssoc($res);
117 if ($row === null) {
118 return $this->microMigrateOutboxFolder();
119 }
120
121 return (int) $row['obj_id'];
122 }
microMigrateOutboxFolder()

References $res, microMigrateOutboxFolder(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ getParentFolderId()

ilMailbox::getParentFolderId ( int  $folder_id)

Definition at line 321 of file class.ilMailbox.php.

321 : int
322 {
323 $res = $this->db->queryF(
324 'SELECT * FROM ' . $this->table_tree . ' WHERE child = %s AND tree = %s',
325 ['integer', 'integer'],
326 [$folder_id, $this->usr_id]
327 );
328 $row = $this->db->fetchAssoc($res);
329
330 return is_array($row) ? (int) $row['parent'] : 0;
331 }

References $res, and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getRootFolder()

ilMailbox::getRootFolder ( )

Definition at line 69 of file class.ilMailbox.php.

69 : ?int
70 {
71 $res = $this->db->queryF(
72 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
73 ['integer', 'text'],
74 [$this->usr_id, 'root']
75 );
76
77 $row = $this->db->fetchAssoc($res);
78
79 return isset($row['obj_id']) ? (int) $row['obj_id'] : null;
80 }

References $res, and ILIAS\Repository\int().

Referenced by microMigrateOutboxFolder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSentFolder()

ilMailbox::getSentFolder ( )

Definition at line 166 of file class.ilMailbox.php.

166 : int
167 {
168 $res = $this->db->queryF(
169 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
170 ['integer', 'text'],
171 [$this->usr_id, 'sent']
172 );
173
174 $row = $this->db->fetchAssoc($res);
175
176 return (int) $row['obj_id'];
177 }

References $res.

◆ getSubFolders()

ilMailbox::getSubFolders ( )
Returns
list<MailFolderData>

Definition at line 336 of file class.ilMailbox.php.

336 : array
337 {
338 $user_folders = [];
339
340 foreach (array_keys($this->default_folders) as $key) {
341 $res = $this->db->queryF(
342 'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
343 ['integer', 'text'],
344 [$this->usr_id, $key]
345 );
346 $row = $this->db->fetchAssoc($res);
347 if (is_array($row)) {
348 $user_folders[] = $this->getFolderDataFromRow($row);
349 }
350 }
351
352 $query = implode(' ', [
353 'SELECT * FROM ' . $this->table_tree . ', ' . $this->table_mail_obj_data,
354 'WHERE ' . $this->table_mail_obj_data . '.obj_id = ' . $this->table_tree . '.child',
355 'AND ' . $this->table_tree . '.depth > %s',
356 'AND ' . $this->table_tree . '.tree = %s',
357 'ORDER BY ' . $this->table_tree . '.lft, ' . $this->table_mail_obj_data . '.title',
358 ]);
359 $res = $this->db->queryF(
360 $query,
361 ['integer', 'integer'],
362 [2, $this->usr_id]
363 );
364 while ($row = $this->db->fetchAssoc($res)) {
365 $user_folders[] = $this->getFolderDataFromRow($row);
366 }
367
368 return $user_folders;
369 }

References $res, and getFolderDataFromRow().

+ Here is the call graph for this function:

◆ getTrashFolder()

ilMailbox::getTrashFolder ( )

Definition at line 153 of file class.ilMailbox.php.

153 : int
154 {
155 $res = $this->db->queryF(
156 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
157 ['integer', 'text'],
158 [$this->usr_id, 'trash']
159 );
160
161 $row = $this->db->fetchAssoc($res);
162
163 return (int) $row['obj_id'];
164 }

References $res.

◆ getUsrId()

ilMailbox::getUsrId ( )

Definition at line 376 of file class.ilMailbox.php.

376 : int
377 {
378 return $this->usr_id;
379 }

◆ isOwnedFolder()

ilMailbox::isOwnedFolder ( int  $folder_id)

Definition at line 439 of file class.ilMailbox.php.

439 : bool
440 {
441 $folder_data = $this->getFolderData($folder_id);
442
443 return $folder_data?->getFolderId() === $folder_id;
444 }
getFolderData(int $folder_id)

References getFolderData().

+ Here is the call graph for this function:

◆ microMigrateOutboxFolder()

ilMailbox::microMigrateOutboxFolder ( )
private

Definition at line 124 of file class.ilMailbox.php.

124 : int
125 {
126 $root_folder_id = $this->getRootFolder();
127 if ($root_folder_id === null) {
128 $this->createDefaultFolder();
129
130 $res = $this->db->queryF(
131 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
133 [$this->usr_id, 'outbox']
134 );
135 $row = $this->db->fetchAssoc($res);
136
137 return (int) ($row['obj_id'] ?? 0);
138 }
139
140 $last_id = $this->db->nextId($this->table_mail_obj_data);
141 $this->db->manipulateF(
142 'INSERT INTO ' . $this->table_mail_obj_data .
143 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
145 [$last_id, $this->usr_id, 'e_outbox', 'outbox']
146 );
147
148 $this->mtree->insertNode($last_id, $root_folder_id, $this->getDraftsFolder());
149
150 return $last_id;
151 }
createDefaultFolder()
Creates all default folders for a user.

References $res, createDefaultFolder(), getDraftsFolder(), getRootFolder(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by getOutboxFolder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renameFolder()

ilMailbox::renameFolder ( int  $folder_id,
string  $name 
)

Definition at line 223 of file class.ilMailbox.php.

223 : bool
224 {
225 if ($this->folderNameExists($name)) {
226 return false;
227 }
228
229 $this->db->manipulateF(
230 'UPDATE ' . $this->table_mail_obj_data . ' SET title = %s WHERE obj_id = %s AND user_id = %s',
231 ['text', 'integer', 'integer'],
232 [$name, $folder_id, $this->usr_id]
233 );
234
235 return true;
236 }

References folderNameExists().

+ Here is the call graph for this function:

◆ setUsrId()

ilMailbox::setUsrId ( int  $usr_id)

Definition at line 371 of file class.ilMailbox.php.

371 : void
372 {
373 $this->usr_id = $usr_id;
374 }

◆ updateMailsOfDeletedUser()

ilMailbox::updateMailsOfDeletedUser ( string  $name_to_show)

Update existing mails.

Set sender id to 0 and import name to login name. This is only necessary for deleted users.

Definition at line 430 of file class.ilMailbox.php.

430 : void
431 {
432 $this->db->manipulateF(
433 'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
434 ['integer', 'text', 'integer'],
435 [0, $name_to_show, $this->usr_id]
436 );
437 }

Field Documentation

◆ $db

readonly ilDBInterface ilMailbox::$db
private

Definition at line 27 of file class.ilMailbox.php.

◆ $default_folders

array ilMailbox::$default_folders
private
Initial value:
= [
'b_inbox' => 'inbox',
'c_trash' => 'trash',
'd_drafts' => 'drafts',
'e_outbox' => 'outbox',
'f_sent' => 'sent',
'z_local' => 'local',
]

Definition at line 39 of file class.ilMailbox.php.

◆ $lng

readonly ilLanguage ilMailbox::$lng
private

Definition at line 26 of file class.ilMailbox.php.

◆ $mtree

readonly ilTree ilMailbox::$mtree
private

Definition at line 28 of file class.ilMailbox.php.

◆ $table_mail_obj_data

readonly string ilMailbox::$table_mail_obj_data
private

Definition at line 47 of file class.ilMailbox.php.

◆ $table_tree

readonly string ilMailbox::$table_tree
private

Definition at line 48 of file class.ilMailbox.php.


The documentation for this class was generated from the following file: