ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups 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)
 Constructor.
 getRootFolderId ()
 get Id of the root folder of an user public
 getActions ($a_mobj_id)
 get all possible actions if no mobj_id is given or folder specific actions if mobj_id is given
 createDefaultFolder ()
 create all default folders public
 addFolder ($a_parent_id, $a_folder_name)
 add folder
 renameFolder ($a_obj_id, $a_new_folder_name)
 rename folder and check if the name already exists
 folderNameExists ($a_folder_name)
 rename folder and check if the name already exists
 deleteFolder ($a_folder_id)
 add folder
 getLastInsertId ()
 getFolderData ($a_obj_id)
 get data of a specific folder
 getParentFolderId ($a_obj_id)
 get id of parent folder
 getSubFolders ($a_folder=0, $a_folder_parent=0)
 get all folders under given node
 setUserId ($a_user_id)
 set user_id

Static Public Member Functions

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

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:
class.ilMailbox.php 51992 2014-08-04 09:28:15Z mjansen

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

Constructor & Destructor Documentation

ilMailbox::__construct (   $a_user_id = 0)

Constructor.

Parameters
integeruser_id of mailbox public

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

References $ilias, and $lng.

{
global $ilias,$lng;
$this->ilias = $ilias;
$this->lng = $lng;
$this->user_id = $a_user_id;
$this->table_mail_obj_data = 'mail_obj_data';
$this->table_tree = 'mail_tree';
if ($a_user_id)
{
$this->mtree = new ilTree($this->user_id);
$this->mtree->setTableNames($this->table_tree,$this->table_mail_obj_data);
}
// i added this, becaus if i create a new user automatically during
// CAS authentication, we have no $lng variable (alex, 16.6.2006)
// (alternative: make createDefaultFolder call static in ilObjUser->saveAsNew())
if (is_object($this->lng))
{
$this->lng->loadLanguageModule("mail");
$this->actions = array(
"moveMails" => $this->lng->txt("mail_move_to"),
"markMailsRead" => $this->lng->txt("mail_mark_read"),
"markMailsUnread" => $this->lng->txt("mail_mark_unread"),
"deleteMails" => $this->lng->txt("delete"));
}
// array contains basic folders and there lng translation for every new user
$this->default_folder = array(
"b_inbox" => "inbox",
"c_trash" => "trash",
"d_drafts" => "drafts",
"e_sent" => "sent",
"z_local" => "local");
}

Member Function Documentation

ilMailbox::_countNewMails (   $a_user_id)
static

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

Returns
int number of mails

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

References ilMailGlobalServices\getNumberOfNewMailsByUserId().

{
include_once 'Services/Mail/classes/class.ilMailGlobalServices.php';
}

+ Here is the call graph for this function:

ilMailbox::addFolder (   $a_parent_id,
  $a_folder_name 
)

add folder

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

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

References folderNameExists().

{
global $ilDB;
if ($this->folderNameExists($a_folder_name))
{
return 0;
}
// ENTRY IN mail_obj_data
$next_id = $ilDB->nextId($this->table_mail_obj_data);
$statement = $ilDB->manipulateF('
INSERT INTO '. $this->table_mail_obj_data .'
( obj_id,
user_id,
title,
m_type
)
VALUES(%s,%s,%s,%s)',
array('integer','integer', 'text', 'text'),
array($next_id, $this->user_id, $a_folder_name, 'user_folder'));
// ENTRY IN mail_tree
$this->mtree->insertNode($next_id,$a_parent_id);
return $next_id;
}

+ Here is the call graph for this function:

ilMailbox::createDefaultFolder ( )

create all default folders public

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

References $res.

{
global $ilDB;
/* $root_id = $this->getLastInsertId();
++$root_id;
*/
$root_id = $ilDB->nextId($this->table_mail_obj_data);
$res = $ilDB->manipulateF('
INSERT INTO '. $this->table_mail_obj_data .'
( obj_id,
user_id,
title,
m_type
)
VALUES( %s, %s, %s, %s)',
array('integer','integer', 'text', 'text'),
array($root_id, $this->user_id, 'a_root', 'root'));
$this->mtree->addTree($this->user_id,$root_id);
foreach ($this->default_folder as $key => $folder)
{
/*$last_id = $this->getLastInsertId();
++$last_id;
*/
$last_id = $ilDB->nextId($this->table_mail_obj_data);
$statement = $ilDB->manipulateF('
INSERT INTO '. $this->table_mail_obj_data .'
( obj_id,
user_id,
title,
m_type
)
VALUES( %s, %s, %s, %s)',
array('integer','integer', 'text', 'text'),
array($last_id,$this->user_id, $key, $folder));
$this->mtree->insertNode($last_id,$root_id);
}
}
ilMailbox::deleteFolder (   $a_folder_id)

add folder

Parameters
integerid of parent folder public

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

References $query, and $row.

