mirror of
https://github.com/wbbaddons/Tims-Chat.git
synced 2024-12-22 21:40:08 +00:00
Adding ChatMessage DataBaseObjects
This commit is contained in:
parent
74464ff83b
commit
6bc4285f30
45
file/lib/data/chat/message/ChatMessage.class.php
Normal file
45
file/lib/data/chat/message/ChatMessage.class.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace wcf\data\chat\message;
|
||||
|
||||
/**
|
||||
* Represents a chat message.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @copyright 2010-2011 Tim Düsterhus
|
||||
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||
* @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;
|
||||
}
|
||||
}
|
41
file/lib/data/chat/message/ChatMessageEditor.class.php
Normal file
41
file/lib/data/chat/message/ChatMessageEditor.class.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace wcf\data\chat\message;
|
||||
|
||||
/**
|
||||
* Provides functions to edit chat messages.
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @copyright 2010-2011 Tim Düsterhus
|
||||
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
||||
* @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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user