ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 ()
 get Id of the inbox folder of an user More...
 
 getDraftsFolder ()
 get Id of the inbox folder of an user More...
 
 getTrashFolder ()
 get Id of the trash folder of an user More...
 
 getSentFolder ()
 get Id of the sent folder of an user More...
 
 getRootFolderId ()
 get Id of the root folder of an user More...
 
 getActions ($a_mobj_id)
 get all possible actions if no mobj_id is given or folder specific actions if mobj_id is given More...
 
 createDefaultFolder ()
 Creates all default folders for a user. More...
 
 addFolder ($a_parent_id, $a_folder_name)
 Adds a new mail folder with the passed name under the given parent folder. More...
 
 renameFolder ($a_obj_id, $a_new_folder_name)
 Rename a folder and check if the name already exists. More...
 
 deleteFolder ($a_folder_id)
 
 getFolderData ($a_obj_id)
 Fetches the data of a specific folder. More...
 
 getParentFolderId ($a_obj_id)
 Get id of parent folder. More...
 
 getSubFolders ($a_folder=0, $a_folder_parent=0)
 Get all folders under a given folder/node id. More...
 
 setUserId ($a_user_id)
 
 getUserId ()
 
 delete ()
 deletes user's mailbox and all db entries related to mailbox TODO: stefan, bitte nochmal kontrollieren, ob auch wirklich alles gel�scht wird. More...
 
 updateMailsOfDeletedUser ($nameToShow)
 Update existing mails. More...
 
 isOwnedFolder (int $folderId)
 

Protected Member Functions

 folderNameExists ($a_folder_name)
 Checks whether or not the passed folder name exists in the context of the folder owner. More...
 

Protected Attributes

 $ilias
 
 $lng
 
 $db
 
 $mtree
 
 $user_id
 
 $actions = array()
 
 $default_folder = array()
 
 $table_mail_obj_data
 
 $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 13 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 69 of file class.ilMailbox.php.

70 {
71 global $DIC;
72
73 $this->ilias = $DIC['ilias'];
74 $this->lng = $DIC->language();
75 $this->db = $DIC->database();
76
77 $this->user_id = $a_user_id;
78
79 $this->table_mail_obj_data = 'mail_obj_data';
80 $this->table_tree = 'mail_tree';
81
82 if ($a_user_id) {
83 $this->mtree = new ilTree($this->user_id);
84 $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data);
85 }
86
87 // i added this, becaus if i create a new user automatically during
88 // CAS authentication, we have no $lng variable (alex, 16.6.2006)
89 // (alternative: make createDefaultFolder call static in ilObjUser->saveAsNew())
90 if (is_object($this->lng)) {
91 $this->lng->loadLanguageModule("mail");
92
93 $this->actions = array(
94 "moveMails" => $this->lng->txt("mail_move_to"),
95 "markMailsRead" => $this->lng->txt("mail_mark_read"),
96 "markMailsUnread" => $this->lng->txt("mail_mark_unread"),
97 "deleteMails" => $this->lng->txt("delete"));
98 }
99
100 // array contains basic folders and there lng translation for every new user
101 $this->default_folder = array(
102 "b_inbox" => "inbox",
103 "c_trash" => "trash",
104 "d_drafts" => "drafts",
105 "e_sent" => "sent",
106 "z_local" => "local");
107 }
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
redirection script todo: (a better solution should control the processing via a xml file)
global $DIC
Definition: saml.php:7

References $DIC.

Member Function Documentation

◆ addFolder()

ilMailbox::addFolder (   $a_parent_id,
  $a_folder_name 
)

Adds a new mail folder with the passed name under the given parent folder.

Parameters
integer$a_parent_idId of parent folder
string$a_folder_nameName of tje folder to be created
Returns
integer The new id of the created folder

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

258 {
259 if ($this->folderNameExists($a_folder_name)) {
260 return 0;
261 }
262
263 $next_id = $this->db->nextId($this->table_mail_obj_data);
264 $this->db->manipulateF(
265 '
266 INSERT INTO ' . $this->table_mail_obj_data . '
267 ( obj_id,
268 user_id,
269 title,
270 m_type
271 )
272 VALUES(%s,%s,%s,%s)',
273 array('integer','integer', 'text', 'text'),
274 array($next_id, $this->user_id, $a_folder_name, 'user_folder')
275 );
276 $this->mtree->insertNode($next_id, $a_parent_id);
277
278 return $next_id;
279 }
folderNameExists($a_folder_name)
Checks whether or not the passed folder name exists in the context of the folder owner.

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