{
global $ilDB;
$query = $ilDB->queryf('
SELECT title FROM mail_obj_data
WHERE obj_id = %s',
array('integer'),
array($a_folder_id)
);
$row = $ilDB->fetchAssoc($query);
if( array_key_exists($row['title'], $this->default_folder) )
{
return false;
}
include_once("Services/Mail/classes/class.ilMail.php");
$umail = new ilMail($this->user_id);
// SAVE SUBTREE DATA
$subtree = $this->mtree->getSubtree($this->mtree->getNodeData($a_folder_id));
// DELETE ENTRY IN TREE
$this->mtree->deleteTree($this->mtree->getNodeData($a_folder_id));
// DELETE ENTRY IN mobj_data
foreach($subtree as $node)
{
// DELETE mail(s) of folder(s)
$mails = $umail->getMailsOfFolder($node["obj_id"]);
foreach ($mails as $mail)
{
$mail_ids[] = $mail["mail_id"];
}
if (is_array($mail_ids))
{
$umail->deleteMails($mail_ids);
}
// DELETE mobj_data entries
$statement = $ilDB->manipulateF('
DELETE FROM '. $this->table_mail_obj_data .'
WHERE obj_id = %s',
array('integer'),
array($node['obj_id']));
}
return true;
}
ilMailbox::folderNameExists (   $a_folder_name)

rename folder and check if the name already exists

Parameters
stringnew name of folder
Returns
boolean public

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

References $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by addFolder(), and renameFolder().

{
global $ilDB;
$res = $ilDB->queryf('
SELECT obj_id FROM '. $this->table_mail_obj_data .'
WHERE user_id = %s
AND title = %s',
array('integer', 'text'),
array($this->user_id, $a_folder_name));
return $row->obj_id ? true : false;
}

+ Here is the caller graph for this function:

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().

{
if ($a_mobj_id)
{
$folder_data = $this->getFolderData($a_mobj_id);
if ($folder_data["type"] == "user_folder" or $folder_data["type"] == "local")
{
#return array_merge($this->actions,array("add" => $this->lng->txt("mail_add_subfolder")));
}
}
}

+ Here is the call graph for this function:

ilMailbox::getFolderData (   $a_obj_id)

get data of a specific folder

Parameters
intid of parent folder public

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

References $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by getActions().

{
global $ilDB;
$res = $ilDB->queryf('
SELECT * FROM '. $this->table_mail_obj_data .'
WHERE user_id = %s
AND obj_id = %s',
array('integer', 'integer'),
array($this->user_id, $a_obj_id));
return array(
"obj_id" => $row->obj_id,
"title" => stripslashes($row->title),
"type" => $row->m_type
);
}

+ Here is the caller graph for this function:

ilMailbox::getLastInsertId ( )

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

{
global $ilDB;
return $ilDB->getLastInsertId();
}
ilMailbox::getParentFolderId (   $a_obj_id)

get id of parent folder

Parameters
integerid of folder public

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

References $res, $row, and DB_FETCHMODE_OBJECT.

{
global $ilDB;
$res = $ilDB->queryf('
SELECT * FROM '. $this->table_tree .'
WHERE child = %s',
array('integer'),
array($a_obj_id));
return $row->parent;
}
ilMailbox::getRootFolderId ( )

get Id of the root folder of an user public

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

Referenced by getSubFolders().

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

+ Here is the caller graph for this function:

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

get all folders under given node

Parameters
integerobj_id
integerparent_id public

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

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

{
global $ilDB;
if (!$a_folder)
{
$a_folder = $this->getRootFolderId();
}
foreach ($this->default_folder as $key => $value)
{
$res = $ilDB->queryf('
SELECT obj_id,m_type FROM '. $this->table_mail_obj_data .'
WHERE user_id = %s
AND title = %s',
array('integer', 'text'),
array($this->user_id, $key));
$user_folder[] = array(
"title" => $key,
"type" => $row->m_type,
"obj_id" => $row->obj_id);
}
$res = $ilDB->queryf('
SELECT * FROM '. $this->table_tree. ', '. $this->table_mail_obj_data .'
WHERE '. $this->table_mail_obj_data.'.obj_id = '. $this->table_tree.'.child
AND '. $this->table_tree.'.depth > %s
AND '. $this->table_tree.'.tree = %s
ORDER BY '. $this->table_mail_obj_data.'.title ',
array('integer', 'integer'),
array('2', $this->user_id));
while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$user_folder[] = array(
"title" => stripslashes($row->title),
"type" => $row->m_type,
"obj_id" => $row->child);
}
return $user_folder;
}

+ Here is the call graph for this function:

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 public

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

References folderNameExists().

{
global $ilDB;
if ($this->folderNameExists($a_new_folder_name))
{
return false;
}
$statement = $ilDB->manipulateF('
UPDATE '. $this->table_mail_obj_data .'
SET title = %s
WHERE obj_id = %s',
array('text', 'integer'),
array($a_new_folder_name, $a_obj_id));
return true;
}

+ Here is the call graph for this function:

ilMailbox::setUserId (   $a_user_id)

set user_id

Parameters
integerid of user public

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

{
$this->user_id = $a_user_id;
}

Field Documentation

ilMailbox::$actions

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

Referenced by getActions().

ilMailbox::$default_folder

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

ilMailbox::$ilias

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

Referenced by __construct().

ilMailbox::$lng

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

Referenced by __construct().

ilMailbox::$mtree

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

ilMailbox::$table_mail_obj_data

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

ilMailbox::$table_tree

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

ilMailbox::$user_id

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


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