ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilMailbox Class Reference

Mail Box class Base class for creating and handling mail boxes. More...

+ Collaboration diagram for ilMailbox:

Public Member Functions

 __construct (protected int $usrId)
 
 getRooFolder ()
 
 getInboxFolder ()
 
 getDraftsFolder ()
 
 getTrashFolder ()
 
 getSentFolder ()
 
 getActions (int $folderId)
 
 createDefaultFolder ()
 Creates all default folders for a user. More...
 
 addFolder (int $parentFolderId, string $name)
 
 renameFolder (int $folderId, string $name)
 
 deleteFolder (int $folderId)
 
 getFolderData (int $folderId)
 
 getParentFolderId (int $folderId)
 
 getSubFolders ()
 
 setUsrId (int $usrId)
 
 getUsrId ()
 
 delete ()
 
 updateMailsOfDeletedUser (string $nameToShow)
 Update existing mails. More...
 
 isOwnedFolder (int $folderId)
 

Protected Member Functions

 folderNameExists (string $name)
 

Protected Attributes

ilLanguage $lng
 
ilDBInterface $db
 
ilTree $mtree
 
array $actions
 
array $defaultFolders
 
array string $table_mail_obj_data
 
string $table_tree
 

Detailed Description

Mail Box class Base class for creating and handling mail boxes.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

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

Constructor & Destructor Documentation

◆ __construct()

ilMailbox::__construct ( protected int  $usrId)

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

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

