34 $mails = array(
'cnt' => 0,
'cnt_unread' => 0,
'set' => array());
37 $queryCount =
'SELECT COUNT(mail_id) cnt FROM mail '
38 .
'LEFT JOIN usr_data ON usr_id = sender_id '
39 .
'WHERE user_id = %s '
40 .
'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)) '
41 .
'AND folder_id = %s '
43 .
'SELECT COUNT(mail_id) cnt FROM mail '
44 .
'LEFT JOIN usr_data ON usr_id = sender_id '
45 .
'WHERE user_id = %s '
46 .
'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)) '
47 .
'AND folder_id = %s '
48 .
'AND m_status = %s';
52 array(
'integer',
'integer',
'integer',
'integer',
'text'),
53 array(self::$userId, self::$folderId, self::$userId, self::$folderId,
'unread')
56 while($cnt_row = $ilDB->fetchAssoc(
$res))
60 $mails[
'cnt'] = $cnt_row[
'cnt'];
62 else if($counter == 1)
64 $mails[
'cnt_unread'] = $cnt_row[
'cnt'];
75 if(self::$orderColumn ==
'rcp_to' && $ilDB->getDBType() ==
'oracle')
77 $sortColumn =
", CAST(rcp_to AS VARCHAR2(4000)) SORTCOL";
81 $query =
'SELECT mail.*'.$sortColumn.
' FROM mail '
82 .
'LEFT JOIN usr_data ON usr_id = sender_id '
83 .
'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)) '
84 .
'WHERE user_id = %s '
85 .
'AND folder_id = %s';
89 if(in_array(strtolower(self::$orderDirection), array(
'desc',
'asc')))
99 if(self::$orderColumn ==
'rcp_to' && $ilDB->getDBType() ==
'oracle')
101 $query .=
' ORDER BY SORTCOL '.$orderDirection;
103 else if(strlen(self::$orderColumn) &&
104 $ilDB->tableColumnExists(
'mail', strtolower(self::$orderColumn)))
108 else if(self::$orderColumn ==
'from')
111 .
' firstname '.$orderDirection.
', '
112 .
' lastname '.$orderDirection.
', '
113 .
' login '.$orderDirection.
', '
114 .
' import_name '.$orderDirection;
118 $query .=
' ORDER BY send_time DESC';
121 $ilDB->setLimit(self::$limit, self::$offset);
122 $res = $ilDB->queryf(
124 array(
'integer',
'integer'),
125 array(self::$userId, self::$folderId)
127 while(
$row = $ilDB->fetchAssoc(
$res))
129 $row[
'attachments'] = unserialize(stripslashes(
$row[
'attachments']));
130 $row[
'm_type'] = unserialize(stripslashes(
$row[
'm_type']));
131 $mails[
'set'][] =
$row;