ILIAS  eassessment Revision 61809
 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

 ilMailbox ($a_user_id=0)
 Constructor.
 getInboxFolder ()
 get Id of the inbox folder of an user public
 getDraftsFolder ()
 get Id of the inbox folder of an user public
 getTrashFolder ()
 get Id of the trash folder of an user public
 getSentFolder ()
 get Id of the sent folder of an user public
 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
 delete ()
 deletes user's mailbox and all db entries related to mailbox TODO: stefan, bitte nochmal kontrollieren, ob auch wirklich alles gel�scht wird.
 updateMailsOfDeletedUser ()
 Update existing mails.

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 28404 2011-04-07 05:44:49Z hschottm

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

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

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

Referenced by ilSoapUserAdministration\hasNewMail(), and ilMainMenuGUI\renderMainMenuListEntries().

{
global $ilDB;
global $ilias;
if (!$a_user_id)
{
return 0;
}
// CHECK FOR SYSTEM MAIL
$res = $ilDB->queryf('
SELECT count(mail_id) cnt FROM mail
WHERE folder_id = %s
AND user_id = %s
AND m_status = %s',
array('integer', 'integer', 'text'),
array('0', $a_user_id, 'unread'));
$res2 = $ilDB->queryf('
SELECT count(mail_id) cnt FROM mail m,mail_obj_data mo
WHERE m.user_id = mo.user_id
AND m.folder_id = mo.obj_id
AND mo.m_type = %s
AND m.user_id = %s
AND m.m_status = %s',
array('text', 'integer', 'text'),
array('inbox', $a_user_id, 'unread'));
$row2 = $res2->fetchRow(DB_FETCHMODE_OBJECT);
return $row->cnt + $row2->cnt;
}

+ Here is the caller 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 351 of file class.ilMailbox.php.

References $ilDB, and 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 302 of file class.ilMailbox.php.

References $ilDB, and $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::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

public

Returns
boolean true on successful deletion

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

References $data, and $ilDB.

{
global $ilDB;
$data = array($this->user_id);
$statement = $ilDB->manipulateF('
DELETE FROM mail_obj_data WHERE user_id = %s',
array('integer'), array($this->user_id)
);
$statement = $ilDB->manipulateF('
DELETE FROM mail_options WHERE user_id = %s',
array('integer'), array($this->user_id)
);
$statement = $ilDB->manipulateF('
DELETE FROM mail_saved WHERE user_id = %s',
array('integer'), array($this->user_id)
);
$statement = $ilDB->manipulateF('
DELETE FROM mail_tree WHERE tree = %s',
array('integer'), array($this->user_id)
);
return true;
}
ilMailbox::deleteFolder (   $a_folder_id)

add folder

Parameters
integerid of parent folder public

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

References $ilDB, $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 409 of file class.ilMailbox.php.

References $ilDB, $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 238 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::getDraftsFolder ( )

get Id of the inbox folder of an user public

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

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

{
global $ilDB;
$res = $ilDB->queryf('
SELECT * FROM '.$this->table_mail_obj_data.'
WHERE user_id = %s
AND m_type = %s',
array('integer', 'text'),
array($this->user_id, 'drafts'));
return $row->obj_id;
}
ilMailbox::getFolderData (   $a_obj_id)

get data of a specific folder

Parameters
intid of parent folder public

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

References $ilDB, $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(
"title" => stripslashes($row->title),
"type" => $row->m_type
);
}

+ Here is the caller graph for this function:

ilMailbox::getInboxFolder ( )

get Id of the inbox folder of an user public

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

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

{
global $ilDB;
$res = $ilDB->queryf('
SELECT * FROM '.$this->table_mail_obj_data.'
WHERE user_id = %s
AND m_type = %s',
array('integer', 'text'),
array($this->user_id, 'inbox'));
return $row->obj_id;
}
ilMailbox::getLastInsertId ( )

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

References $ilDB.

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

get id of parent folder

Parameters
integerid of folder public

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

References $ilDB, $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 226 of file class.ilMailbox.php.

Referenced by getSubFolders().

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

+ Here is the caller graph for this function:

ilMailbox::getSentFolder ( )

get Id of the sent folder of an user public

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

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

{
global $ilDB;
$res = $ilDB->queryf('
SELECT * FROM '.$this->table_mail_obj_data.'
WHERE user_id = %s
AND m_type = %s',
array('integer', 'text'),
array($this->user_id, 'sent'));
return $row->obj_id;
}
ilMailbox::getSubFolders (   $a_folder = 0,
  $a_folder_parent = 0 
)

get all folders under given node

Parameters
integerobj_id
integerparent_id public

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

References $ilDB, $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::getTrashFolder ( )

get Id of the trash folder of an user public

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

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

{
global $ilDB;
$res = $ilDB->queryf('
SELECT * FROM '.$this->table_mail_obj_data.'
WHERE user_id = %s
AND m_type = %s',
array('integer', 'text'),
array($this->user_id, 'trash'));
return $row->obj_id;
}
ilMailbox::ilMailbox (   $a_user_id = 0)

Constructor.

Parameters
integeruser_id of mailbox public

Definition at line 99 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");
}
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 384 of file class.ilMailbox.php.

References $ilDB, and 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 593 of file class.ilMailbox.php.

{
$this->user_id = $a_user_id;
}
ilMailbox::updateMailsOfDeletedUser ( )

Update existing mails.

Set sender id to null and import name to login name. This is only necessary for deleted users.

public

Returns
boolean true on successful deletion

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

References $ilDB, $user_id, and ilObjectFactory\getInstanceByObjId().

{
global $ilDB;
$tmp_user =& ilObjectFactory::getInstanceByObjId($this->user_id,false);
$statement = $ilDB->manipulateF('
UPDATE mail
SET sender_id = %s,
import_name = %s
WHERE sender_id = %s',
array('integer', 'text', 'integer'),
array('0', $tmp_user->getLogin(), $this->user_id));
return true;
}

+ Here is the call graph for this function:

Field Documentation

ilMailbox::$actions

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

Referenced by getActions().

ilMailbox::$default_folder

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

ilMailbox::$ilias

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

Referenced by _countNewMails(), and ilMailbox().

ilMailbox::$lng

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

Referenced by ilMailbox().

ilMailbox::$mtree

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

ilMailbox::$table_mail_obj_data

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

ilMailbox::$table_tree

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

ilMailbox::$user_id

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

Referenced by updateMailsOfDeletedUser().


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