ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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)
 Constructor. More...
 
 getRootFolderId ()
 get Id of the root folder of an user @access public 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 ()
 create all default folders @access public More...
 
 addFolder ($a_parent_id, $a_folder_name)
 add folder More...
 
 renameFolder ($a_obj_id, $a_new_folder_name)
 rename folder and check if the name already exists More...
 
 folderNameExists ($a_folder_name)
 rename folder and check if the name already exists More...
 
 deleteFolder ($a_folder_id)
 add folder More...
 
 getLastInsertId ()
 
 getFolderData ($a_obj_id)
 get 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 given node More...
 
 setUserId ($a_user_id)
 set user_id More...
 

Static Public Member Functions

 _countNewMails ($a_user_id)
 Static method check how many unread mails are in inbox @access public. More...
 

Data Fields

 $ilias
 
 $lng
 
 $mtree
 
 $user_id
 
 $actions
 
 $default_folder
 
 $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 14 of file class.ilMailbox.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailbox::__construct (   $a_user_id = 0)

Constructor.

Parameters
integeruser_id of mailbox @access public

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

79 {
80 global $ilias,$lng;
81
82 $this->ilias = $ilias;
83 $this->lng = $lng;
84 $this->user_id = $a_user_id;
85
86 $this->table_mail_obj_data = 'mail_obj_data';
87 $this->table_tree = 'mail_tree';
88
89 if ($a_user_id)
90 {
91 $this->mtree = new ilTree($this->user_id);
92 $this->mtree->setTableNames($this->table_tree,$this->table_mail_obj_data);
93 }
94
95 // i added this, becaus if i create a new user automatically during
96 // CAS authentication, we have no $lng variable (alex, 16.6.2006)
97 // (alternative: make createDefaultFolder call static in ilObjUser->saveAsNew())
98 if (is_object($this->lng))
99 {
100 $this->lng->loadLanguageModule("mail");
101
102 $this->actions = array(
103 "moveMails" => $this->lng->txt("mail_move_to"),
104 "markMailsRead" => $this->lng->txt("mail_mark_read"),
105 "markMailsUnread" => $this->lng->txt("mail_mark_unread"),
106 "deleteMails" => $this->lng->txt("delete"));
107 }
108
109 // array contains basic folders and there lng translation for every new user
110 $this->default_folder = array(
111 "b_inbox" => "inbox",
112 "c_trash" => "trash",
113 "d_drafts" => "drafts",
114 "e_sent" => "sent",
115 "z_local" => "local");
116
117 }
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)

References $ilias, and $lng.

Member Function Documentation

◆ _countNewMails()

ilMailbox::_countNewMails (   $a_user_id)
static

Static method check how many unread mails are in inbox @access public.

Returns
int number of mails

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

254 {
255 include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
257 }
static getNumberOfNewMailsByUserId($usr_id)
Determines the number of new mails for the passed user id and stores this information in a local cach...

References ilMailGlobalServices\getNumberOfNewMailsByUserId().

+ Here is the call graph for this function:

◆ addFolder()

ilMailbox::addFolder (   $a_parent_id,
  $a_folder_name 
)

add folder

Parameters
integerid of parent folder
stringname of folder
Returns
integer new id of folder @access public

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

313 {
314 global $ilDB;
315
316 if ($this->folderNameExists($a_folder_name))
317 {
318 return 0;
319 }
320 // ENTRY IN mail_obj_data
321 $next_id = $ilDB->nextId($this->table_mail_obj_data);
322 $statement = $ilDB->manipulateF('
323 INSERT INTO '. $this->table_mail_obj_data .'
324 ( obj_id,
325 user_id,
326 title,
327 m_type
328 )
329 VALUES(%s,%s,%s,%s)',
330 array('integer','integer', 'text', 'text'),
331 array($next_id, $this->user_id, $a_folder_name, 'user_folder'));
332
333 // ENTRY IN mail_tree
334 $this->mtree->insertNode($next_id,$a_parent_id);
335 return $next_id;
336 }
folderNameExists($a_folder_name)
rename folder and check if the name already exists
global $ilDB

References $ilDB, and folderNameExists().

+ Here is the call graph for this function:

◆ createDefaultFolder()

ilMailbox::createDefaultFolder ( )

create all default folders @access public

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

