ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $left_interval=0)
 

Data Fields

final const int CACHE_TYPE_REF_ID = 0
 
final const int 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.

Definition at line 28 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 self::$global_mail_services_cache[self::CACHE_TYPE_REF_ID] !== null) {
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
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26

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

Referenced by ilMailUserActionProvider\checkUserMailAccess(), ilMailSearchObjectGUI\doesExposeMembers(), ILIAS\User\Profile\PublicProfileGUI\getEmbeddable(), ilAccessibilitySupportContactsGUI\getFooterLink(), ilMailAddressTypeHelperImpl\getGlobalMailSystemId(), ILIAS\Mail\Provider\MailMainBarProvider\getStaticSubItems(), ilObjCourseGUI\infoScreen(), ilTutorialSupportBlockGUI\isIliasInternalMailEnabled(), ilMailSearchObjectGUI\mailObjects(), ilContactGUI\mailToUsers(), ilMail\readMailObjectReferenceId(), and ilContactGUI\showContacts().

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

◆ getNewMailsData()

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

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

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

References $DIC, $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

final const int ilMailGlobalServices::CACHE_TYPE_NEW_MAILS = 1

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

◆ CACHE_TYPE_REF_ID

final const int ilMailGlobalServices::CACHE_TYPE_REF_ID = 0

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