ILIAS  release_7 Revision v7.30-3-g800a261c036
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{
22
31
41 protected static $global_mail_services_cache = array();
42
52 public static function getMailObjectRefId() : int
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 (int) 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 (int) self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID];
82 }
83
95 public static function getNewMailsData(int $usr_id, int $leftInterval = 0) : array
96 {
97 global $DIC;
98
99 if (!$usr_id) {
100 return 0;
101 }
102
103 $cacheKey = implode('_', [self::CACHE_TYPE_NEW_MAILS, $usr_id, $leftInterval]);
104
105 if (
106 isset(self::$global_mail_services_cache[$cacheKey]) &&
107 null !== self::$global_mail_services_cache[$cacheKey]) {
108 return self::$global_mail_services_cache[$cacheKey];
109 }
110
111 $query = '
112 SELECT COUNT(mail_id) cnt, MAX(send_time) send_time
113 FROM mail
114 WHERE folder_id = %s AND user_id = %s AND m_status = %s
115 ';
116 if ($leftInterval > 0) {
117 $query .= ' AND send_time > ' . $DIC->database()->quote(date('Y-m-d H:i:s', $leftInterval), 'timestamp');
118 }
119
120 $res = $DIC->database()->queryF(
121 $query,
122 ['integer', 'integer', 'text'],
123 [0, $usr_id, 'unread']
124 );
125 $row = $DIC->database()->fetchAssoc($res);
126
127 $query = '
128 SELECT COUNT(mail_id) cnt, MAX(m.send_time) send_time
129 FROM mail m
130 INNER JOIN mail_obj_data mo
131 ON mo.user_id = m.user_id
132 AND mo.obj_id = m.folder_id
133 AND mo.m_type = %s
134 WHERE m.user_id = %s
135 AND m.m_status = %s';
136 if ($leftInterval > 0) {
137 $query .= ' AND m.send_time > ' . $DIC->database()->quote(date('Y-m-d H:i:s', $leftInterval), 'timestamp');
138 }
139
140 $res = $DIC->database()->queryF(
141 $query,
142 ['text', 'integer', 'text'],
143 ['inbox', $usr_id, 'unread']
144 );
145 $row2 = $DIC->database()->fetchAssoc($res);
146
147 self::$global_mail_services_cache[$cacheKey] = [
148 'count' => (int) ($row['cnt'] + $row2['cnt']),
149 'max_time' => max(
150 (string) $row['send_time'],
151 (string) $row2['send_time']
152 ),
153 ];
154
155 return self::$global_mail_services_cache[$cacheKey];
156 }
157}
An exception for terminatinating execution or to throw for unit testing.
Class for global mail information (e.g.
static getMailObjectRefId()
Determines the reference id of the mail object and stores this information in a local cache variable.
static getNewMailsData(int $usr_id, int $leftInterval=0)
Determines the number of new mails for the passed user id and stores this information in a local cach...
const MAIL_SETTINGS_ID
Definition: constants.php:34
const SYSTEM_FOLDER_ID
Definition: constants.php:33
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res