264 {
265 global $ilDB;
266
267/* $root_id = $this->getLastInsertId();
268 ++$root_id;
269*/
270 $root_id = $ilDB->nextId($this->table_mail_obj_data);
271
272 $res = $ilDB->manipulateF('
273 INSERT INTO '. $this->table_mail_obj_data .'
274 ( obj_id,
275 user_id,
276 title,
277 m_type
278 )
279 VALUES( %s, %s, %s, %s)',
280 array('integer','integer', 'text', 'text'),
281 array($root_id, $this->user_id, 'a_root', 'root'));
282
283 $this->mtree->addTree($this->user_id,$root_id);
284
285 foreach ($this->default_folder as $key => $folder)
286 {
287 /*$last_id = $this->getLastInsertId();
288 ++$last_id;
289 */
290 $last_id = $ilDB->nextId($this->table_mail_obj_data);
291 $statement = $ilDB->manipulateF('
292 INSERT INTO '. $this->table_mail_obj_data .'
293 ( obj_id,
294 user_id,
295 title,
296 m_type
297 )
298 VALUES( %s, %s, %s, %s)',
299 array('integer','integer', 'text', 'text'),
300 array($last_id,$this->user_id, $key, $folder));
301
302 $this->mtree->insertNode($last_id,$root_id);
303 }
304 }

References $ilDB, and $res.

◆ deleteFolder()

ilMailbox::deleteFolder (   $a_folder_id)

add folder

Parameters
integerid of parent folder @access public

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

392 {
393 global $ilDB;
394
395 $query = $ilDB->queryf('
396 SELECT title FROM mail_obj_data
397 WHERE obj_id = %s',
398 array('integer'),
399 array($a_folder_id)
400 );
401
402 $row = $ilDB->fetchAssoc($query);
403
404 if( array_key_exists($row['title'], $this->default_folder) )
405 {
406 return false;
407 }
408
409 include_once("Services/Mail/classes/class.ilMail.php");
410 $umail = new ilMail($this->user_id);
411
412 // SAVE SUBTREE DATA
413 $subtree = $this->mtree->getSubtree($this->mtree->getNodeData($a_folder_id));
414
415 // DELETE ENTRY IN TREE
416 $this->mtree->deleteTree($this->mtree->getNodeData($a_folder_id));
417
418 // DELETE ENTRY IN mobj_data
419 foreach($subtree as $node)
420 {
421 // DELETE mail(s) of folder(s)
422 $mails = $umail->getMailsOfFolder($node["obj_id"]);
423
424 foreach ($mails as $mail)
425 {
426 $mail_ids[] = $mail["mail_id"];
427 }
428
429 if (is_array($mail_ids))
430 {
431 $umail->deleteMails($mail_ids);
432 }
433
434 // DELETE mobj_data entries
435 $statement = $ilDB->manipulateF('
436 DELETE FROM '. $this->table_mail_obj_data .'
437 WHERE obj_id = %s',
438 array('integer'),
439 array($node['obj_id']));
440 }
441
442 return true;
443 }
Class Mail this class handles base functions for mail handling.

References $ilDB, $query, and $row.

◆ folderNameExists()

ilMailbox::folderNameExists (   $a_folder_name)

rename folder and check if the name already exists

Parameters
stringnew name of folder
Returns
boolean @access public

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

