ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 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 ()
 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)
 

Data Fields

 $ilias
 
 $lng
 
 $mtree
 
 $user_id
 
 $actions
 
 $default_folder
 
 $table_mail_obj_data
 
 $table_tree
 

Protected Member Functions

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

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 public

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

References $ilDB, $ilias, $lng, $res, $row, and array.

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  }
redirection script todo: (a better solution should control the processing via a xml file) ...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.

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

References $ilDB, array, and folderNameExists().

292  {
293  global $ilDB;
294 
295  if($this->folderNameExists($a_folder_name))
296  {
297  return 0;
298  }
299 
300  $next_id = $ilDB->nextId($this->table_mail_obj_data);
301  $ilDB->manipulateF('
302  INSERT INTO '. $this->table_mail_obj_data .'
303  ( obj_id,
304  user_id,
305  title,
306  m_type
307  )
308  VALUES(%s,%s,%s,%s)',
309  array('integer','integer', 'text', 'text'),
310  array($next_id, $this->user_id, $a_folder_name, 'user_folder')
311  );
312  $this->mtree->insertNode($next_id, $a_parent_id);
313 
314  return $next_id;
315  }
folderNameExists($a_folder_name)
Checks whether or not the passed folder name exists in the context of the folder owner.
Create styles array
The data for the language used.
global $ilDB
+ 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 249 of file class.ilMailbox.php.

References $ilDB, and array.

250  {
251  global $ilDB;
252 
253  $root_id = $ilDB->nextId($this->table_mail_obj_data);
254  $ilDB->manipulateF('
255  INSERT INTO '. $this->table_mail_obj_data .'
256  ( obj_id,
257  user_id,
258  title,
259  m_type
260  )
261  VALUES(%s, %s, %s, %s)',
262  array('integer','integer', 'text', 'text'),
263  array($root_id, $this->user_id, 'a_root', 'root')
264  );
265  $this->mtree->addTree($this->user_id, $root_id);
266 
267  foreach($this->default_folder as $key => $folder)
268  {
269  $last_id = $ilDB->nextId($this->table_mail_obj_data);
270  $ilDB->manipulateF('
271  INSERT INTO '. $this->table_mail_obj_data .'
272  ( obj_id,
273  user_id,
274  title,
275  m_type
276  )
277  VALUES(%s, %s, %s, %s)',
278  array('integer','integer', 'text', 'text'),
279  array($last_id, $this->user_id, $key, $folder)
280  );
281  $this->mtree->insertNode($last_id, $root_id);
282  }
283  }
Create styles array
The data for the language used.
global $ilDB

◆ deleteFolder()

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

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

References $ilDB, $query, $row, and array.

370  {
371  global $ilDB;
372 
373  $query = $ilDB->queryf('
374  SELECT obj_id, title FROM mail_obj_data
375  WHERE obj_id = %s AND user_id = %s',
376  array('integer', 'integer'),
377  array($a_folder_id, $this->user_id)
378  );
379  $row = $ilDB->fetchAssoc($query);
380 
381  if(!is_array($row) || array_key_exists($row['title'], $this->default_folder))
382  {
383  return false;
384  }
385 
386  require_once 'Services/Mail/classes/class.ilMail.php';
387  $umail = new ilMail($this->user_id);
388 
389  $subtree = $this->mtree->getSubtree($this->mtree->getNodeData($a_folder_id));
390  $this->mtree->deleteTree($this->mtree->getNodeData($a_folder_id));
391 
392  foreach($subtree as $node)
393  {
394  $mails = $umail->getMailsOfFolder($node["obj_id"]);
395  $mail_ids = array();
396  foreach($mails as $mail)
397  {
398  $mail_ids[] = $mail["mail_id"];
399  }
400 
401  $umail->deleteMails($mail_ids);
402 
403  $ilDB->manipulateF('
404  DELETE FROM '. $this->table_mail_obj_data .'
405  WHERE obj_id = %s AND user_id = %s',
406  array('integer', 'integer'),
407  array($node['obj_id'], $this->user_id)
408  );
409  }
410 
411  return true;
412  }
This class handles base functions for mail handling.
Create styles array
The data for the language used.
global $ilDB

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

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

Referenced by addFolder(), and renameFolder().

349  {
350  global $ilDB;
351 
352  $res = $ilDB->queryF('
353  SELECT obj_id FROM '. $this->table_mail_obj_data .'
354  WHERE user_id = %s
355  AND title = %s',
356  array('integer', 'text'),
357  array($this->user_id, $a_folder_name)
358  );
359  $row = $ilDB->fetchAssoc($res);
360 
361  return is_array($row) && $row['obj_id'] > 0 ? true : false;
362  }
Create styles array
The data for the language used.
global $ilDB
+ 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 public
Returns
array possible actions

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