53  {
54  global $DIC;
55 
56  if ($usrId < 1) {
57  throw new InvalidArgumentException("Cannot create mailbox without user id");
58  }
59 
60  $this->lng = $DIC->language();
61  $this->db = $DIC->database();
62  $this->table_mail_obj_data = 'mail_obj_data';
63  $this->table_tree = 'mail_tree';
64 
65  $this->mtree = new ilTree($this->usrId);
66  $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
67 
68  // i added this, becaus if i create a new user automatically during
69  // CAS authentication, we have no $lng variable (alex, 16.6.2006)
70  // (alternative: make createDefaultFolder call static in ilObjUser->saveAsNew())
71  if (is_object($this->lng)) {
72  $this->lng->loadLanguageModule("mail");
73 
74  $this->actions = [
75  'moveMails' => $this->lng->txt('mail_move_to'),
76  'markMailsRead' => $this->lng->txt('mail_mark_read'),
77  'markMailsUnread' => $this->lng->txt('mail_mark_unread'),
78  'deleteMails' => $this->lng->txt('delete'),
79  ];
80  }
81  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addFolder()

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

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

References folderNameExists().

182  : int
183  {
184  if ($this->folderNameExists($name)) {
185  return 0;
186  }
187 
188  $nextId = $this->db->nextId($this->table_mail_obj_data);
189  $this->db->manipulateF(
190  'INSERT INTO ' . $this->table_mail_obj_data .
191  ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
192  ['integer', 'integer', 'text', 'text'],
193  [$nextId, $this->usrId, $name, 'user_folder']
194  );
195  $this->mtree->insertNode($nextId, $parentFolderId);
196 
197  return $nextId;
198  }
folderNameExists(string $name)
+ 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 159 of file class.ilMailbox.php.

References ILIAS\LTI\ToolProvider\$key.

159  : void
160  {
161  $rootFolderId = $this->db->nextId($this->table_mail_obj_data);
162  $this->db->manipulateF(
163  'INSERT INTO ' . $this->table_mail_obj_data .
164  ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
165  ['integer', 'integer', 'text', 'text'],
166  [$rootFolderId, $this->usrId, 'a_root', 'root']
167  );
168  $this->mtree->addTree($this->usrId, $rootFolderId);
169 
170  foreach ($this->defaultFolders as $key => $folder) {
171  $last_id = $this->db->nextId($this->table_mail_obj_data);
172  $this->db->manipulateF(
173  'INSERT INTO ' . $this->table_mail_obj_data .
174  ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
175  ['integer', 'integer', 'text', 'text'],
176  [$last_id, $this->usrId, $key, $folder]
177  );
178  $this->mtree->insertNode($last_id, $rootFolderId);
179  }
180  }
string $key
Consumer key/client ID value.
Definition: System.php:193

◆ delete()

ilMailbox::delete ( )

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

357  : void
358  {
359  $this->db->manipulateF(
360  'DELETE FROM mail_obj_data WHERE user_id = %s',
361  ['integer'],
362  [$this->usrId]
363  );
364 
365  $this->db->manipulateF(
366  'DELETE FROM mail_options WHERE user_id = %s',
367  ['integer'],
368  [$this->usrId]
369  );
370 
371  $this->db->manipulateF(
372  'DELETE FROM mail_saved WHERE user_id = %s',
373  ['integer'],
374  [$this->usrId]
375  );
376 
377  $this->db->manipulateF(
378  'DELETE FROM mail_tree WHERE tree = %s',
379  ['integer'],
380  [$this->usrId]
381  );
382 
383  $this->db->manipulateF(
384  'DELETE FROM mail_auto_responder WHERE sender_id = %s OR receiver_id = %s',
385  ['integer', 'integer'],
386  [$this->usrId, $this->usrId]
387  );
388 
389  // Delete the user's files from filesystem:
390  // This has to be done before deleting the database entries in table 'mail'
391  $fdm = new ilFileDataMail($this->usrId);
392  $fdm->onUserDelete();
393 
394  // Delete mails of deleted user
395  $this->db->manipulateF(
396  'DELETE FROM mail WHERE user_id = %s',
397  ['integer'],
398  [$this->usrId]
399  );
400  }
This class handles all operations on files (attachments) in directory ilias_data/mail.

◆ deleteFolder()

ilMailbox::deleteFolder ( int  $folderId)
Exceptions
ilInvalidTreeStructureException

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

References ILIAS\Repository\int().

230  : bool
231  {
232  $query = $this->db->queryF(
233  'SELECT obj_id, title FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
234  ['integer', 'integer'],
235  [$folderId, $this->usrId]
236  );
237  $row = $this->db->fetchAssoc($query);
238 
239  if (!is_array($row) || array_key_exists($row['title'], $this->defaultFolders)) {
240  return false;
241  }
242 
243  $mailer = new ilMail($this->usrId);
244 
245  $subtree = $this->mtree->getSubTree($this->mtree->getNodeData($folderId));
246  $this->mtree->deleteTree($this->mtree->getNodeData($folderId));
247 
248  foreach ($subtree as $node) {
249  $nodeId = (int) $node['obj_id'];
250 
251  $mails = $mailer->getMailsOfFolder($nodeId);
252 
253  $mailIds = [];
254  foreach ($mails as $mail) {
255  $mailIds[] = (int) $mail['mail_id'];
256  }
257 
258  $mailer->deleteMails($mailIds);
259 
260  $this->db->manipulateF(
261  'DELETE FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
262  ['integer', 'integer'],
263  [$nodeId, $this->usrId]
264  );
265  }
266 
267  return true;
268  }
+ Here is the call graph for this function:

◆ folderNameExists()

ilMailbox::folderNameExists ( string  $name)
protected

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

References $res.

Referenced by addFolder(), and renameFolder().

215  : bool
216  {
217  $res = $this->db->queryF(
218  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
219  ['integer', 'text'],
220  [$this->usrId, $name]
221  );
222  $row = $this->db->fetchAssoc($res);
223 
224  return is_array($row) && $row['obj_id'] > 0;
225  }
$res
Definition: ltiservices.php:69
+ Here is the caller graph for this function:

◆ getActions()

ilMailbox::getActions ( int  $folderId)
Returns
array{moveMails: string, markMailsRead: string, markMailsUnread: string, deleteMails: string}

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

References $actions.

151  : array
152  {
153  return $this->actions;
154  }

◆ getDraftsFolder()

ilMailbox::getDraftsFolder ( )

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

References $res.

109  : int
110  {
111  $res = $this->db->queryF(
112  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
113  ['integer', 'text'],
114  [$this->usrId, 'drafts']
115  );
116 
117  $row = $this->db->fetchAssoc($res);
118 
119  return (int) $row['obj_id'];
120  }
$res
Definition: ltiservices.php:69

◆ getFolderData()

ilMailbox::getFolderData ( int  $folderId)
Returns
array{obj_id: int, title: string, type: string}|null

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

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

Referenced by isOwnedFolder().

273  : ?array
274  {
275  $res = $this->db->queryF(
276  'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND obj_id = %s',
277  ['integer', 'integer'],
278  [$this->usrId, $folderId]
279  );
280  $row = $this->db->fetchAssoc($res);
281 
282  if (is_array($row)) {
283  return [
284  'obj_id' => (int) $row['obj_id'],
285  'title' => (string) $row['title'],
286  'type' => (string) $row['m_type'],
287  ];
288  }
289 
290  return null;
291  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInboxFolder()

ilMailbox::getInboxFolder ( )

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

References $res.

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

◆ getParentFolderId()

ilMailbox::getParentFolderId ( int  $folderId)

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

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

293  : int
294  {
295  $res = $this->db->queryF(
296  'SELECT * FROM ' . $this->table_tree . ' WHERE child = %s AND tree = %s',
297  ['integer', 'integer'],
298  [$folderId, $this->usrId]
299  );
300  $row = $this->db->fetchAssoc($res);
301 
302  return is_array($row) ? (int) $row['parent'] : 0;
303  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ getRooFolder()

ilMailbox::getRooFolder ( )

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

References $res.

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

◆ getSentFolder()

ilMailbox::getSentFolder ( )

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

References $res.

135  : int
136  {
137  $res = $this->db->queryF(
138  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
139  ['integer', 'text'],
140  [$this->usrId, 'sent']
141  );
142 
143  $row = $this->db->fetchAssoc($res);
144 
145  return (int) $row['obj_id'];
146  }
$res
Definition: ltiservices.php:69

◆ getSubFolders()

ilMailbox::getSubFolders ( )

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

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

305  : array
306  {
307  $userFolders = [];
308 
309  foreach (array_keys($this->defaultFolders) as $key) {
310  $res = $this->db->queryF(
311  'SELECT obj_id, m_type FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
312  ['integer', 'text'],
313  [$this->usrId, $key]
314  );
315  $row = $this->db->fetchAssoc($res);
316 
317  $userFolders[] = [
318  'title' => $key,
319  'type' => (string) $row['m_type'],
320  'obj_id' => (int) $row['obj_id'],
321  ];
322  }
323 
324  $query = implode(' ', [
325  'SELECT * FROM ' . $this->table_tree . ', ' . $this->table_mail_obj_data,
326  'WHERE ' . $this->table_mail_obj_data . '.obj_id = ' . $this->table_tree . '.child',
327  'AND ' . $this->table_tree . '.depth > %s',
328  'AND ' . $this->table_tree . '.tree = %s',
329  'ORDER BY ' . $this->table_tree . '.lft, ' . $this->table_mail_obj_data . '.title',
330  ]);
331  $res = $this->db->queryF(
332  $query,
333  ['integer', 'integer'],
334  [2, $this->usrId]
335  );
336  while ($row = $this->db->fetchAssoc($res)) {
337  $userFolders[] = [
338  'title' => (string) $row['title'],
339  'type' => (string) $row['m_type'],
340  'obj_id' => (int) $row['child'],
341  ];
342  }
343 
344  return $userFolders;
345  }
$res
Definition: ltiservices.php:69
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ getTrashFolder()

ilMailbox::getTrashFolder ( )

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

References $res.

122  : int
123  {
124  $res = $this->db->queryF(
125  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
126  ['integer', 'text'],
127  [$this->usrId, 'trash']
128  );
129 
130  $row = $this->db->fetchAssoc($res);
131 
132  return (int) $row['obj_id'];
133  }
$res
Definition: ltiservices.php:69

◆ getUsrId()

ilMailbox::getUsrId ( )

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

352  : int
353  {
354  return $this->usrId;
355  }

◆ isOwnedFolder()

ilMailbox::isOwnedFolder ( int  $folderId)

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

References getFolderData(), and ILIAS\Repository\int().

415  : bool
416  {
417  $folderData = $this->getFolderData($folderId);
418 
419  return $folderData !== null && (int) $folderData['obj_id'] === $folderId;
420  }
getFolderData(int $folderId)
+ Here is the call graph for this function:

◆ renameFolder()

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

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

References folderNameExists().

200  : bool
201  {
202  if ($this->folderNameExists($name)) {
203  return false;
204  }
205 
206  $this->db->manipulateF(
207  'UPDATE ' . $this->table_mail_obj_data . ' SET title = %s WHERE obj_id = %s AND user_id = %s',
208  ['text', 'integer', 'integer'],
209  [$name, $folderId, $this->usrId]
210  );
211 
212  return true;
213  }
folderNameExists(string $name)
+ Here is the call graph for this function:

◆ setUsrId()

ilMailbox::setUsrId ( int  $usrId)

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

347  : void
348  {
349  $this->usrId = $usrId;
350  }

◆ updateMailsOfDeletedUser()

ilMailbox::updateMailsOfDeletedUser ( string  $nameToShow)

Update existing mails.

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

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

406  : void
407  {
408  $this->db->manipulateF(
409  'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
410  ['integer', 'text', 'integer'],
411  [0, $nameToShow, $this->usrId]
412  );
413  }

Field Documentation

◆ $actions

array ilMailbox::$actions
protected
Initial value:
= [
'moveMails' => ''

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

Referenced by getActions().

◆ $db

ilDBInterface ilMailbox::$db
protected

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

◆ $defaultFolders

array ilMailbox::$defaultFolders
protected
Initial value:
= [
'b_inbox' => 'inbox'

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

◆ $lng

ilLanguage ilMailbox::$lng
protected

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

◆ $mtree

ilTree ilMailbox::$mtree
protected

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

◆ $table_mail_obj_data

array string ilMailbox::$table_mail_obj_data
protected
Initial value:
=> 'trash',
'd_drafts' => 'drafts',
'e_sent' => 'sent',
'z_local' => 'local',
]

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

◆ $table_tree

string ilMailbox::$table_tree
protected

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


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