ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 
 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...
 

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

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

260 {
261 if ($this->folderNameExists($a_folder_name)) {
262 return 0;
263 }
264
265 $next_id = $this->db->nextId($this->table_mail_obj_data);
266 $this->db->manipulateF(
267 '
268 INSERT INTO ' . $this->table_mail_obj_data . '
269 ( obj_id,
270 user_id,
271 title,
272 m_type
273 )
274 VALUES(%s,%s,%s,%s)',
275 array('integer','integer', 'text', 'text'),
276 array($next_id, $this->user_id, $a_folder_name, 'user_folder')
277 );
278 $this->mtree->insertNode($next_id, $a_parent_id);
279
280 return $next_id;
281 }
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 218 of file class.ilMailbox.php.

219 {
220 $root_id = $this->db->nextId($this->table_mail_obj_data);
221 $this->db->manipulateF(
222 '
223 INSERT INTO ' . $this->table_mail_obj_data . '
224 ( obj_id,
225 user_id,
226 title,
227 m_type
228 )
229 VALUES(%s, %s, %s, %s)',
230 array('integer','integer', 'text', 'text'),
231 array($root_id, $this->user_id, 'a_root', 'root')
232 );
233 $this->mtree->addTree($this->user_id, $root_id);
234
235 foreach ($this->default_folder as $key => $folder) {
236 $last_id = $this->db->nextId($this->table_mail_obj_data);
237 $this->db->manipulateF(
238 '
239 INSERT INTO ' . $this->table_mail_obj_data . '
240 ( obj_id,
241 user_id,
242 title,
243 m_type
244 )
245 VALUES(%s, %s, %s, %s)',
246 array('integer','integer', 'text', 'text'),
247 array($last_id, $this->user_id, $key, $folder)
248 );
249 $this->mtree->insertNode($last_id, $root_id);
250 }
251 }
$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 485 of file class.ilMailbox.php.

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

◆ deleteFolder()

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

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

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

313 {
314 $res = $this->db->queryF(
315 '
316 SELECT obj_id FROM ' . $this->table_mail_obj_data . '
317 WHERE user_id = %s
318 AND title = %s',
319 array('integer', 'text'),
320 array($this->user_id, $a_folder_name)
321 );
322 $row = $this->db->fetchAssoc($res);
323
324 return is_array($row) && $row['obj_id'] > 0 ? true : false;
325 }
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 201 of file class.ilMailbox.php.

202 {
203 if ($a_mobj_id) {
204 $folder_data = $this->getFolderData($a_mobj_id);
205
206 if ($folder_data["type"] == "user_folder" or $folder_data["type"] == "local") {
207 #return array_merge($this->actions,array("add" => $this->lng->txt("mail_add_subfolder")));
208 return $this->actions;
209 }
210 }
211
212 return $this->actions;
213 }
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 132 of file class.ilMailbox.php.

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

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

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

References $res, and $row.

Referenced by getActions().

+ Here is the caller graph for this function:

◆ getInboxFolder()

ilMailbox::getInboxFolder ( )

get Id of the inbox folder of an user

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

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

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

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

References $res, and $row.

◆ getRootFolderId()

ilMailbox::getRootFolderId ( )

get Id of the root folder of an user

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

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

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

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

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

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

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

References $res, and $row.

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

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

References folderNameExists().

+ Here is the call graph for this function:

◆ setUserId()

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

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

475 {
476 $this->user_id = $a_user_id;
477 }

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

536 {
537 $this->db->manipulateF(
538 '
539 UPDATE mail
540 SET sender_id = %s, import_name = %s
541 WHERE sender_id = %s',
542 array('integer', 'text', 'integer'),
543 array(0, $nameToShow, $this->user_id)
544 );
545 }

Field Documentation

◆ $actions

ilMailbox::$actions = array()
protected

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

Referenced by getActions().

◆ $db

ilMailbox::$db
protected

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

◆ $default_folder

ilMailbox::$default_folder = array()
protected

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

◆ $ilias

ilMailbox::$ilias
protected

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

◆ $lng

ilMailbox::$lng
protected

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

◆ $mtree

ilMailbox::$mtree
protected

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

◆ $table_mail_obj_data

ilMailbox::$table_mail_obj_data
protected

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

◆ $table_tree

ilMailbox::$table_tree
protected

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

◆ $user_id

ilMailbox::$user_id
protected

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


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