371 {
372 global $ilDB;
373
374 $res = $ilDB->queryf('
375 SELECT obj_id FROM '. $this->table_mail_obj_data .'
376 WHERE user_id = %s
377 AND title = %s',
378 array('integer', 'text'),
379 array($this->user_id, $a_folder_name));
380
381 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
382
383 return $row->obj_id ? true : false;
384 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11

References $ilDB, $res, $row, and DB_FETCHMODE_OBJECT.

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

231 {
232 if ($a_mobj_id)
233 {
234 $folder_data = $this->getFolderData($a_mobj_id);
235
236 if ($folder_data["type"] == "user_folder" or $folder_data["type"] == "local")
237 {
238 #return array_merge($this->actions,array("add" => $this->lng->txt("mail_add_subfolder")));
239 return $this->actions;
240 }
241 }
242
243 return $this->actions;
244 }
getFolderData($a_obj_id)
get data of a specific folder

References $actions, and getFolderData().

+ Here is the call graph for this function:

◆ getFolderData()

ilMailbox::getFolderData (   $a_obj_id)

get data of a specific folder

Parameters
intid of parent folder @access public

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

459 {
460 global $ilDB;
461
462 $res = $ilDB->queryf('
463 SELECT * FROM '. $this->table_mail_obj_data .'
464 WHERE user_id = %s
465 AND obj_id = %s',
466 array('integer', 'integer'),
467 array($this->user_id, $a_obj_id));
468
469 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
470
471 return array(
472 "obj_id" => $row->obj_id,
473 "title" => stripslashes($row->title),
474 "type" => $row->m_type
475 );
476 }

References $ilDB, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by getActions().

+ Here is the caller graph for this function:

◆ getLastInsertId()

ilMailbox::getLastInsertId ( )

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

447 {
448 global $ilDB;
449
450 return $ilDB->getLastInsertId();
451 }

References $ilDB.

◆ getParentFolderId()

ilMailbox::getParentFolderId (   $a_obj_id)

get id of parent folder

Parameters
integerid of folder @access public

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

483 {
484 global $ilDB;
485
486 $res = $ilDB->queryf('
487 SELECT * FROM '. $this->table_tree .'
488 WHERE child = %s',
489 array('integer'),
490 array($a_obj_id));
491
492 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
493
494
495 return $row->parent;
496 }

References $ilDB, $res, $row, and DB_FETCHMODE_OBJECT.

◆ getRootFolderId()

ilMailbox::getRootFolderId ( )

get Id of the root folder of an user @access public

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

219 {
220 return $this->mtree->getRootID($this->user_id);
221 }

Referenced by getSubFolders().

+ Here is the caller graph for this function:

◆ getSubFolders()

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

get all folders under given node

Parameters
integerobj_id
integerparent_id @access public

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

504 {
505
506 global $ilDB;
507
508 if (!$a_folder)
509 {
510 $a_folder = $this->getRootFolderId();
511 }
512
513 foreach ($this->default_folder as $key => $value)
514 {
515 $res = $ilDB->queryf('
516 SELECT obj_id,m_type FROM '. $this->table_mail_obj_data .'
517 WHERE user_id = %s
518 AND title = %s',
519 array('integer', 'text'),
520 array($this->user_id, $key));
521
522 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
523
524 $user_folder[] = array(
525 "title" => $key,
526 "type" => $row->m_type,
527 "obj_id" => $row->obj_id);
528 }
529
530 $res = $ilDB->queryf('
531 SELECT * FROM '. $this->table_tree. ', '. $this->table_mail_obj_data .'
532 WHERE '. $this->table_mail_obj_data.'.obj_id = '. $this->table_tree.'.child
533 AND '. $this->table_tree.'.depth > %s
534 AND '. $this->table_tree.'.tree = %s
535 ORDER BY '. $this->table_mail_obj_data.'.title ',
536 array('integer', 'integer'),
537 array('2', $this->user_id));
538
539 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
540 {
541 $user_folder[] = array(
542 "title" => stripslashes($row->title),
543 "type" => $row->m_type,
544 "obj_id" => $row->child);
545 }
546
547 return $user_folder;
548 }
getRootFolderId()
get Id of the root folder of an user @access public

References $ilDB, $res, $row, DB_FETCHMODE_OBJECT, and getRootFolderId().

+ Here is the call graph for this function:

◆ renameFolder()

ilMailbox::renameFolder (   $a_obj_id,
  $a_new_folder_name 
)

rename folder and check if the name already exists

Parameters
integerid folder
stringnew name of folder
Returns
boolean @access public

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

346 {
347 global $ilDB;
348
349 if ($this->folderNameExists($a_new_folder_name))
350 {
351 return false;
352 }
353
354 $statement = $ilDB->manipulateF('
355 UPDATE '. $this->table_mail_obj_data .'
356 SET title = %s
357 WHERE obj_id = %s',
358 array('text', 'integer'),
359 array($a_new_folder_name, $a_obj_id));
360
361 return true;
362 }

References $ilDB, and folderNameExists().

+ Here is the call graph for this function:

◆ setUserId()

ilMailbox::setUserId (   $a_user_id)

set user_id

Parameters
integerid of user @access public

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

556 {
557 $this->user_id = $a_user_id;
558 }

Field Documentation

◆ $actions

ilMailbox::$actions

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

Referenced by getActions().

◆ $default_folder

ilMailbox::$default_folder

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

◆ $ilias

ilMailbox::$ilias

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

Referenced by __construct().

◆ $lng

ilMailbox::$lng

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

Referenced by __construct().

◆ $mtree

ilMailbox::$mtree

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

◆ $table_mail_obj_data

ilMailbox::$table_mail_obj_data

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

◆ $table_tree

ilMailbox::$table_tree

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

◆ $user_id

ilMailbox::$user_id

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


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