217 {
218 $root_id = $this->db->nextId($this->table_mail_obj_data);
219 $this->db->manipulateF(
220 '
221 INSERT INTO ' . $this->table_mail_obj_data . '
222 ( obj_id,
223 user_id,
224 title,
225 m_type
226 )
227 VALUES(%s, %s, %s, %s)',
228 array('integer','integer', 'text', 'text'),
229 array($root_id, $this->user_id, 'a_root', 'root')
230 );
231 $this->mtree->addTree($this->user_id, $root_id);
232
233 foreach ($this->default_folder as $key => $folder) {
234 $last_id = $this->db->nextId($this->table_mail_obj_data);
235 $this->db->manipulateF(
236 '
237 INSERT INTO ' . $this->table_mail_obj_data . '
238 ( obj_id,
239 user_id,
240 title,
241 m_type
242 )
243 VALUES(%s, %s, %s, %s)',
244 array('integer','integer', 'text', 'text'),
245 array($last_id, $this->user_id, $key, $folder)
246 );
247 $this->mtree->insertNode($last_id, $root_id);
248 }
249 }
$key
Definition: croninfo.php:18

References $key.

◆ delete()

ilMailbox::delete ( )

deletes user's mailbox and all db entries related to mailbox TODO: stefan, bitte nochmal kontrollieren, ob auch wirklich alles gel�scht wird.

Vielleicht hab ich was �bersehen. - shofmann, 15.7.03

Returns
boolean true on successful deletion

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

492 {
493 $this->db->manipulateF(
494 '
495 DELETE FROM mail_obj_data WHERE user_id = %s',
496 array('integer'),
497 array($this->user_id)
498 );
499
500 $this->db->manipulateF(
501 '
502 DELETE FROM mail_options WHERE user_id = %s',
503 array('integer'),
504 array($this->user_id)
505 );
506
507 $this->db->manipulateF(
508 '
509 DELETE FROM mail_saved WHERE user_id = %s',
510 array('integer'),
511 array($this->user_id)
512 );
513
514 $this->db->manipulateF(
515 '
516 DELETE FROM mail_tree WHERE tree = %s',
517 array('integer'),
518 array($this->user_id)
519 );
520
521 // Delete the user's files from filesystem: This has to be done before deleting the database entries in table 'mail'
522 require_once 'Services/Mail/classes/class.ilFileDataMail.php';
523 $fdm = new ilFileDataMail($this->user_id);
524 $fdm->onUserDelete();
525
526 // Delete mails of deleted user
527 $this->db->manipulateF(
528 'DELETE FROM mail WHERE user_id = %s',
529 array('integer'),
530 array($this->user_id)
531 );
532
533 return true;
534 }
Class ilFileDataMail.

◆ deleteFolder()

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

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

331 {
332 $query = $this->db->queryf(
333 '
334 SELECT obj_id, title FROM mail_obj_data
335 WHERE obj_id = %s AND user_id = %s',
336 array('integer', 'integer'),
337 array($a_folder_id, $this->user_id)
338 );
339 $row = $this->db->fetchAssoc($query);
340
341 if (!is_array($row) || array_key_exists($row['title'], $this->default_folder)) {
342 return false;
343 }
344
345 require_once 'Services/Mail/classes/class.ilMail.php';
346 $umail = new ilMail($this->user_id);
347
348 $subtree = $this->mtree->getSubtree($this->mtree->getNodeData($a_folder_id));
349 $this->mtree->deleteTree($this->mtree->getNodeData($a_folder_id));
350
351 foreach ($subtree as $node) {
352 $mails = $umail->getMailsOfFolder($node["obj_id"]);
353 $mail_ids = array();
354 foreach ($mails as $mail) {
355 $mail_ids[] = $mail["mail_id"];
356 }
357
358 $umail->deleteMails($mail_ids);
359
360 $this->db->manipulateF(
361 '
362 DELETE FROM ' . $this->table_mail_obj_data . '
363 WHERE obj_id = %s AND user_id = %s',
364 array('integer', 'integer'),
365 array($node['obj_id'], $this->user_id)
366 );
367 }
368
369 return true;
370 }
$row
$query

References $query, and $row.

◆ folderNameExists()

ilMailbox::folderNameExists (   $a_folder_name)
protected

Checks whether or not the passed folder name exists in the context of the folder owner.

Parameters
string$a_folder_nameThe new name of folder
Returns
boolean

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

