ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ($a_user_id=0)
 ilMailbox constructor. More...
 
 getInboxFolder ()
 
 getDraftsFolder ()
 
 getTrashFolder ()
 
 getSentFolder ()
 
 getActions ($folderId)
 
 createDefaultFolder ()
 Creates all default folders for a user. More...
 
 addFolder (int $parentFolderId, string $name)
 
 renameFolder (int $folderId, string $name)
 
 deleteFolder ($folderId)
 
 getFolderData ($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

 $lng
 
 $db
 
 $mtree
 
 $usrId
 
 $actions = []
 
 $defaultFolders = []
 
 $table_mail_obj_data
 
 $table_tree
 

Private Member Functions

 getRootFolderId ()
 

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

Constructor & Destructor Documentation

◆ __construct()

ilMailbox::__construct (   $a_user_id = 0)

ilMailbox constructor.

Parameters
int$a_user_id

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

References $DIC.

43  {
44  global $DIC;
45 
46  $this->lng = $DIC->language();
47  $this->db = $DIC->database();
48 
49  $this->usrId = (int) $a_user_id;
50  $this->table_mail_obj_data = 'mail_obj_data';
51  $this->table_tree = 'mail_tree';
52 
53  if ($this->usrId) {
54  $this->mtree = new ilTree($this->usrId);
55  $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
56  }
57 
58  // i added this, becaus if i create a new user automatically during
59  // CAS authentication, we have no $lng variable (alex, 16.6.2006)
60  // (alternative: make createDefaultFolder call static in ilObjUser->saveAsNew())
61  if (is_object($this->lng)) {
62  $this->lng->loadLanguageModule("mail");
63 
64  $this->actions = [
65  'moveMails' => $this->lng->txt('mail_move_to'),
66  'markMailsRead' => $this->lng->txt('mail_mark_read'),
67  'markMailsUnread' => $this->lng->txt('mail_mark_unread'),
68  'deleteMails' => $this->lng->txt('delete')
69  ];
70  }
71 
72  // array contains basic folders and there lng translation for every new user
73  $this->defaultFolders = [
74  'b_inbox' => 'inbox',
75  'c_trash' => 'trash',
76  'd_drafts' => 'drafts',
77  'e_sent' => 'sent',
78  'z_local' => 'local'
79  ];
80  }
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ addFolder()

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

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

References folderNameExists().

199  : int
200  {
201  if ($this->folderNameExists($name)) {
202  return 0;
203  }
204 
205  $nextId = (int) $this->db->nextId($this->table_mail_obj_data);
206  $this->db->manipulateF(
207  'INSERT INTO ' . $this->table_mail_obj_data . ' (obj_id, user_id, title, m_type) VALUES(%s,%s,%s,%s)',
208  ['integer', 'integer', 'text', 'text'],
209  [$nextId, $this->usrId, $name, 'user_folder']
210  );
211  $this->mtree->insertNode($nextId, $parentFolderId);
212 
213  return $nextId;
214  }
if($format !==null) $name
Definition: metadata.php:230
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 173 of file class.ilMailbox.php.

173  : void
174  {
175  $rootFolderId = (int) $this->db->nextId($this->table_mail_obj_data);
176  $this->db->manipulateF(
177  'INSERT INTO ' . $this->table_mail_obj_data . ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
178  ['integer', 'integer', 'text', 'text'],
179  [$rootFolderId, $this->usrId, 'a_root', 'root']
180  );
181  $this->mtree->addTree($this->usrId, $rootFolderId);
182 
183  foreach ($this->defaultFolders as $key => $folder) {
184  $last_id = $this->db->nextId($this->table_mail_obj_data);
185  $this->db->manipulateF(
186  'INSERT INTO ' . $this->table_mail_obj_data . ' (obj_id, user_id, title, m_type) VALUES(%s, %s, %s, %s)',
187  ['integer', 'integer', 'text', 'text'],
188  [$last_id, $this->usrId, $key, $folder]
189  );
190  $this->mtree->insertNode($last_id, $rootFolderId);
191  }
192  }

◆ delete()

ilMailbox::delete ( )

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

397  : void
398  {
399  $this->db->manipulateF(
400  'DELETE FROM mail_obj_data WHERE user_id = %s',
401  ['integer'],
402  [$this->usrId]
403  );
404 
405  $this->db->manipulateF(
406  'DELETE FROM mail_options WHERE user_id = %s',
407  ['integer'],
408  [$this->usrId]
409  );
410 
411  $this->db->manipulateF(
412  'DELETE FROM mail_saved WHERE user_id = %s',
413  ['integer'],
414  [$this->usrId]
415  );
416 
417  $this->db->manipulateF(
418  'DELETE FROM mail_tree WHERE tree = %s',
419  ['integer'],
420  [$this->usrId]
421  );
422 
423  // Delete the user's files from filesystem: This has to be done before deleting the database entries in table 'mail'
424  $fdm = new ilFileDataMail($this->usrId);
425  $fdm->onUserDelete();
426 
427  // Delete mails of deleted user
428  $this->db->manipulateF(
429  'DELETE FROM mail WHERE user_id = %s',
430  ['integer'],
431  [$this->usrId]
432  );
433  }
Class ilFileDataMail.

◆ deleteFolder()

ilMailbox::deleteFolder (   $folderId)
Parameters
int$folderId
Returns
bool
Exceptions
ilInvalidTreeStructureException

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

References $query.

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

◆ folderNameExists()

ilMailbox::folderNameExists ( string  $name)
protected
Parameters
$name
Returns
bool

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

References $res.

Referenced by addFolder(), and renameFolder().

240  : bool
241  {
242  $res = $this->db->queryF(
243  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
244  ['integer', 'text'],
245  [$this->usrId, $name]
246  );
247  $row = $this->db->fetchAssoc($res);
248 
249  return is_array($row) && $row['obj_id'] > 0 ? true : false;
250  }
if($format !==null) $name
Definition: metadata.php:230
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ getActions()

ilMailbox::getActions (   $folderId)
Parameters
int$folderId
Returns
array

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

References $actions, and getFolderData().

158  : array
159  {
160  if ($folderId) {
161  $folder_data = $this->getFolderData($folderId);
162  if ($folder_data['type'] === 'user_folder' || $folder_data['type'] === 'local') {
163  return $this->actions;
164  }
165  }
166 
167  return $this->actions;
168  }
getFolderData($folderId)
+ Here is the call graph for this function:

◆ getDraftsFolder()

ilMailbox::getDraftsFolder ( )
Returns
int

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

References $res.

101  : int
102  {
103  $res = $this->db->queryF(
104  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
105  ['integer', 'text'],
106  [$this->usrId, 'drafts']
107  );
108 
109  $row = $this->db->fetchAssoc($res);
110 
111  return (int) $row['obj_id'];
112  }
foreach($_POST as $key=> $value) $res

◆ getFolderData()

ilMailbox::getFolderData (   $folderId)
Parameters
$folderId
Returns
array

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

References $res.

Referenced by getActions(), and isOwnedFolder().

301  : array
302  {
303  $res = $this->db->queryF(
304  'SELECT * FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND obj_id = %s',
305  ['integer', 'integer'],
306  [$this->usrId, $folderId]
307  );
308  $row = $this->db->fetchAssoc($res);
309 
310  return [
311  'obj_id' => (int) $row['obj_id'],
312  'title' => (string) $row['title'],
313  'type' => (string) $row['m_type'],
314  ];
315  }
foreach($_POST as $key=> $value) $res
+ Here is the caller graph for this function:

◆ getInboxFolder()

ilMailbox::getInboxFolder ( )
Returns
int

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

References $res.

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

◆ getParentFolderId()

ilMailbox::getParentFolderId ( int  $folderId)
Parameters
int$folderId
Returns
int

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

References $res.

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

◆ getRootFolderId()

ilMailbox::getRootFolderId ( )
private
Returns
int

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

149  : int
150  {
151  return (int) $this->mtree->getRootId();
152  }

◆ getSentFolder()

ilMailbox::getSentFolder ( )
Returns
int

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

References $res.

133  : int
134  {
135  $res = $this->db->queryF(
136  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
137  ['integer', 'text'],
138  [$this->usrId, 'sent']
139  );
140 
141  $row = $this->db->fetchAssoc($res);
142 
143  return (int) $row['obj_id'];
144  }
foreach($_POST as $key=> $value) $res

◆ getSubFolders()

ilMailbox::getSubFolders ( )
Returns
array

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

References $query, and $res.

336  : array
337  {
338  $userFolders = [];
339 
340  foreach ($this->defaultFolders as $key => $value) {
341  $res = $this->db->queryF(
342  'SELECT obj_id, m_type FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND title = %s',
343  ['integer', 'text'],
344  [$this->usrId, $key]
345  );
346  $row = $this->db->fetchAssoc($res);
347 
348  $userFolders[] = [
349  'title' => (string) $key,
350  'type' => (string) $row['m_type'],
351  'obj_id' => (int) $row['obj_id'],
352  ];
353  }
354 
355  $query = implode(' ', [
356  'SELECT * FROM ' . $this->table_tree . ', ' . $this->table_mail_obj_data,
357  'WHERE ' . $this->table_mail_obj_data . '.obj_id = ' . $this->table_tree . '.child',
358  'AND ' . $this->table_tree . '.depth > %s',
359  'AND ' . $this->table_tree . '.tree = %s',
360  'ORDER BY ' . $this->table_tree . '.lft, ' . $this->table_mail_obj_data . '.title'
361  ]);
362  $res = $this->db->queryF(
363  $query,
364  ['integer', 'integer'],
365  [2, $this->usrId]
366  );
367  while ($row = $this->db->fetchAssoc($res)) {
368  $userFolders[] = [
369  'title' => (string) $row['title'],
370  'type' => (string) $row['m_type'],
371  'obj_id' => (int) $row['child'],
372  ];
373  }
374 
375  return $userFolders;
376  }
foreach($_POST as $key=> $value) $res
$query

◆ getTrashFolder()

ilMailbox::getTrashFolder ( )
Returns
int

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

References $res.

117  : int
118  {
119  $res = $this->db->queryF(
120  'SELECT obj_id FROM ' . $this->table_mail_obj_data . ' WHERE user_id = %s AND m_type = %s',
121  ['integer', 'text'],
122  [$this->usrId, 'trash']
123  );
124 
125  $row = $this->db->fetchAssoc($res);
126 
127  return (int) $row['obj_id'];
128  }
foreach($_POST as $key=> $value) $res

◆ getUsrId()

ilMailbox::getUsrId ( )
Returns
int

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

References $usrId.

389  : int
390  {
391  return (int) $this->usrId;
392  }

◆ isOwnedFolder()

ilMailbox::isOwnedFolder ( int  $folderId)
Parameters
int$folderId
Returns
bool

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

References getFolderData().

453  : bool
454  {
455  $folderData = $this->getFolderData($folderId);
456 
457  return (int) $folderData['obj_id'] === $folderId;
458  }
getFolderData($folderId)
+ Here is the call graph for this function:

◆ renameFolder()

ilMailbox::renameFolder ( int  $folderId,
string  $name 
)
Parameters
int$folderId
string$name
Returns
bool

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

References folderNameExists().

221  : bool
222  {
223  if ($this->folderNameExists($name)) {
224  return false;
225  }
226 
227  $this->db->manipulateF(
228  'UPDATE ' . $this->table_mail_obj_data . ' SET title = %s WHERE obj_id = %s AND user_id = %s',
229  ['text', 'integer', 'integer'],
230  [$name, $folderId, $this->usrId]
231  );
232 
233  return true;
234  }
if($format !==null) $name
Definition: metadata.php:230
folderNameExists(string $name)
+ Here is the call graph for this function:

◆ setUsrId()

ilMailbox::setUsrId ( int  $usrId)
Parameters
int$usrId

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

References $usrId.

381  : void
382  {
383  $this->usrId = $usrId;
384  }

◆ 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.

Parameters
string$nameToShow

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

440  : void
441  {
442  $this->db->manipulateF(
443  'UPDATE mail SET sender_id = %s, import_name = %s WHERE sender_id = %s',
444  ['integer', 'text', 'integer'],
445  [0, $nameToShow, $this->usrId]
446  );
447  }

Field Documentation

◆ $actions

ilMailbox::$actions = []
protected

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

Referenced by getActions().

◆ $db

ilMailbox::$db
protected

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

◆ $defaultFolders

ilMailbox::$defaultFolders = []
protected

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

◆ $lng

ilMailbox::$lng
protected

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

◆ $mtree

ilMailbox::$mtree
protected

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

◆ $table_mail_obj_data

ilMailbox::$table_mail_obj_data
protected

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

◆ $table_tree

ilMailbox::$table_tree
protected

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

◆ $usrId

ilMailbox::$usrId
protected

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

Referenced by getUsrId(), and setUsrId().


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