ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailBoxQuery Class Reference

Mail query class. More...

+ Collaboration diagram for ilMailBoxQuery:

Static Public Member Functions

static _getMailBoxListData ()
 _getMailBoxListData More...
 

Static Public Attributes

static $folderId = -1
 
static $userId = -1
 
static $limit = 0
 
static $offset = 0
 
static $orderDirection = ''
 
static $orderColumn = ''
 
static $filter = array()
 
static $filtered_ids = array()
 

Detailed Description

Mail query class.

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

Definition at line 12 of file class.ilMailBoxQuery.php.

Member Function Documentation

◆ _getMailBoxListData()

static ilMailBoxQuery::_getMailBoxListData ( )
static

_getMailBoxListData

@access public

Returns
array Array of mails

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

32 {
33 global $DIC;
34
35 $mails = ['cnt' => 0, 'cnt_unread' => 0, 'set' => []];
36
37 $filter = [
38 'mail_filter_sender' => 'CONCAT(CONCAT(firstname, lastname), login)',
39 'mail_filter_recipients' => 'CONCAT(CONCAT(rcp_to, rcp_cc), rcp_bcc)',
40 'mail_filter_subject' => 'm_subject',
41 'mail_filter_body' => 'm_message',
42 'mail_filter_attach' => ''
43 ];
44
45 $filter_parts = [];
46 if (isset(self::$filter['mail_filter']) && strlen(self::$filter['mail_filter'])) {
47 foreach ($filter as $key => $column) {
48 if (strlen($column) && isset(self::$filter[$key]) && (int) self::$filter[$key]) {
49 $filter_parts[] = $DIC->database()->like(
50 $column,
51 'text',
52 '%%' . self::$filter['mail_filter'] . '%%',
53 false
54 );
55 }
56 }
57 }
58
59 $filter_qry = '';
60 if ($filter_parts) {
61 $filter_qry = 'AND (' . implode(' OR ', $filter_parts) . ')';
62 }
63
64 if (isset(self::$filter['mail_filter_only_unread']) && self::$filter['mail_filter_only_unread']) {
65 $filter_qry .= ' AND m_status = ' . $DIC->database()->quote('unread', 'text') . ' ';
66 }
67
68 if (isset(self::$filter['mail_filter_only_with_attachments']) && self::$filter['mail_filter_only_with_attachments']) {
69 $filter_qry .= ' AND attachments != ' . $DIC->database()->quote(serialize(null), 'text') . ' ';
70 }
71
72 if (isset(self::$filter['period']) && is_array(self::$filter['period'])) {
73 $dateFilterParts = [];
74
75 if (null !== self::$filter['period']['start']) {
76 $dateFilterParts[] = 'send_time >= ' . $DIC->database()->quote(
77 (new \DateTimeImmutable('@' . self::$filter['period']['start']))->format('Y-m-d 00:00:00'),
78 'timestamp'
79 );
80 }
81
82 if (null !== self::$filter['period']['end']) {
83 $dateFilterParts[] = 'send_time <= ' . $DIC->database()->quote(
84 (new \DateTimeImmutable('@' . self::$filter['period']['end']))->format('Y-m-d 23:59:59'),
85 'timestamp'
86 );
87 }
88
89 if (count($dateFilterParts) > 0) {
90 $filter_qry .= ' AND (' . implode(' AND ', $dateFilterParts) . ') ';
91 }
92 }
93
94 // count query
95 $queryCount = 'SELECT COUNT(mail_id) cnt FROM mail '
96 . 'LEFT JOIN usr_data ON usr_id = sender_id '
97 . 'WHERE user_id = %s '
98 . 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND usr_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL)) '
99 . 'AND folder_id = %s '
100 . $filter_qry;
101
102 if (self::$filtered_ids) {
103 $queryCount .= ' AND ' . $DIC->database()->in('mail_id', self::$filtered_ids, false, 'integer') . ' ';
104 }
105
106 $queryCount .= ' UNION ALL '
107 . 'SELECT COUNT(mail_id) cnt FROM mail '
108 . 'LEFT JOIN usr_data ON usr_id = sender_id '
109 . 'WHERE user_id = %s '
110 . 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND usr_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL)) '
111 . 'AND folder_id = %s '
112 . $filter_qry . ' '
113 . 'AND m_status = %s';
114
115 if (self::$filtered_ids) {
116 $queryCount .= ' AND ' . $DIC->database()->in('mail_id', self::$filtered_ids, false, 'integer') . ' ';
117 }
118
119 $res = $DIC->database()->queryF(
120 $queryCount,
121 ['integer', 'integer', 'integer', 'integer', 'text'],
122 [self::$userId, self::$folderId, self::$userId, self::$folderId, 'unread']
123 );
124
125 $counter = 0;
126 while ($cnt_row = $DIC->database()->fetchAssoc($res)) {
127 if ($counter === 0) {
128 $mails['cnt'] = $cnt_row['cnt'];
129 } else {
130 if ($counter === 1) {
131 $mails['cnt_unread'] = $cnt_row['cnt'];
132 } else {
133 break;
134 }
135 }
136
137 ++$counter;
138 }
139
140 $sortColumn = '';
141 $firstnameSelection = '';
142 if (self::$orderColumn === 'from') {
143 // Because of the user id of automatically generated mails and ordering issues we have to do some magic
144 $firstnameSelection = '
145 ,(CASE
146 WHEN (usr_id = ' . ANONYMOUS_USER_ID . ') THEN firstname
147 ELSE ' . $DIC->database()->quote(ilMail::_getIliasMailerName(), 'text') . '
148 END) fname
149 ';
150 }
151
152 // item query
153 $query = 'SELECT mail.*' . $sortColumn . ' ' . $firstnameSelection . ' FROM mail '
154 . 'LEFT JOIN usr_data ON usr_id = sender_id '
155 . 'AND ((sender_id > 0 AND sender_id IS NOT NULL AND usr_id IS NOT NULL) OR (sender_id = 0 OR sender_id IS NULL)) '
156 . 'WHERE user_id = %s '
157 . $filter_qry . ' '
158 . 'AND folder_id = %s';
159
160 if (self::$filtered_ids) {
161 $query .= ' AND ' . $DIC->database()->in('mail_id', self::$filtered_ids, false, 'integer') . ' ';
162 }
163
164 $orderDirection = 'ASC';
165 if (in_array(strtolower(self::$orderDirection), array('desc', 'asc'))) {
167 }
168
169 if (self::$orderColumn === 'from') {
170 $query .= ' ORDER BY '
171 . ' fname ' . $orderDirection . ', '
172 . ' lastname ' . $orderDirection . ', '
173 . ' login ' . $orderDirection . ', '
174 . ' import_name ' . $orderDirection;
175 } elseif (strlen(self::$orderColumn) > 0) {
176 if (
177 !in_array(strtolower(self::$orderColumn), ['m_subject', 'send_time', 'rcp_to']) &&
178 !$DIC->database()->tableColumnExists('mail', strtolower(self::$orderColumn))) {
179 // @todo: Performance problem...
180 self::$orderColumn = 'send_time';
181 }
182
183 $query .= ' ORDER BY ' . strtolower(self::$orderColumn) . ' ' . $orderDirection;
184 } else {
185 $query .= ' ORDER BY send_time DESC';
186 }
187
188 $DIC->database()->setLimit(self::$limit, self::$offset);
189 $res = $DIC->database()->queryF(
190 $query,
191 ['integer', 'integer'],
192 [self::$userId, self::$folderId]
193 );
194 while ($row = $DIC->database()->fetchAssoc($res)) {
195 $row['attachments'] = unserialize(stripslashes($row['attachments']));
196 $row['m_type'] = unserialize(stripslashes($row['m_type']));
197 $mails['set'][] = $row;
198 }
199
200 return $mails;
201 }
$key
Definition: croninfo.php:18
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res

