ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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

final const CACHE_TYPE_REF_ID = 0
 
final 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 36 of file class.ilMailGlobalServices.php.

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

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

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

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

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

Referenced by ilSoapUserAdministration\hasNewMail().

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

◆ CACHE_TYPE_NEW_MAILS

final const ilMailGlobalServices::CACHE_TYPE_NEW_MAILS = 1

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

◆ CACHE_TYPE_REF_ID

final const ilMailGlobalServices::CACHE_TYPE_REF_ID = 0

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


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