ILIAS  release_8 Revision v8.24
ilMailGlobalServices Class Reference

Class for global mail information (e.g. More...

+ Collaboration diagram for ilMailGlobalServices:

Static Public Member Functions

static getMailObjectRefId ()
 
static getNewMailsData (ilObjUser $user, int $leftInterval=0)
 

Data Fields

const CACHE_TYPE_REF_ID = 0
 
const CACHE_TYPE_NEW_MAILS = 1
 

Static Protected Attributes

static array $global_mail_services_cache = []
 

Detailed Description

Class for global mail information (e.g.

in main menu). This class should only contain methods for fetching data which is necessary in global parts of ILIAS, e.g. the main menu. We should keep this class as small as possible. Maybe we duplicate some code which already exists in class ilMail, but we need an efficient class.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

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

Member Function Documentation

◆ getMailObjectRefId()

static ilMailGlobalServices::getMailObjectRefId ( )
static

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

35 : int
36 {
37 global $DIC;
38
39 if (isset(self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID]) &&
40 null !== self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID]) {
41 return (int) self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID];
42 }
43
44 // mail settings id is set by a constant in ilias.ini.
45 // Keep the select for some time until everyone has updated his ilias.ini
46 if (!MAIL_SETTINGS_ID) {
47 $res = $DIC->database()->queryF(
48 '
49 SELECT object_reference.ref_id FROM object_reference, tree, object_data
50 WHERE tree.parent = %s
51 AND object_data.type = %s
52 AND object_reference.ref_id = tree.child
53 AND object_reference.obj_id = object_data.obj_id',
54 ['integer', 'text'],
55 [SYSTEM_FOLDER_ID, 'mail']
56 );
57
58 while ($row = $DIC->database()->fetchAssoc($res)) {
59 self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID] = (int) $row['ref_id'];
60 }
61 } else {
62 self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID] = MAIL_SETTINGS_ID;
63 }
64
65 return (int) self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID];
66 }
const MAIL_SETTINGS_ID
Definition: constants.php:36
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69

References $DIC, $res, CACHE_TYPE_REF_ID, ILIAS\Repository\int(), MAIL_SETTINGS_ID, and SYSTEM_FOLDER_ID.

Referenced by ilBuddySystemRelationsTableGUI\__construct(), ilPersonalSettingsGUI\__initSubTabs(), ilMailUserActionProvider\checkUserMailAccess(), ilMailSearchObjectGUI\doesExposeMembers(), ilPersonalSettingsGUI\executeCommand(), ilPublicUserProfileGUI\getEmbeddable(), ilAccessibilitySupportContactsGUI\getFooterLink(), ilMailAddressTypeHelperImpl\getGlobalMailSystemId(), ILIAS\Mail\Provider\MailMainBarProvider\getStaticSubItems(), ilObjCourseGUI\infoScreen(), ilMailSearchObjectGUI\mailObjects(), ilContactGUI\mailToUsers(), and ilMail\readMailObjectReferenceId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewMailsData()

static ilMailGlobalServices::getNewMailsData ( ilObjUser  $user,
int  $leftInterval = 0 
)
static
Parameters
ilObjUser$user
int$leftInterval
Returns
array{count: int, max_time: string}

Definition at line 73 of file class.ilMailGlobalServices.php.

73 : array
74 {
75 global $DIC;
76
77 if ($user->isAnonymous() || 0 === $user->getId()) {
78 return [
79 'count' => 0,
80 'max_time' => (new DateTimeImmutable('@' . time()))->format('Y-m-d H:i:s')
81 ];
82 }
83
84 $cacheKey = implode('_', [self::CACHE_TYPE_NEW_MAILS, $user->getId(), $leftInterval]);
85
86 if (
87 isset(self::$global_mail_services_cache[$cacheKey]) &&
88 null !== self::$global_mail_services_cache[$cacheKey]) {
89 return self::$global_mail_services_cache[$cacheKey];
90 }
91
92 $query = '
93 SELECT COUNT(mail_id) cnt, MAX(send_time) send_time
94 FROM mail
95 WHERE folder_id = %s AND user_id = %s AND m_status = %s
96 ';
97 if ($leftInterval > 0) {
98 $query .= ' AND send_time > '
99 . $DIC->database()->quote(date('Y-m-d H:i:s', $leftInterval), 'timestamp');
100 }
101
102 $res = $DIC->database()->queryF(
103 $query,
104 ['integer', 'integer', 'text'],
105 [0, $user->getId(), 'unread']
106 );
107 $row = $DIC->database()->fetchAssoc($res);
108
109 $query = '
110 SELECT COUNT(mail_id) cnt, MAX(m.send_time) send_time
111 FROM mail m
112 INNER JOIN mail_obj_data mo
113 ON mo.user_id = m.user_id
114 AND mo.obj_id = m.folder_id
115 AND mo.m_type = %s
116 WHERE m.user_id = %s
117 AND m.m_status = %s';
118 if ($leftInterval > 0) {
119 $query .= ' AND m.send_time > '
120 . $DIC->database()->quote(date('Y-m-d H:i:s', $leftInterval), 'timestamp');
121 }
122
123 $res = $DIC->database()->queryF(
124 $query,
125 ['text', 'integer', 'text'],
126 ['inbox', $user->getId(), 'unread']
127 );
128 $row2 = $DIC->database()->fetchAssoc($res);
129
130 self::$global_mail_services_cache[$cacheKey] = [
131 'count' => ((int) $row['cnt'] + (int) $row2['cnt']),
132 'max_time' => max(
133 (string) $row['send_time'],
134 (string) $row2['send_time']
135 ),
136 ];
137
138 return self::$global_mail_services_cache[$cacheKey];
139 }
$query

References $DIC, $query, $res, ilObject\getId(), ILIAS\Repository\int(), and ilObjUser\isAnonymous().

Referenced by ilSoapUserAdministration\hasNewMail().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $global_mail_services_cache

array ilMailGlobalServices::$global_mail_services_cache = []
staticprotected

Definition at line 33 of file class.ilMailGlobalServices.php.

◆ CACHE_TYPE_NEW_MAILS

const ilMailGlobalServices::CACHE_TYPE_NEW_MAILS = 1

Definition at line 32 of file class.ilMailGlobalServices.php.

◆ CACHE_TYPE_REF_ID

const ilMailGlobalServices::CACHE_TYPE_REF_ID = 0

Definition at line 31 of file class.ilMailGlobalServices.php.

Referenced by getMailObjectRefId().


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