ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
55 
56  if (isset(self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID]) &&
57  null !== self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID]) {
58  return self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID];
59  }
60 
61  // mail settings id is set by a constant in ilias.ini. Keep the select for some time until everyone has updated his ilias.ini
62  if (!MAIL_SETTINGS_ID) {
63  $res = $DIC->database()->queryF(
64  '
65  SELECT object_reference.ref_id FROM object_reference, tree, object_data
66  WHERE tree.parent = %s
67  AND object_data.type = %s
68  AND object_reference.ref_id = tree.child
69  AND object_reference.obj_id = object_data.obj_id',
70  array('integer', 'text'),
71  array(SYSTEM_FOLDER_ID, 'mail')
72  );
73 
74  while ($row = $DIC->database()->fetchAssoc($res)) {
75  self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID] = $row['ref_id'];
76  }
77  } else {
78  self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID] = MAIL_SETTINGS_ID;
79  }
80 
81  return self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID];
82  }
83 
94  public static function getNumberOfNewMailsByUserId($usr_id)
95  {
96  global $DIC;
97 
98  if (!$usr_id) {
99  return 0;
100  }
101 
102  if (
103  isset(self::$global_mail_services_cache[self::CACHE_TYPE_NEW_MAILS][$usr_id]) &&
104  null !== self::$global_mail_services_cache[self::CACHE_TYPE_NEW_MAILS][$usr_id]) {
105  return self::$global_mail_services_cache[self::CACHE_TYPE_NEW_MAILS][$usr_id];
106  }
107 
108  $res = $DIC->database()->queryF(
109  '
110  SELECT COUNT(mail_id) cnt FROM mail
111  WHERE folder_id = %s
112  AND user_id = %s
113  AND m_status = %s',
114  array('integer', 'integer', 'text'),
115  array('0', $usr_id, 'unread')
116  );
117 
118  $row = $DIC->database()->fetchAssoc($res);
119 
120  $res = $DIC->database()->queryF(
121  '
122  SELECT COUNT(mail_id) cnt FROM mail m,mail_obj_data mo
123  WHERE m.user_id = mo.user_id
124  AND m.folder_id = mo.obj_id
125  AND mo.m_type = %s
126  AND m.user_id = %s
127  AND m.m_status = %s',
128  array('text', 'integer', 'text'),
129  array('inbox', $usr_id, 'unread')
130  );
131 
132  $row2 = $DIC->database()->fetchAssoc($res);
133 
134  self::$global_mail_services_cache[self::CACHE_TYPE_NEW_MAILS][$usr_id] = $row['cnt'] + $row2['cnt'];
135  return self::$global_mail_services_cache[self::CACHE_TYPE_NEW_MAILS][$usr_id];
136  }
137 }
Class for global mail information (e.g.
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$row
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable...
static getNumberOfNewMailsByUserId($usr_id)
Determines the number of new mails for the passed user id and stores this information in a local cach...