References $actions, and getFolderData().

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)
Fetches the data of a specific folder.
+ Here is the call graph for this function:

◆ getFolderData()

ilMailbox::getFolderData (   $a_obj_id)

Fetches the data of a specific folder.

Parameters
integer$a_obj_id
Returns
array

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

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

Referenced by getActions().

420  {
421  global $ilDB;
422 
423  $res = $ilDB->queryF('
424  SELECT * FROM ' . $this->table_mail_obj_data . '
425  WHERE user_id = %s
426  AND obj_id = %s',
427  array('integer', 'integer'),
428  array($this->user_id, $a_obj_id)
429  );
430  $row = $ilDB->fetchAssoc($res);
431 
432  return array(
433  'obj_id' => $row['obj_id'],
434  'title' => $row['title'],
435  'type' => $row['m_type']
436  );
437  }
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getParentFolderId()

ilMailbox::getParentFolderId (   $a_obj_id)

Get id of parent folder.

Parameters
integer$a_obj_id
Returns
int

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

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

445  {
446  global $ilDB;
447 
448  $res = $ilDB->queryF('
449  SELECT * FROM '. $this->table_tree .'
450  WHERE child = %s AND tree = %s',
451  array('integer', 'integer'),
452  array($a_obj_id, $this->user_id)
453  );
454  $row = $ilDB->fetchAssoc($res);
455 
456  return is_array($row) ? $row['parent'] : 0;
457  }
Create styles array
The data for the language used.
global $ilDB

◆ getRootFolderId()

ilMailbox::getRootFolderId ( )

get Id of the root folder of an user public

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

Referenced by getSubFolders().

219  {
220  return $this->mtree->getRootID($this->user_id);
221  }
+ Here is the caller graph for this function:

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

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

466  {
467  global $ilDB;
468 
469  if(!$a_folder)
470  {
471  $a_folder = $this->getRootFolderId();
472  }
473 
474  $user_folder = array();
475 
476  foreach($this->default_folder as $key => $value)
477  {
478  $res = $ilDB->queryF('
479  SELECT obj_id, m_type
480  FROM ' . $this->table_mail_obj_data . '
481  WHERE user_id = %s
482  AND title = %s',
483  array('integer', 'text'),
484  array($this->user_id, $key)
485  );
486  $row = $ilDB->fetchAssoc($res);
487 
488  $user_folder[] = array(
489  'title' => $key,
490  'type' => $row['m_type'],
491  'obj_id' => $row['obj_id']
492  );
493  }
494 
495  $res = $ilDB->queryF('
496  SELECT * FROM ' . $this->table_tree . ', ' . $this->table_mail_obj_data . '
497  WHERE ' . $this->table_mail_obj_data . '.obj_id = ' . $this->table_tree . '.child
498  AND ' . $this->table_tree . '.depth > %s
499  AND ' . $this->table_tree . '.tree = %s
500  ORDER BY ' . $this->table_tree . '.lft, ' . $this->table_mail_obj_data . '.title ',
501  array('integer', 'integer'),
502  array(2, $this->user_id)
503  );
504  while($row = $ilDB->fetchAssoc($res))
505  {
506  $user_folder[] = array(
507  'title' => $row['title'],
508  'type' => $row['m_type'],
509  'obj_id' => $row['child']
510  );
511  }
512 
513  return $user_folder;
514  }
getRootFolderId()
get Id of the root folder of an user public
Create styles array
The data for the language used.
global $ilDB
+ 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 323 of file class.ilMailbox.php.

References $ilDB, array, and folderNameExists().

324  {
325  global $ilDB;
326 
327  if($this->folderNameExists($a_new_folder_name))
328  {
329  return false;
330  }
331 
332  $ilDB->manipulateF('
333  UPDATE '. $this->table_mail_obj_data .'
334  SET title = %s
335  WHERE obj_id = %s AND user_id = %s',
336  array('text', 'integer', 'integer'),
337  array($a_new_folder_name, $a_obj_id, $this->user_id)
338  );
339 
340  return true;
341  }
folderNameExists($a_folder_name)
Checks whether or not the passed folder name exists in the context of the folder owner.
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:

◆ setUserId()

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

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

References $ilDB, and array.

520  {
521  $this->user_id = $a_user_id;
522  }

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: