From 6bc4285f30df8ed5a7d29f20efca30ccc6548d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 27 Nov 2011 12:21:58 +0100 Subject: [PATCH] Adding ChatMessage DataBaseObjects --- .../data/chat/message/ChatMessage.class.php | 45 +++++++++++++++++++ .../chat/message/ChatMessageEditor.class.php | 41 +++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 file/lib/data/chat/message/ChatMessage.class.php create mode 100644 file/lib/data/chat/message/ChatMessageEditor.class.php diff --git a/file/lib/data/chat/message/ChatMessage.class.php b/file/lib/data/chat/message/ChatMessage.class.php new file mode 100644 index 0000000..b312815 --- /dev/null +++ b/file/lib/data/chat/message/ChatMessage.class.php @@ -0,0 +1,45 @@ + + * @package timwolla.wcf.chat + * @subpackage data.chat.message + */ +class ChatMessage extends \wcf\data\DatabaseObject { + /** + * @see wcf\data\DatabaseObject::$databaseTableName + */ + protected static $databaseTableName = 'chat_message'; + + /** + * @see wcf\data\DatabaseObject::$databaseTableIndexName + */ + protected static $databaseTableIndexName = 'messageID'; + + const TYPE_NORMAL = 0; + const TYPE_JOIN = 1; + const TYPE_LEAVE = 2; + const TYPE_AWAY = 3; + const TYPE_BACK = 4; + const TYPE_MODERATE = 5; + const TYPE_ME = 6; + const TYPE_WHISPER = 7; + const TYPE_INFORMATION = 8; + const TYPE_CLEAR = 9; + const TYPE_TEAM = 10; + const TYPE_GLOBALMESSAGE = 11; + + /** + * Returns the message. + * + * @return string + */ + public function __toString() { + return $this->message; + } +} diff --git a/file/lib/data/chat/message/ChatMessageEditor.class.php b/file/lib/data/chat/message/ChatMessageEditor.class.php new file mode 100644 index 0000000..0e8a80f --- /dev/null +++ b/file/lib/data/chat/message/ChatMessageEditor.class.php @@ -0,0 +1,41 @@ + + * @package timwolla.wcf.chat + * @subpackage data.chat.message + */ +class ChatMessageEditor extends \wcf\data\DatabaseObjectEditor { + /** + * @see wcf\data\DatabaseObjectDecorator::$baseClass + */ + protected static $baseClass = '\wcf\data\chat\message\ChatMessage'; + + + /** + * Removes old messages. + * + * @param integer $lifetime Delete messages older that this time. + * @return integer Number of deleted messages. + */ + public static function cleanup($lifetime = CHAT_ARCHIVETIME) { + $sql = "SELECT + ".static::getDatabaseIndexName()." + FROM + ".static::getDatabaseTableName()." + WHERE + time < ?"; + $statement = \wcf\system\WCF::getDB()->prepareStatement($sql); + $statement->execute(TIME_NOW - $lifetime); + $objectIDs = array(); + while ($row = $statement->fetchArray()) { + $objectIDs[] = $row[static::getDatabaseIndexName()]; + } + return static::deleteAll($objectIDs); + } +}