2012-02-04 20:06:44 +00:00
|
|
|
<?php
|
|
|
|
namespace wcf\data\chat\room;
|
2012-03-03 20:36:52 +00:00
|
|
|
use \wcf\system\WCF;
|
2012-02-04 20:06:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes chatroom-related actions.
|
|
|
|
*
|
|
|
|
* @author Tim Düsterhus
|
|
|
|
* @copyright 2010-2012 Tim Düsterhus
|
|
|
|
* @license Creative Commons Attribution-NonCommercial-ShareAlike <http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode>
|
2012-03-12 16:18:15 +00:00
|
|
|
* @package be.bastelstu.wcf.chat
|
2012-02-04 20:06:44 +00:00
|
|
|
* @subpackage data.chat.room
|
|
|
|
*/
|
|
|
|
class ChatRoomAction extends \wcf\data\AbstractDatabaseObjectAction {
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\data\AbstractDatabaseObjectAction::$className
|
2012-02-04 20:06:44 +00:00
|
|
|
*/
|
|
|
|
protected $className = '\wcf\data\chat\room\ChatRoomEditor';
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\data\AbstractDatabaseObjectAction::$permissionsDelete
|
2012-02-04 20:06:44 +00:00
|
|
|
*/
|
|
|
|
protected $permissionsDelete = array('admin.content.chat.canDeleteRoom');
|
|
|
|
|
|
|
|
/**
|
2012-02-26 16:55:44 +00:00
|
|
|
* @see \wcf\data\AbstractDatabaseObjectAction::$permissionsUpdate
|
2012-02-04 20:06:44 +00:00
|
|
|
*/
|
|
|
|
protected $permissionsUpdate = array('admin.content.chat.canEditRoom');
|
2012-03-03 20:36:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fixes create to append new boards.
|
|
|
|
*/
|
|
|
|
public function create() {
|
|
|
|
$room = parent::create();
|
|
|
|
|
|
|
|
WCF::getDB()->beginTransaction();
|
2012-03-03 20:40:43 +00:00
|
|
|
$sql = "SELECT max(position) as max
|
|
|
|
FROM wcf".WCF_N."_chat_room
|
|
|
|
FOR UPDATE";
|
2012-03-03 20:36:52 +00:00
|
|
|
$stmt = WCF::getDB()->prepareStatement($sql);
|
|
|
|
$stmt->execute();
|
|
|
|
$row = $stmt->fetchArray();
|
|
|
|
|
2012-03-03 20:40:43 +00:00
|
|
|
$sql = "UPDATE wcf".WCF_N."_chat_room
|
|
|
|
SET position = ".($row['max'] + 1)."
|
|
|
|
WHERE roomID = ?";
|
2012-03-03 20:36:52 +00:00
|
|
|
$stmt = WCF::getDB()->prepareStatement($sql);
|
|
|
|
$stmt->execute(array($room->roomID));
|
|
|
|
WCF::getDB()->commitTransaction();
|
|
|
|
|
|
|
|
return $room;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates parameters to update sorting.
|
|
|
|
*/
|
|
|
|
public function validateUpdatePosition() {
|
|
|
|
// validate permissions
|
|
|
|
if (is_array($this->permissionsUpdate) && count($this->permissionsUpdate)) {
|
|
|
|
try {
|
|
|
|
WCF::getSession()->checkPermissions($this->permissionsUpdate);
|
|
|
|
}
|
|
|
|
catch (\wcf\system\exception\PermissionDeniedException $e) {
|
|
|
|
throw new ValidateActionException('Insufficient permissions');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw new ValidateActionException('Insufficient permissions');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($this->parameters['data']['structure'])) {
|
|
|
|
throw new ValidateActionException('Missing parameter structure');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates sorting.
|
|
|
|
*/
|
|
|
|
public function updatePosition() {
|
|
|
|
$roomList = new \wcf\data\chat\room\ChatRoomList();
|
|
|
|
$roomList->sqlOrderBy = "chat_room.position";
|
|
|
|
$roomList->sqlLimit = 0;
|
|
|
|
$roomList->readObjects();
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
WCF::getDB()->beginTransaction();
|
|
|
|
foreach ($this->parameters['data']['structure'][0] as $roomID) {
|
2012-03-03 22:16:24 +00:00
|
|
|
$room = $roomList->search($roomID);
|
|
|
|
if ($room === null) continue;
|
|
|
|
$editor = new ChatRoomEditor($room);
|
2012-03-03 20:36:52 +00:00
|
|
|
$editor->update(array('position' => $i++));
|
|
|
|
}
|
|
|
|
WCF::getDB()->commitTransaction();
|
|
|
|
}
|
2012-02-04 20:06:44 +00:00
|
|
|
}
|