ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ()
 
 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)
 

Private Member Functions

 getFolderDataFromRow (array $row)
 

Private Attributes

ilLanguage $lng
 
ilDBInterface $db
 
ilTree $mtree
 
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 32 of file class.ilMailbox.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailbox::__construct ( protected int  $usrId)

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

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

50  {
51  global $DIC;
52 
53  if ($usrId < 1) {
54  throw new InvalidArgumentException('Cannot create mailbox without user id');
55  }
56 
57  $this->lng = $DIC->language();
58  $this->db = $DIC->database();
59  $this->table_mail_obj_data = 'mail_obj_data';
60  $this->table_tree = 'mail_tree';
61 
62  $this->mtree = new ilTree($this->usrId);
63  $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
64 
65  $this->lng->loadLanguageModule('mail');
66  }
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ addFolder()

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

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

References folderNameExists().

159  : int
160  {
161  if ($this->folderNameExists($name)) {
162  return 0;
163  }
164 
165  $nextId = $this->db->nextId($this->table_mail_obj_data);
166  $this->db->manipulateF(
167  'INSERT INTO ' . $this->table_mail_obj_data .
168  ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
169  ['integer', 'integer', 'text', 'text'],
170  [$nextId, $this->usrId, $name, 'user_folder']
171  );
172  $this->mtree->insertNode($nextId, $parentFolderId);
173 
174  return $nextId;
175  }
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 136 of file class.ilMailbox.php.

136  : void
137  {
138  $rootFolderId = $this->db->nextId($this->table_mail_obj_data);
139  $this->db->manipulateF(
140  'INSERT INTO ' . $this->table_mail_obj_data .
141  ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
142  ['integer', 'integer', 'text', 'text'],
143  [$rootFolderId, $this->usrId, 'a_root', 'root']
144  );
145  $this->mtree->addTree($this->usrId, $rootFolderId);
146 
147  foreach ($this->defaultFolders as $key => $folder) {
148  $last_id = $this->db->nextId($this->table_mail_obj_data);
149  $this->db->manipulateF(
150  'INSERT INTO ' . $this->table_mail_obj_data .
151  ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
152  ['integer', 'integer', 'text', 'text'],
153  [$last_id, $this->usrId, $key, $folder]
154  );
155  $this->mtree->insertNode($last_id, $rootFolderId);
156  }
157  }

◆ delete()

ilMailbox::delete ( )

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

335  : void
336  {
337  $this->db->manipulateF(
338  'DELETE FROM mail_obj_data WHERE user_id = %s',
339  ['integer'],
340  [$this->usrId]
341  );
342 
343  $this->db->manipulateF(
344  'DELETE FROM mail_options WHERE user_id = %s',
345  ['integer'],
346  [$this->usrId]
347  );
348 
349  $this->db->manipulateF(
350  'DELETE FROM mail_saved WHERE user_id = %s',
351  ['integer'],
352  [$this->usrId]
353  );
354 
355  $this->db->manipulateF(
356  'DELETE FROM mail_tree WHERE tree = %s',
357  ['integer'],
358  [$this->usrId]
359  );
360 
361  $this->db->manipulateF(
362  'DELETE FROM mail_auto_responder WHERE sender_id = %s OR receiver_id = %s',
363  ['integer', 'integer'],
364  [$this->usrId, $this->usrId]
365  );
366 
367  // Delete the user's files from filesystem:
368  // This has to be done before deleting the database entries in table 'mail'
369  $fdm = new ilFileDataMail($this->usrId);
370  $fdm->onUserDelete();
371 
372  // Delete mails of deleted user
373  $this->db->manipulateF(
374  'DELETE FROM mail WHERE user_id = %s',
375  ['integer'],
376  [$this->usrId]
377  );
378  }
This class handles all operations on files (attachments) in directory ilias_data/mail.

◆ deleteFolder()

ilMailbox::deleteFolder ( int  $folderId)
Exceptions
ilInvalidTreeStructureException

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

References ILIAS\Repository\int().

207  : bool
208  {
209  $query = $this->db->queryF(
210  'SELECT obj_id, title FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
211  ['integer', 'integer'],
212  [$folderId, $this->usrId]
213  );
214  $row = $this->db->fetchAssoc($query);
215 
216  if (!is_array($row) || array_key_exists($row['title'], $this->defaultFolders)) {
217  return false;
218  }
219 
220  $mailer = new ilMail($this->usrId);
221 
222  $subtree = $this->mtree->getSubTree($this->mtree->getNodeData($folderId));
223  $this->mtree->deleteTree($this->mtree->getNodeData($folderId));
224 
225  foreach ($subtree as $node) {
226  $nodeId = (int) $node['obj_id'];
227 
228  $mails = $mailer->getMailsOfFolder($nodeId);
229 
230  $mailIds = [];
231  foreach ($mails as $mail) {
232  $mailIds[] = (int) $mail['mail_id'];
233  }
234 
235  $mailer->deleteMails($mailIds);
236 
237  $this->db->manipulateF(
238  'DELETE FROM ' . $this->table_mail_obj_data . ' WHERE obj_id = %s AND user_id = %s',
239  ['integer', 'integer'],
240  [$nodeId, $this->usrId]
241  );
242  }
243 
244  return true;
245  }
+ Here is the call graph for this function:

◆ folderNameExists()

ilMailbox::folderNameExists ( string  $name)
protected

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

References $res.

Referenced by addFolder(), and renameFolder().

192  : bool
193  {
194  $res = $this->db->queryF(
195  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
196  ['integer', 'text'],
197  [$this->usrId, $name]
198  );
199  $row = $this->db->fetchAssoc($res);
200 
201  return is_array($row) && $row['obj_id'] > 0;
202  }
$res
Definition: ltiservices.php:66
+ Here is the caller graph for this function:

◆ getDraftsFolder()

ilMailbox::getDraftsFolder ( )

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

References $res.

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

◆ getFolderData()

ilMailbox::getFolderData ( int  $folderId)

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

References $res, getFolderDataFromRow(), and null.

Referenced by isOwnedFolder().

247  : ?MailFolderData
248  {
249  $res = $this->db->queryF(
250  'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND obj_id = %s',
251  ['integer', 'integer'],
252  [$this->usrId, $folderId]
253  );
254  $row = $this->db->fetchAssoc($res);
255 
256  if (is_array($row)) {
257  return $this->getFolderDataFromRow($row);
258  }
259 
260  return null;
261  }
$res
Definition: ltiservices.php:66
getFolderDataFromRow(array $row)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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 263 of file class.ilMailbox.php.

References ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), ILIAS\Repository\lng(), and ILIAS\Mail\Folder\USER.

Referenced by getFolderData(), and getSubFolders().

264  {
265  return new MailFolderData(
266  (int) $row['obj_id'],
267  (int) $row['user_id'],
268  MailFolderType::from($row['m_type']),
269  (string) ($row['m_type'] === MailFolderType::USER->value
270  ? $row['title']
271  : $this->lng->txt('mail_' . $row['title']))
272  );
273  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInboxFolder()

ilMailbox::getInboxFolder ( )

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

References $res.

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

◆ getParentFolderId()

ilMailbox::getParentFolderId ( int  $folderId)

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

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

275  : int
276  {
277  $res = $this->db->queryF(
278  'SELECT * FROM ' . $this->table_tree . ' WHERE child = %s AND tree = %s',
279  ['integer', 'integer'],
280  [$folderId, $this->usrId]
281  );
282  $row = $this->db->fetchAssoc($res);
283 
284  return is_array($row) ? (int) $row['parent'] : 0;
285  }
$res
Definition: ltiservices.php:66
+ Here is the call graph for this function:

◆ getRooFolder()

ilMailbox::getRooFolder ( )

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

References $res.

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

◆ getSentFolder()

ilMailbox::getSentFolder ( )

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

References $res.

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

◆ getSubFolders()

ilMailbox::getSubFolders ( )
Returns
MailFolderData[]

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

References $res, and getFolderDataFromRow().

290  : array
291  {
292  $userFolders = [];
293 
294  foreach (array_keys($this->defaultFolders) as $key) {
295  $res = $this->db->queryF(
296  'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
297  ['integer', 'text'],
298  [$this->usrId, $key]
299  );
300  $row = $this->db->fetchAssoc($res);
301  if (is_array($row)) {
302  $userFolders[] = $this->getFolderDataFromRow($row);
303  }
304  }
305 
306  $query = implode(' ', [
307  'SELECT * FROM ' . $this->table_tree . ', ' . $this->table_mail_obj_data,
308  'WHERE ' . $this->table_mail_obj_data . '.obj_id = ' . $this->table_tree . '.child',
309  'AND ' . $this->table_tree . '.depth > %s',
310  'AND ' . $this->table_tree . '.tree = %s',
311  'ORDER BY ' . $this->table_tree . '.lft, ' . $this->table_mail_obj_data . '.title',
312  ]);
313  $res = $this->db->queryF(
314  $query,
315  ['integer', 'integer'],
316  [2, $this->usrId]
317  );
318  while ($row = $this->db->fetchAssoc($res)) {
319  $userFolders[] = $this->getFolderDataFromRow($row);
320  }
321 
322  return $userFolders;
323  }
$res
Definition: ltiservices.php:66
getFolderDataFromRow(array $row)
+ Here is the call graph for this function:

◆ getTrashFolder()

ilMailbox::getTrashFolder ( )

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

References $res.

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

◆ getUsrId()

ilMailbox::getUsrId ( )

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

330  : int
331  {
332  return $this->usrId;
333  }

◆ isOwnedFolder()

ilMailbox::isOwnedFolder ( int  $folderId)

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

References getFolderData().

393  : bool
394  {
395  $folder_data = $this->getFolderData($folderId);
396 
397  return $folder_data?->getFolderId() === $folderId;
398  }
getFolderData(int $folderId)
+ Here is the call graph for this function:

◆ renameFolder()

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

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

References folderNameExists().

177  : bool
178  {
179  if ($this->folderNameExists($name)) {
180  return false;
181  }
182 
183  $this->db->manipulateF(
184  'UPDATE ' . $this->table_mail_obj_data . ' SET title = %s WHERE obj_id = %s AND user_id = %s',
185  ['text', 'integer', 'integer'],
186  [$name, $folderId, $this->usrId]
187  );
188 
189  return true;
190  }
folderNameExists(string $name)
+ Here is the call graph for this function:

◆ setUsrId()

ilMailbox::setUsrId ( int  $usrId)

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

325  : void
326  {
327  $this->usrId = $usrId;
328  }

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

384  : void
385  {
386  $this->db->manipulateF(
387  'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
388  ['integer', 'text', 'integer'],
389  [0, $nameToShow, $this->usrId]
390  );
391  }

Field Documentation

◆ $db

ilDBInterface ilMailbox::$db
private

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

◆ $defaultFolders

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

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

◆ $lng

ilLanguage ilMailbox::$lng
private

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

◆ $mtree

ilTree ilMailbox::$mtree
private

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

◆ $table_mail_obj_data

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

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

◆ $table_tree

string ilMailbox::$table_tree
private

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


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