2012-05-19 19:25:50 +00:00
|
|
|
<?php
|
2013-01-19 19:36:40 +00:00
|
|
|
namespace chat\data\suspension;
|
2012-05-19 19:25:50 +00:00
|
|
|
use \wcf\system\WCF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a chat suspension.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
2013-01-19 19:36:40 +00:00
|
|
|
* @copyright 2010-2013 Tim Düsterhus
|
2012-05-19 19:25: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 data.suspension
|
2012-05-19 19:25:50 +00:00
|
|
|
*/
|
2013-01-26 21:46:54 +00:00
|
|
|
class Suspension extends \chat\data\CHATDatabaseObject {
|
2012-05-19 19:25:50 +00:00
|
|
|
/**
|
|
|
|
* @see \wcf\data\DatabaseObject::$databaseTableName
|
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
protected static $databaseTableName = 'suspension';
|
2012-05-19 19:25:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see \wcf\data\DatabaseObject::$databaseTableIndexName
|
|
|
|
*/
|
|
|
|
protected static $databaseTableIndexName = 'suspensionID';
|
|
|
|
|
|
|
|
const TYPE_MUTE = 1;
|
|
|
|
const TYPE_BAN = 2;
|
|
|
|
|
|
|
|
public static function getSuspensionsForUser(\wcf\data\user\User $user = null) {
|
|
|
|
if ($user === null) $user = WCF::getUser();
|
2013-01-19 19:36:40 +00:00
|
|
|
$suspensions = \chat\util\ChatUtil::readUserData('suspensions', $user);
|
2013-04-23 14:16:27 +00:00
|
|
|
|
2012-05-19 19:25:50 +00:00
|
|
|
if ($suspensions === null) {
|
|
|
|
$sql = "SELECT
|
|
|
|
*
|
|
|
|
FROM
|
2013-01-19 19:36:40 +00:00
|
|
|
chat".WCF_N."_suspension
|
2012-05-19 19:25:50 +00:00
|
|
|
WHERE
|
|
|
|
userID = ?
|
|
|
|
AND time > ?";
|
|
|
|
$stmt = WCF::getDB()->prepareStatement($sql);
|
|
|
|
$stmt->execute(array($user->userID, TIME_NOW));
|
|
|
|
|
|
|
|
$suspensions = array();
|
2013-04-23 14:16:27 +00:00
|
|
|
while ($suspension = $stmt->fetchObject('\chat\data\suspension\Suspension')) {
|
|
|
|
$suspensions[$suspension->roomID][$suspension->type] = $suspension;
|
2012-05-19 19:25:50 +00:00
|
|
|
}
|
|
|
|
|
2013-01-19 19:36:40 +00:00
|
|
|
\chat\util\ChatUtil::writeUserData(array('suspensions' => $suspensions), $user);
|
2012-05-19 19:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $suspensions;
|
|
|
|
}
|
2012-10-20 16:24:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the appropriate suspension for user, room and type.
|
|
|
|
*
|
2013-01-19 19:36:40 +00:00
|
|
|
* @param \wcf\data\user\User $user
|
|
|
|
* @param \chat\data\room\Room $room
|
|
|
|
* @param integer $type
|
|
|
|
* @return \chat\data\suspension\Suspension
|
2012-10-20 16:24:48 +00:00
|
|
|
*/
|
2013-01-19 19:36:40 +00:00
|
|
|
public static function getSuspensionByUserRoomAndType(\wcf\data\user\User $user, \chat\data\room\Room $room, $type) {
|
2012-10-20 16:24:48 +00:00
|
|
|
$sql = "SELECT
|
|
|
|
*
|
|
|
|
FROM
|
2013-01-19 19:36:40 +00:00
|
|
|
chat".WCF_N."_suspension
|
2012-10-20 16:24:48 +00:00
|
|
|
WHERE
|
|
|
|
userID = ?
|
|
|
|
AND type = ?";
|
2013-02-01 19:41:59 +00:00
|
|
|
|
|
|
|
$parameter = array($user->userID, $type);
|
|
|
|
if ($room->roomID) {
|
|
|
|
$sql .= " AND roomID = ?";
|
|
|
|
$parameter[] = $room->roomID;
|
|
|
|
}
|
|
|
|
else $sql .= " AND roomID IS NULL";
|
|
|
|
|
2012-10-20 16:24:48 +00:00
|
|
|
$statement = WCF::getDB()->prepareStatement($sql);
|
2013-02-01 19:41:59 +00:00
|
|
|
$statement->execute($parameter);
|
2012-10-20 16:24:48 +00:00
|
|
|
$row = $statement->fetchArray();
|
|
|
|
if(!$row) $row = array();
|
|
|
|
|
|
|
|
return new self(null, $row);
|
|
|
|
}
|
2012-05-19 19:25:50 +00:00
|
|
|
}
|