ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMailbox Class Reference
+ Collaboration diagram for ilMailbox:

Public Member Functions

 __construct (protected int $usr_id)
 
 getRooFolder ()
 
 getInboxFolder ()
 
 getDraftsFolder ()
 
 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

 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 41 of file class.ilMailbox.php.

42 {
43 global $DIC;
44
45 if ($usr_id < 1) {
46 throw new InvalidArgumentException('Cannot create mailbox without user id');
47 }
48
49 $this->lng = $DIC->language();
50 $this->db = $DIC->database();
51 $this->table_mail_obj_data = 'mail_obj_data';
52 $this->table_tree = 'mail_tree';
53
54 $this->mtree = new ilTree($this->usr_id);
55 $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
56
57 $this->lng->loadLanguageModule('mail');
58 }
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 151 of file class.ilMailbox.php.

151 : int
152 {
153 if ($this->folderNameExists($name)) {
154 return 0;
155 }
156
157 $next_id = $this->db->nextId($this->table_mail_obj_data);
158 $this->db->manipulateF(
159 'INSERT INTO ' . $this->table_mail_obj_data .
160 ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
161 ['integer', 'integer', 'text', 'text'],
162 [$next_id, $this->usr_id, $name, 'user_folder']
163 );
164 $this->mtree->insertNode($next_id, $parent_folder_id);
165
166 return $next_id;
167 }
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 128 of file class.ilMailbox.php.

128 : void
129 {
130 $root_folder_id = $this->db->nextId($this->table_mail_obj_data);
131 $this->db->manipulateF(
132 'INSERT INTO ' . $this->table_mail_obj_data .
133 ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
134 ['integer', 'integer', 'text', 'text'],
135 [$root_folder_id, $this->usr_id, 'a_root', 'root']
136 );
137 $this->mtree->addTree($this->usr_id, $root_folder_id);
138
139 foreach ($this->default_folders as $key => $folder) {
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)',
144 ['integer', 'integer', 'text', 'text'],
145 [$last_id, $this->usr_id, $key, $folder]
146 );
147 $this->mtree->insertNode($last_id, $root_folder_id);
148 }
149 }

◆ delete()

ilMailbox::delete ( )

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

327 : void
328 {
329 $this->db->manipulateF(
330 'DELETE FROM mail_obj_data WHERE user_id = %s',
331 ['integer'],
332 [$this->usr_id]
333 );
334
335 $this->db->manipulateF(
336 'DELETE FROM mail_options WHERE user_id = %s',
337 ['integer'],
338 [$this->usr_id]
339 );
340
341 $this->db->manipulateF(
342 'DELETE FROM mail_saved WHERE user_id = %s',
343 ['integer'],
344 [$this->usr_id]
345 );
346
347 $this->db->manipulateF(
348 'DELETE FROM mail_tree WHERE tree = %s',
349 ['integer'],
350 [$this->usr_id]
351 );
352
353 $this->db->manipulateF(
354 'DELETE FROM mail_auto_responder WHERE sender_id = %s OR receiver_id = %s',
355 ['integer', 'integer'],
356 [$this->usr_id, $this->usr_id]
357 );
358
359 // Delete the user's files from filesystem:
360 // This has to be done before deleting the database entries in table 'mail'
361 $fdm = new ilFileDataMail($this->usr_id);
362 $fdm->onUserDelete();
363
364 // Delete mails of deleted user
365 $this->db->manipulateF(
366 'DELETE FROM mail WHERE user_id = %s',
367 ['integer'],
368 [$this->usr_id]
369 );
370 }

◆ deleteFolder()

ilMailbox::deleteFolder ( int  $folder_id)
Exceptions
ilInvalidTreeStructureException

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

199 : bool
200 {
201 $query = $this->db->queryF(
202 'SELECT obj_id, title FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
203 ['integer', 'integer'],
204 [$folder_id, $this->usr_id]
205 );
206 $row = $this->db->fetchAssoc($query);
207
208 if (!is_array($row) || array_key_exists($row['title'], $this->default_folders)) {
209 return false;
210 }
211
212 $mailer = new ilMail($this->usr_id);
213
214 $subtree = $this->mtree->getSubTree($this->mtree->getNodeData($folder_id));
215 $this->mtree->deleteTree($this->mtree->getNodeData($folder_id));
216
217 foreach ($subtree as $node) {
218 $node_id = (int) $node['obj_id'];
219
220 $mails = $mailer->getMailsOfFolder($node_id);
221
222 $mail_ids = [];
223 foreach ($mails as $mail) {
224 $mail_ids[] = (int) $mail['mail_id'];
225 }
226
227 $mailer->deleteMails($mail_ids);
228
229 $this->db->manipulateF(
230 'DELETE FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
231 ['integer', 'integer'],
232 [$node_id, $this->usr_id]
233 );
234 }
235
236 return true;
237 }

References ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ folderNameExists()

ilMailbox::folderNameExists ( string  $name)
protected

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

184 : bool
185 {
186 $res = $this->db->queryF(
187 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
188 ['integer', 'text'],
189 [$this->usr_id, $name]
190 );
191 $row = $this->db->fetchAssoc($res);
192
193 return is_array($row) && $row['obj_id'] > 0;
194 }
$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 86 of file class.ilMailbox.php.

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

References $res.

◆ getFolderData()

ilMailbox::getFolderData ( int  $folder_id)

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

