ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 = array('cnt' => 0, 'cnt_unread' => 0, 'set' => array());
36
37 $filter = array(
38 'mail_filter_sender' => 'CONCAT(CONCAT(firstname, lastname), login)',
39 'mail_filter_recipients' => ($DIC->database()->getDBType() == 'oracle' ?
40 "CONCAT(CONCAT(CAST(rcp_to AS VARCHAR2(4000)), CAST(rcp_cc AS VARCHAR2(4000))), CAST(rcp_bcc AS VARCHAR2(4000))))" :
41 "CONCAT(CONCAT(rcp_to, rcp_cc), rcp_bcc)"),
42 'mail_filter_subject' => 'm_subject',
43 'mail_filter_body' => 'm_message',
44 'mail_filter_attach' => ''
45 );
46 $filter_parts = array();
47 if (isset(self::$filter['mail_filter']) && strlen(self::$filter['mail_filter'])) {
48 foreach ($filter as $key => $column) {
49 if (strlen($column) && isset(self::$filter[$key]) && (int) self::$filter[$key]) {
50 $filter_parts[] = $DIC->database()->like($column, 'text', '%%' . self::$filter['mail_filter'] . '%%', false);
51 }
52 }
53 }
54 $filter_qry = '';
55 if ($filter_parts) {
56 $filter_qry = 'AND (' . implode(' OR ', $filter_parts) . ')';
57 }
58 // count query
59 $queryCount = 'SELECT COUNT(mail_id) cnt FROM mail '
60 . 'LEFT JOIN usr_data ON usr_id = sender_id '
61 . 'WHERE user_id = %s '
62 . '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)) '
63 . 'AND folder_id = %s '
64 . $filter_qry . ' '
65 . 'UNION ALL '
66 . 'SELECT COUNT(mail_id) cnt FROM mail '
67 . 'LEFT JOIN usr_data ON usr_id = sender_id '
68 . 'WHERE user_id = %s '
69 . '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)) '
70 . 'AND folder_id = %s '
71 . $filter_qry . ' '
72 . 'AND m_status = %s';
73
74 if (self::$filtered_ids) {
75 $queryCount .= ' AND ' . $DIC->database()->in('mail_id', self::$filtered_ids, false, 'integer') . ' ';
76 }
77
78 $res = $DIC->database()->queryf(
79 $queryCount,
80 array('integer', 'integer', 'integer', 'integer', 'text'),
81 array(self::$userId, self::$folderId, self::$userId, self::$folderId, 'unread')
82 );
83 $counter = 0;
84 while ($cnt_row = $DIC->database()->fetchAssoc($res)) {
85 if ($counter == 0) {
86 $mails['cnt'] = $cnt_row['cnt'];
87 } elseif ($counter == 1) {
88 $mails['cnt_unread'] = $cnt_row['cnt'];
89 } else {
90 break;
91 }
92
93 ++$counter;
94 }
95
96 $sortColumn = '';
97 if (self::$orderColumn == 'rcp_to' && $DIC->database()->getDBType() == 'oracle') {
98 $sortColumn = ", CAST(rcp_to AS VARCHAR2(4000)) SORTCOL";
99 }
100
101 $firstname = '';
102 if (self::$orderColumn == 'from') {
103 // Because of the user id of automatically generated mails and ordering issues we have to do some magic
104 $firstname = '
105 ,(CASE
106 WHEN (usr_id = ' . ANONYMOUS_USER_ID . ') THEN firstname
107 ELSE ' . $DIC->database()->quote(ilMail::_getIliasMailerName(), 'text') . '
108 END) fname
109 ';
110 }
111
112 // item query
113 $query = 'SELECT mail.*' . $sortColumn . ' ' . $firstname . ' FROM mail '
114 . 'LEFT JOIN usr_data ON usr_id = sender_id '
115 . '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)) '
116 . 'WHERE user_id = %s '
117 . $filter_qry . ' '
118 . 'AND folder_id = %s';
119
120 if (self::$filtered_ids) {
121 $query .= ' AND ' . $DIC->database()->in('mail_id', self::$filtered_ids, false, 'integer') . ' ';
122 }
123
124 // order direction
125 $orderDirection = '';
126 if (in_array(strtolower(self::$orderDirection), array('desc', 'asc'))) {
128 } else {
129 $orderDirection = 'ASC';
130 }
131
132 // order column
133 if (self::$orderColumn == 'rcp_to' && $DIC->database()->getDBType() == 'oracle') {
134 $query .= ' ORDER BY SORTCOL ' . $orderDirection;
135 } elseif (self::$orderColumn == 'from') {
136 $query .= ' ORDER BY '
137 . ' fname ' . $orderDirection . ', '
138 . ' lastname ' . $orderDirection . ', '
139 . ' login ' . $orderDirection . ', '
140 . ' import_name ' . $orderDirection;
141 } elseif (strlen(self::$orderColumn)) {
142 if (!in_array(strtolower(self::$orderColumn), array('m_subject', 'send_time', 'rcp_to')) &&
143 !$DIC->database()->tableColumnExists('mail', strtolower(self::$orderColumn))) {
144 // @todo: Performance problem...
145 self::$orderColumn = 'send_time';
146 }
147
148 $query .= ' ORDER BY ' . strtolower(self::$orderColumn) . ' ' . $orderDirection;
149 } else {
150 $query .= ' ORDER BY send_time DESC';
151 }
152
153 $DIC->database()->setLimit(self::$limit, self::$offset);
154 $res = $DIC->database()->queryF(
155 $query,
156 array('integer', 'integer'),
157 array(self::$userId, self::$folderId)
158 );
159 while ($row = $DIC->database()->fetchAssoc($res)) {
160 $row['attachments'] = unserialize(stripslashes($row['attachments']));
161 $row['m_type'] = unserialize(stripslashes($row['m_type']));
162 $mails['set'][] = $row;
163 }
164
165 return $mails;
166 }
$column
Definition: 39dropdown.php:62
$counter
$key
Definition: croninfo.php:18
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res

References $column, $counter, $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: