ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables 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 (int $a_user_id)
 
 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
 
int $usrId
 
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 ( int  $a_user_id)

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

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

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

References folderNameExists().

186  : int
187  {
188  if ($this->folderNameExists($name)) {
189  return 0;
190  }
191 
192  $nextId = $this->db->nextId($this->table_mail_obj_data);
193  $this->db->manipulateF(
194  'INSERT INTO ' . $this->table_mail_obj_data .
195  ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
196  ['integer', 'integer', 'text', 'text'],
197  [$nextId, $this->usrId, $name, 'user_folder']
198  );
199  $this->mtree->insertNode($nextId, $parentFolderId);
200 
201  return $nextId;
202  }
if($format !==null) $name
Definition: metadata.php:247
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 163 of file class.ilMailbox.php.

References ILIAS\LTI\ToolProvider\$key.

163  : void
164  {
165  $rootFolderId = $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  [$rootFolderId, $this->usrId, 'a_root', 'root']
171  );
172  $this->mtree->addTree($this->usrId, $rootFolderId);
173 
174  foreach ($this->defaultFolders as $key => $folder) {
175  $last_id = $this->db->nextId($this->table_mail_obj_data);
176  $this->db->manipulateF(
177  'INSERT INTO ' . $this->table_mail_obj_data .
178  ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
179  ['integer', 'integer', 'text', 'text'],
180  [$last_id, $this->usrId, $key, $folder]
181  );
182  $this->mtree->insertNode($last_id, $rootFolderId);
183  }
184  }
string $key
Consumer key/client ID value.
Definition: System.php:193

◆ delete()

ilMailbox::delete ( )

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

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

◆ deleteFolder()

ilMailbox::deleteFolder ( int  $folderId)
Exceptions
ilInvalidTreeStructureException

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

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

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

◆ folderNameExists()

ilMailbox::folderNameExists ( string  $name)
protected

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

References $res.

Referenced by addFolder(), and renameFolder().

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

◆ getActions()

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

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

References $actions.

155  : array
156  {
157  return $this->actions;
158  }

◆ getDraftsFolder()

ilMailbox::getDraftsFolder ( )

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

References $res.

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->usrId, 'drafts']
118  );
119 
120  $row = $this->db->fetchAssoc($res);
121 
122  return (int) $row['obj_id'];
123  }
$res
Definition: ltiservices.php:69

◆ getFolderData()

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

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

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

Referenced by isOwnedFolder().

277  : ?array
278  {
279  $res = $this->db->queryF(
280  'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND obj_id = %s',
281  ['integer', 'integer'],
282  [$this->usrId, $folderId]
283  );
284  $row = $this->db->fetchAssoc($res);
285 
286  if (is_array($row)) {
287  return [
288  'obj_id' => (int) $row['obj_id'],
289  'title' => (string) $row['title'],
290  'type' => (string) $row['m_type'],
291  ];
292  }
293 
294  return null;
295  }
$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 99 of file class.ilMailbox.php.

References $res.

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->usrId, 'inbox']
105  );
106 
107  $row = $this->db->fetchAssoc($res);
108 
109  return (int) $row['obj_id'];
110  }
$res
Definition: ltiservices.php:69

◆ getParentFolderId()

ilMailbox::getParentFolderId ( int  $folderId)

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

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

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

◆ getRooFolder()

ilMailbox::getRooFolder ( )

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

References $res.

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->usrId, 'root']
92  );
93 
94  $row = $this->db->fetchAssoc($res);
95 
96  return (int) $row['obj_id'];
97  }
$res
Definition: ltiservices.php:69

◆ getSentFolder()

ilMailbox::getSentFolder ( )

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

References $res.

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

◆ getSubFolders()

ilMailbox::getSubFolders ( )

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

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

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

◆ getTrashFolder()

ilMailbox::getTrashFolder ( )

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

References $res.

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

◆ getUsrId()

ilMailbox::getUsrId ( )

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

References $usrId.

356  : int
357  {
358  return $this->usrId;
359  }

◆ isOwnedFolder()

ilMailbox::isOwnedFolder ( int  $folderId)

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

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

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

◆ renameFolder()

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

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

References folderNameExists().

204  : bool
205  {
206  if ($this->folderNameExists($name)) {
207  return false;
208  }
209 
210  $this->db->manipulateF(
211  'UPDATE ' . $this->table_mail_obj_data . ' SET title = %s WHERE obj_id = %s AND user_id = %s',
212  ['text', 'integer', 'integer'],
213  [$name, $folderId, $this->usrId]
214  );
215 
216  return true;
217  }
if($format !==null) $name
Definition: metadata.php:247
folderNameExists(string $name)
+ Here is the call graph for this function:

◆ setUsrId()

ilMailbox::setUsrId ( int  $usrId)

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

References $usrId.

Referenced by ilMail\sendChanneledMails().

351  : void
352  {
353  $this->usrId = $usrId;
354  }
+ Here is the caller graph for this function:

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

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

Field Documentation

◆ $actions

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

Definition at line 36 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 43 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 45 of file class.ilMailbox.php.

◆ $table_tree

string ilMailbox::$table_tree
protected

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

◆ $usrId

int ilMailbox::$usrId
protected

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

Referenced by getUsrId(), and setUsrId().


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