2011-12-04 21:46:50 +00:00
|
|
|
<?php
|
2013-01-19 19:36:40 +00:00
|
|
|
namespace chat\data\message;
|
2011-12-04 21:46:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a list of chat messages.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2014-02-27 22:05:09 +00:00
|
|
|
* @copyright 2010-2014 Tim Düsterhus
|
2011-12-04 21:46:50 +00:00
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2013-01-19 19:36:40 +00:00
|
|
|
* @package be.bastelstu.chat
|
|
|
|
* @subpackage chat.room
|
2011-12-04 21:46:50 +00:00
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
class MessageList extends \wcf\data\DatabaseObjectList {
|
2011-12-04 21:46:50 +00:00
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\data\DatabaseObjectList::$className
|
2011-12-04 21:46:50 +00:00
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
public $className = 'chat\data\message\Message';
|
2011-12-04 21:46:50 +00:00
|
|
|
|
2011-12-26 15:31:37 +00:00
|
|
|
/**
|
|
|
|
* Reads the newest messages for the given room.
|
|
|
|
*
|
2013-01-19 19:36:40 +00:00
|
|
|
* @param \chat\data\room\Room $room
|
|
|
|
* @param integer $number
|
|
|
|
* @return array<\chat\data\message\Message>
|
2011-12-26 15:31:37 +00:00
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
public static function getNewestMessages(\chat\data\room\Room $room, $number = CHAT_LASTMESSAGES) {
|
2013-06-23 15:46:52 +00:00
|
|
|
if ($number === 0) return array();
|
|
|
|
|
2011-12-04 21:46:50 +00:00
|
|
|
$messageList = new static();
|
2013-01-26 21:46:54 +00:00
|
|
|
$messageList->sqlOrderBy = "message.messageID DESC";
|
2011-12-04 21:46:50 +00:00
|
|
|
$messageList->sqlLimit = $number;
|
2013-05-15 20:11:47 +00:00
|
|
|
$messageList->getConditionBuilder()->add('message.receiver IS NULL', array());
|
|
|
|
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
|
2011-12-26 15:31:37 +00:00
|
|
|
|
2011-12-04 21:46:50 +00:00
|
|
|
$messageList->readObjects();
|
|
|
|
return array_reverse($messageList->getObjects());
|
|
|
|
}
|
2011-12-26 15:31:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the messages since the given message-id for the given room.
|
|
|
|
*
|
2013-01-19 19:36:40 +00:00
|
|
|
* @param \chat\data\room\Room $room
|
|
|
|
* @param integer $since
|
|
|
|
* @return array<\chat\data\message\Message>
|
2011-12-26 15:31:37 +00:00
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
public static function getMessagesSince(\chat\data\room\Room $room, $since) {
|
2011-12-26 15:31:37 +00:00
|
|
|
$messageList = new static();
|
2013-01-26 21:46:54 +00:00
|
|
|
$messageList->sqlOrderBy = "message.messageID ASC";
|
|
|
|
$messageList->getConditionBuilder()->add('message.messageID > ?', array($since));
|
2011-12-26 15:31:37 +00:00
|
|
|
$messageList->getConditionBuilder()->add('
|
|
|
|
((
|
2013-01-26 21:46:54 +00:00
|
|
|
message.receiver IS NULL
|
|
|
|
AND message.roomID = ?
|
2011-12-26 15:31:37 +00:00
|
|
|
)
|
2013-01-26 21:46:54 +00:00
|
|
|
OR message.receiver = ?
|
2013-05-15 20:11:47 +00:00
|
|
|
OR message.sender = ?)',
|
|
|
|
array($room->roomID, \wcf\system\WCF::getUser()->userID, \wcf\system\WCF::getUser()->userID)
|
|
|
|
);
|
2011-12-26 15:31:37 +00:00
|
|
|
|
|
|
|
$messageList->readObjects();
|
|
|
|
return $messageList->getObjects();
|
|
|
|
}
|
2013-07-29 22:19:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads the message between the given timestamps for the given room.
|
|
|
|
*
|
|
|
|
* @param \chat\data\room\Room $room
|
|
|
|
* @param integer $start
|
|
|
|
* @param integer $end
|
|
|
|
* @return array<\chat\data\message\Message>
|
|
|
|
*/
|
|
|
|
public static function getMessagesBetween(\chat\data\room\Room $room, $start, $end) {
|
|
|
|
$messageList = new static();
|
|
|
|
$messageList->sqlOrderBy = "message.messageID ASC";
|
|
|
|
$messageList->getConditionBuilder()->add('message.receiver IS NULL', array());
|
|
|
|
$messageList->getConditionBuilder()->add('message.roomID = ?', array($room->roomID));
|
|
|
|
$messageList->getConditionBuilder()->add('message.time BETWEEN ? AND ?', array($start, $end));
|
|
|
|
|
|
|
|
$messageList->readObjects();
|
|
|
|
return $messageList->getObjects();
|
|
|
|
}
|
2011-12-04 21:46:50 +00:00
|
|
|
}
|