240 {
241 $res = $this->db->queryF(
242 'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND obj_id = %s',
243 ['integer', 'integer'],
244 [$this->usr_id, $folder_id]
245 );
246 $row = $this->db->fetchAssoc($res);
247
248 if (is_array($row)) {
249 return $this->getFolderDataFromRow($row);
250 }
251
252 return null;
253 }
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 255 of file class.ilMailbox.php.

256 {
257 return new MailFolderData(
258 (int) $row['obj_id'],
259 (int) $row['user_id'],
260 MailFolderType::from($row['m_type']),
261 (string) ($row['m_type'] === MailFolderType::USER->value
262 ? $row['title']
263 : $this->lng->txt('mail_' . $row['title']))
264 );
265 }

References ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), ILIAS\Repository\lng(), and ILIAS\Mail\Folder\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 73 of file class.ilMailbox.php.

73 : int
74 {
75 $res = $this->db->queryF(
76 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
77 ['integer', 'text'],
78 [$this->usr_id, 'inbox']
79 );
80
81 $row = $this->db->fetchAssoc($res);
82
83 return (int) $row['obj_id'];
84 }

References $res.

◆ getParentFolderId()

ilMailbox::getParentFolderId ( int  $folder_id)

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

267 : int
268 {
269 $res = $this->db->queryF(
270 'SELECT * FROM ' . $this->table_tree . ' WHERE child = %s AND tree = %s',
271 ['integer', 'integer'],
272 [$folder_id, $this->usr_id]
273 );
274 $row = $this->db->fetchAssoc($res);
275
276 return is_array($row) ? (int) $row['parent'] : 0;
277 }

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

+ Here is the call graph for this function:

◆ getRooFolder()

ilMailbox::getRooFolder ( )

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

60 : int
61 {
62 $res = $this->db->queryF(
63 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
64 ['integer', 'text'],
65 [$this->usr_id, 'root']
66 );
67
68 $row = $this->db->fetchAssoc($res);
69
70 return (int) $row['obj_id'];
71 }

References $res.

◆ getSentFolder()

ilMailbox::getSentFolder ( )

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

112 : int
113 {
114 $res = $this->db->queryF(
115 'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
116 ['integer', 'text'],
117 [$this->usr_id, 'sent']
118 );
119
120 $row = $this->db->fetchAssoc($res);
121
122 return (int) $row['obj_id'];
123 }

References $res.

◆ getSubFolders()

ilMailbox::getSubFolders ( )
Returns
list<MailFolderData>

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

282 : array
283 {
284 $user_folders = [];
285
286 foreach (array_keys($this->default_folders) as $key) {
287 $res = $this->db->queryF(
288 'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
289 ['integer', 'text'],
290 [$this->usr_id, $key]
291 );
292 $row = $this->db->fetchAssoc($res);
293 if (is_array($row)) {
294 $user_folders[] = $this->getFolderDataFromRow($row);
295 }
296 }
297
298 $query = implode(' ', [
299 'SELECT * FROM ' . $this->table_tree . ', ' . $this->table_mail_obj_data,
300 'WHERE ' . $this->table_mail_obj_data . '.obj_id = ' . $this->table_tree . '.child',
301 'AND ' . $this->table_tree . '.depth > %s',
302 'AND ' . $this->table_tree . '.tree = %s',
303 'ORDER BY ' . $this->table_tree . '.lft, ' . $this->table_mail_obj_data . '.title',
304 ]);
305 $res = $this->db->queryF(
306 $query,
307 ['integer', 'integer'],
308 [2, $this->usr_id]
309 );
310 while ($row = $this->db->fetchAssoc($res)) {
311 $user_folders[] = $this->getFolderDataFromRow($row);
312 }
313
314 return $user_folders;
315 }

References $res, and getFolderDataFromRow().

+ Here is the call graph for this function:

◆ getTrashFolder()

ilMailbox::getTrashFolder ( )

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

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

References $res.

◆ getUsrId()

ilMailbox::getUsrId ( )

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

322 : int
323 {
324 return $this->usr_id;
325 }

◆ isOwnedFolder()

ilMailbox::isOwnedFolder ( int  $folder_id)

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

385 : bool
386 {
387 $folder_data = $this->getFolderData($folder_id);
388
389 return $folder_data?->getFolderId() === $folder_id;
390 }
getFolderData(int $folder_id)

References getFolderData().

+ Here is the call graph for this function:

◆ renameFolder()

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

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

169 : bool
170 {
171 if ($this->folderNameExists($name)) {
172 return false;
173 }
174
175 $this->db->manipulateF(
176 'UPDATE ' . $this->table_mail_obj_data . ' SET title = %s WHERE obj_id = %s AND user_id = %s',
177 ['text', 'integer', 'integer'],
178 [$name, $folder_id, $this->usr_id]
179 );
180
181 return true;
182 }

References folderNameExists().

+ Here is the call graph for this function:

◆ setUsrId()

ilMailbox::setUsrId ( int  $usr_id)

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

317 : void
318 {
319 $this->usr_id = $usr_id;
320 }

◆ 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 376 of file class.ilMailbox.php.

376 : void
377 {
378 $this->db->manipulateF(
379 'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
380 ['integer', 'text', 'integer'],
381 [0, $name_to_show, $this->usr_id]
382 );
383 }

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_sent' => 'sent',
'z_local' => 'local',
]

Definition at line 31 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 38 of file class.ilMailbox.php.

◆ $table_tree

readonly string ilMailbox::$table_tree
private

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


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