ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailGlobalServices.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
21  const CACHE_TYPE_REF_ID = 0;
22 
31 
41  protected static $global_mail_services_cache = array();
42 
52  public static function getMailObjectRefId()
53  {
54  global $ilDB;
55 
56  if(isset(self::$global_mail_services_cache[CACHE_TYPE_REF_ID]) &&
57  null !== self::$global_mail_services_cache[CACHE_TYPE_REF_ID])
58  {
59  return self::$global_mail_services_cache[CACHE_TYPE_REF_ID];
60  }
61 
62  // mail settings id is set by a constant in ilias.ini. Keep the select for some time until everyone has updated his ilias.ini
63  if(!MAIL_SETTINGS_ID)
64  {
65  $res = $ilDB->queryf('
66  SELECT object_reference.ref_id FROM object_reference, tree, object_data
67  WHERE tree.parent = %s
68  AND object_data.type = %s
69  AND object_reference.ref_id = tree.child
70  AND object_reference.obj_id = object_data.obj_id',
71  array('integer', 'text'),
72  array(SYSTEM_FOLDER_ID, 'mail'));
73 
74  while($row = $ilDB->fetchAssoc($res))
75  {
76  self::$global_mail_services_cache[CACHE_TYPE_REF_ID] = $row['ref_id'];
77  }
78  }
79  else
80  {
81  self::$global_mail_services_cache[CACHE_TYPE_REF_ID] = MAIL_SETTINGS_ID;
82  }
83 
84  return self::$global_mail_services_cache[CACHE_TYPE_REF_ID];
85  }
86 
97  public static function getNumberOfNewMailsByUserId($usr_id)
98  {
99  global $ilDB;
100 
101  if(!$usr_id)
102  {
103  return 0;
104  }
105 
106  if(isset(self::$global_mail_services_cache[CACHE_TYPE_NEW_MAILS][$usr_id]) &&
107  null !== self::$global_mail_services_cache[CACHE_TYPE_NEW_MAILS][$usr_id])
108  {
109  return self::$global_mail_services_cache[CACHE_TYPE_NEW_MAILS][$usr_id];
110  }
111 
112  // Read system mails
113  $res = $ilDB->queryf('
114  SELECT COUNT(mail_id) cnt FROM mail
115  WHERE folder_id = %s
116  AND user_id = %s
117  AND m_status = %s',
118  array('integer', 'integer', 'text'),
119  array('0', $usr_id, 'unread'));
120 
121  $row = $ilDB->fetchAssoc($res);
122 
123  $res = $ilDB->queryf('
124  SELECT COUNT(mail_id) cnt FROM mail m,mail_obj_data mo
125  WHERE m.user_id = mo.user_id
126  AND m.folder_id = mo.obj_id
127  AND mo.m_type = %s
128  AND m.user_id = %s
129  AND m.m_status = %s',
130  array('text', 'integer', 'text'),
131  array('inbox', $usr_id, 'unread'));
132 
133 
134  $row2 = $ilDB->fetchAssoc($res);
135 
136  self::$global_mail_services_cache[CACHE_TYPE_NEW_MAILS][$usr_id] = $row['cnt'] + $row2['cnt'];
137 
138  return self::$global_mail_services_cache[CACHE_TYPE_NEW_MAILS][$usr_id];
139  }
140 }