ILIAS  release_7 Revision v7.30-3-g800a261c036
ilMailGlobalServices Class Reference

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

+ Collaboration diagram for ilMailGlobalServices:

Static Public Member Functions

static getMailObjectRefId ()
 Determines the reference id of the mail object and stores this information in a local cache variable. More...
 
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 cache variable. More...
 

Data Fields

const CACHE_TYPE_REF_ID = 0
 
const CACHE_TYPE_NEW_MAILS = 1
 

Static Protected Attributes

static $global_mail_services_cache = array()
 

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 12 of file class.ilMailGlobalServices.php.

Member Function Documentation

◆ getMailObjectRefId()

static ilMailGlobalServices::getMailObjectRefId ( )
static

Determines the reference id of the mail object and stores this information in a local cache variable.

@access public

Returns
integer The reference id of the mail object

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

52 : 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 }
const MAIL_SETTINGS_ID
Definition: constants.php:34
const SYSTEM_FOLDER_ID
Definition: constants.php:33
global $DIC
Definition: goto.php:24
foreach($_POST as $key=> $value) $res

References $DIC, $res, CACHE_TYPE_REF_ID, MAIL_SETTINGS_ID, and SYSTEM_FOLDER_ID.

Referenced by ilBuddySystemRelationsTableGUI\__construct(), ilMailUserActionProvider\checkUserMailAccess(), ilPersonalSettingsGUI\executeCommand(), ilPublicUserProfileGUI\getEmbeddable(), ilAccessibilitySupportContactsGUI\getFooterLink(), ilMailAddressTypeHelperImpl\getGlobalMailSystemId(), ILIAS\Mail\Provider\MailNotificationProvider\getNotifications(), ILIAS\Mail\Provider\MailMainBarProvider\getStaticSubItems(), ilMailSearchCoursesGUI\mailCourses(), ilMailSearchGroupsGUI\mailGroups(), ilContactGUI\mailToUsers(), and ilMail\readMailObjectReferenceId().

+ Here is the caller graph for this function:

◆ getNewMailsData()

static ilMailGlobalServices::getNewMailsData ( int  $usr_id,
int  $leftInterval = 0 
)
static

Determines the number of new mails for the passed user id and stores this information in a local cache variable.

@access public

Parameters
$usr_id
int$leftInterval
Returns
integer The number on unread mails (system messages + inbox mails) for the passed user id

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

95 : 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 }
$query

References $DIC, $query, and $res.

Referenced by ILIAS\Mail\Provider\MailNotificationProvider\getNotifications(), and ilSoapUserAdministration\hasNewMail().

+ Here is the caller graph for this function:

Field Documentation

◆ $global_mail_services_cache

ilMailGlobalServices::$global_mail_services_cache = array()
staticprotected

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

◆ CACHE_TYPE_NEW_MAILS

const ilMailGlobalServices::CACHE_TYPE_NEW_MAILS = 1

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

◆ CACHE_TYPE_REF_ID

const ilMailGlobalServices::CACHE_TYPE_REF_ID = 0

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

Referenced by getMailObjectRefId().


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