311 {
312 $res = $this->db->queryF(
313 '
314 SELECT obj_id FROM ' . $this->table_mail_obj_data . '
315 WHERE user_id = %s
316 AND title = %s',
317 array('integer', 'text'),
318 array($this->user_id, $a_folder_name)
319 );
320 $row = $this->db->fetchAssoc($res);
321
322 return is_array($row) && $row['obj_id'] > 0 ? true : false;
323 }
foreach($_POST as $key=> $value) $res

References $res, and $row.

Referenced by addFolder(), and renameFolder().

+ Here is the caller graph for this function:

◆ getActions()

ilMailbox::getActions (   $a_mobj_id)

get all possible actions if no mobj_id is given or folder specific actions if mobj_id is given

Parameters
integermobj_id @access public
Returns
array possible actions

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

201 {
202 if ($a_mobj_id) {
203 $folder_data = $this->getFolderData($a_mobj_id);
204
205 if ($folder_data["type"] == "user_folder" or $folder_data["type"] == "local") {
206 return $this->actions;
207 }
208 }
209
210 return $this->actions;
211 }
getFolderData($a_obj_id)
Fetches the data of a specific folder.

References $actions, and getFolderData().

+ Here is the call graph for this function:

◆ getDraftsFolder()

ilMailbox::getDraftsFolder ( )

get Id of the inbox folder of an user

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

132 {
133 $res = $this->db->queryF(
134 '
135 SELECT obj_id FROM ' . $this->table_mail_obj_data . '
136 WHERE user_id = %s
137 AND m_type = %s',
138 array('integer', 'text'),
139 array($this->user_id, 'drafts')
140 );
141
142 $row = $this->db->fetchAssoc($res);
143
144 return $row['obj_id'];
145 }

References $res, and $row.

◆ getFolderData()

ilMailbox::getFolderData (   $a_obj_id)

Fetches the data of a specific folder.

Parameters
integer$a_obj_id
Returns
array

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

378 {
379 $res = $this->db->queryF(
380 '
381 SELECT * FROM ' . $this->table_mail_obj_data . '
382 WHERE user_id = %s
383 AND obj_id = %s',
384 array('integer', 'integer'),
385 array($this->user_id, $a_obj_id)
386 );
387 $row = $this->db->fetchAssoc($res);
388
389 return array(
390 'obj_id' => $row['obj_id'],
391 'title' => $row['title'],
392 'type' => $row['m_type']
393 );
394 }

References $res, and $row.

Referenced by getActions(), and isOwnedFolder().

+ Here is the caller graph for this function:

◆ getInboxFolder()

ilMailbox::getInboxFolder ( )

get Id of the inbox folder of an user

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

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

References $res, and $row.

◆ getParentFolderId()

ilMailbox::getParentFolderId (   $a_obj_id)

Get id of parent folder.

Parameters
integer$a_obj_id
Returns
int

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

402 {
403 $res = $this->db->queryF(
404 '
405 SELECT * FROM ' . $this->table_tree . '
406 WHERE child = %s AND tree = %s',
407 array('integer', 'integer'),
408 array($a_obj_id, $this->user_id)
409 );
410 $row = $this->db->fetchAssoc($res);
411
412 return is_array($row) ? $row['parent'] : 0;
413 }

References $res, and $row.

◆ getRootFolderId()

ilMailbox::getRootFolderId ( )

get Id of the root folder of an user

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

189 {
190 return $this->mtree->getRootID($this->user_id);
191 }

Referenced by getSubFolders().

+ Here is the caller graph for this function:

◆ getSentFolder()

ilMailbox::getSentFolder ( )

get Id of the sent folder of an user

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

170 {
171 $res = $this->db->queryf(
172 '
173 SELECT obj_id FROM ' . $this->table_mail_obj_data . '
174 WHERE user_id = %s
175 AND m_type = %s',
176 array('integer', 'text'),
177 array($this->user_id, 'sent')
178 );
179
180 $row = $this->db->fetchAssoc($res);
181
182 return $row['obj_id'];
183 }

References $res, and $row.

◆ getSubFolders()

ilMailbox::getSubFolders (   $a_folder = 0,
  $a_folder_parent = 0 
)

Get all folders under a given folder/node id.

Parameters
int$a_folder
int$a_folder_parent
Returns
array

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

422 {
423 if (!$a_folder) {
424 $a_folder = $this->getRootFolderId();
425 }
426
427 $user_folder = array();
428
429 foreach ($this->default_folder as $key => $value) {
430 $res = $this->db->queryF(
431 '
432 SELECT obj_id, m_type
433 FROM ' . $this->table_mail_obj_data . '
434 WHERE user_id = %s
435 AND title = %s',
436 array('integer', 'text'),
437 array($this->user_id, $key)
438 );
439 $row = $this->db->fetchAssoc($res);
440
441 $user_folder[] = array(
442 'title' => $key,
443 'type' => $row['m_type'],
444 'obj_id' => $row['obj_id']
445 );
446 }
447
448 $res = $this->db->queryF(
449 '
450 SELECT * FROM ' . $this->table_tree . ', ' . $this->table_mail_obj_data . '
451 WHERE ' . $this->table_mail_obj_data . '.obj_id = ' . $this->table_tree . '.child
452 AND ' . $this->table_tree . '.depth > %s
453 AND ' . $this->table_tree . '.tree = %s
454 ORDER BY ' . $this->table_tree . '.lft, ' . $this->table_mail_obj_data . '.title ',
455 array('integer', 'integer'),
456 array(2, $this->user_id)
457 );
458 while ($row = $this->db->fetchAssoc($res)) {
459 $user_folder[] = array(
460 'title' => $row['title'],
461 'type' => $row['m_type'],
462 'obj_id' => $row['child']
463 );
464 }
465
466 return $user_folder;
467 }
getRootFolderId()
get Id of the root folder of an user

References $key, $res, $row, and getRootFolderId().

+ Here is the call graph for this function:

◆ getTrashFolder()

ilMailbox::getTrashFolder ( )

get Id of the trash folder of an user

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

151 {
152 $res = $this->db->queryf(
153 '
154 SELECT obj_id FROM ' . $this->table_mail_obj_data . '
155 WHERE user_id = %s
156 AND m_type = %s',
157 array('integer', 'text'),
158 array($this->user_id, 'trash')
159 );
160
161 $row = $this->db->fetchAssoc($res);
162
163 return $row['obj_id'];
164 }

References $res, and $row.

◆ getUserId()

ilMailbox::getUserId ( )
Returns
int

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

480 : int
481 {
482 return (int) $this->user_id;
483 }

References $user_id.

◆ isOwnedFolder()

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

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

557 : bool
558 {
559 $folderData = $this->getFolderData($folderId);
560
561 return $folderData['obj_id'] == $folderId;
562 }

References getFolderData().

+ Here is the call graph for this function:

◆ renameFolder()

ilMailbox::renameFolder (   $a_obj_id,
  $a_new_folder_name 
)

Rename a folder and check if the name already exists.

Parameters
integer$a_obj_idThe id of the folder to be renamed
string$a_new_folder_nameThe new name of the folder
Returns
boolean

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

288 {
289 if ($this->folderNameExists($a_new_folder_name)) {
290 return false;
291 }
292
293 $this->db->manipulateF(
294 '
295 UPDATE ' . $this->table_mail_obj_data . '
296 SET title = %s
297 WHERE obj_id = %s AND user_id = %s',
298 array('text', 'integer', 'integer'),
299 array($a_new_folder_name, $a_obj_id, $this->user_id)
300 );
301
302 return true;
303 }

References folderNameExists().

+ Here is the call graph for this function:

◆ setUserId()

ilMailbox::setUserId (   $a_user_id)
Parameters
integer$a_user_id

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

473 {
474 $this->user_id = $a_user_id;
475 }

◆ updateMailsOfDeletedUser()

ilMailbox::updateMailsOfDeletedUser (   $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 541 of file class.ilMailbox.php.

542 {
543 $this->db->manipulateF(
544 '
545 UPDATE mail
546 SET sender_id = %s, import_name = %s
547 WHERE sender_id = %s',
548 array('integer', 'text', 'integer'),
549 array(0, $nameToShow, $this->user_id)
550 );
551 }

Field Documentation

◆ $actions

ilMailbox::$actions = array()
protected

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

Referenced by getActions().

◆ $db

ilMailbox::$db
protected

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

◆ $default_folder

ilMailbox::$default_folder = array()
protected

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

◆ $ilias

ilMailbox::$ilias
protected

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

◆ $lng

ilMailbox::$lng
protected

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

◆ $mtree

ilMailbox::$mtree
protected

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

◆ $table_mail_obj_data

ilMailbox::$table_mail_obj_data
protected

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

◆ $table_tree

ilMailbox::$table_tree
protected

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

◆ $user_id

ilMailbox::$user_id
protected

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

Referenced by getUserId().


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