References $DIC, $filter, $key, $orderDirection, $query, $res, and $row.

Referenced by ilMailFolderTableGUI\fetchTableData().

+ Here is the caller graph for this function:

Field Documentation

◆ $filter

ilMailBoxQuery::$filter = array()
static

◆ $filtered_ids

ilMailBoxQuery::$filtered_ids = array()
static

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

Referenced by ilMailFolderTableGUI\fetchTableData().

◆ $folderId

ilMailBoxQuery::$folderId = -1
static

Definition at line 14 of file class.ilMailBoxQuery.php.

Referenced by ilMailFolderTableGUI\fetchTableData().

◆ $limit

ilMailBoxQuery::$limit = 0
static

Definition at line 16 of file class.ilMailBoxQuery.php.

Referenced by ilMailFolderTableGUI\fetchTableData().

◆ $offset

ilMailBoxQuery::$offset = 0
static

Definition at line 17 of file class.ilMailBoxQuery.php.

Referenced by ilMailFolderTableGUI\fetchTableData().

◆ $orderColumn

ilMailBoxQuery::$orderColumn = ''
static

Definition at line 19 of file class.ilMailBoxQuery.php.

Referenced by ilMailFolderTableGUI\fetchTableData().

◆ $orderDirection

ilMailBoxQuery::$orderDirection = ''
static

◆ $userId

ilMailBoxQuery::$userId = -1
static

Definition at line 15 of file class.ilMailBoxQuery.php.

Referenced by ilMailFolderTableGUI\fetchTableData().


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