From 86544d5ae8edb966f623deb6ec446ba896b6a04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 3 Mar 2012 21:36:52 +0100 Subject: [PATCH] Made rooms sortable --- acptemplate/chatRoomList.tpl | 109 ++++++------------ file/lib/acp/form/ChatRoomAddForm.class.php | 2 +- .../data/chat/room/ChatRoomAction.class.php | 64 ++++++++++ 3 files changed, 101 insertions(+), 74 deletions(-) diff --git a/acptemplate/chatRoomList.tpl b/acptemplate/chatRoomList.tpl index 99f7392..e42144a 100644 --- a/acptemplate/chatRoomList.tpl +++ b/acptemplate/chatRoomList.tpl @@ -1,18 +1,19 @@ {include file='header'} - + + +

{lang}wcf.acp.chat.room.list{/lang}

- -
@@ -27,69 +28,31 @@ {/if}
-{hascontent} -
-
-

{lang}wcf.acp.chat.room.list{/lang} {#$items}

-
- - - - - - - - {event name='headColumns'} - - - - - {content} - {foreach from=$objects item=chatRoom} - - - - - - {event name='columns'} - - {/foreach} - {/content} - -
{lang}wcf.global.objectID{/lang}{lang}wcf.acp.chat.room.title{/lang}
- {if $__wcf->session->getPermission('admin.content.chat.canEditRoom')} - - {else} - - {/if} - {if $__wcf->session->getPermission('admin.content.chat.canDeleteRoom')} - - {else} - - {/if} - - {event name='buttons'} -

{@$chatRoom->roomID}

{if $__wcf->session->getPermission('admin.content.chat.canEditRoom')}{$chatRoom->title|language}{else}{$chatRoom->title|language}{/if}

- -
- -
- {@$pagesLinks} - - {if $__wcf->session->getPermission('admin.content.chat.canAddRoom')} - - {/if} -
-{hascontentelse} -
-
-

{lang}wcf.acp.chat.room.noneAvailable{/lang}

-
-
-{/hascontent} +
+ {hascontent} +
    + {content} + {foreach from=$objects item=chatRoom} +
  1. + + {$chatRoom->title|language} + + + {if $__wcf->session->getPermission('admin.content.chat.canEditRoom')} + + {/if} + {if $__wcf->session->getPermission('admin.content.chat.canDeleteRoom')} + + {/if} + + +
  2. + {/foreach} + {/content} +
+ {hascontentelse} +

{lang}wcf.acp.chat.room.noneAvailable{/lang}

+ {/hascontent} +
{include file='footer'} \ No newline at end of file diff --git a/file/lib/acp/form/ChatRoomAddForm.class.php b/file/lib/acp/form/ChatRoomAddForm.class.php index 81d4c3f..e5a95e1 100644 --- a/file/lib/acp/form/ChatRoomAddForm.class.php +++ b/file/lib/acp/form/ChatRoomAddForm.class.php @@ -117,7 +117,7 @@ public function save() { } \wcf\system\acl\ACLHandler::getInstance()->save($roomID, $this->objectTypeID); - \wcf\system\chat\permissions\ChatPermissionHandler::clearCache(); + \wcf\system\chat\permission\ChatPermissionHandler::clearCache(); $this->saved(); diff --git a/file/lib/data/chat/room/ChatRoomAction.class.php b/file/lib/data/chat/room/ChatRoomAction.class.php index 20be631..c5afc37 100644 --- a/file/lib/data/chat/room/ChatRoomAction.class.php +++ b/file/lib/data/chat/room/ChatRoomAction.class.php @@ -1,5 +1,6 @@ beginTransaction(); + $sql = "SELECT max(position) as max + FROM wcf".WCF_N."_chat_room"; + $stmt = WCF::getDB()->prepareStatement($sql); + $stmt->execute(); + $row = $stmt->fetchArray(); + + $sql = "UPDATE wcf".WCF_N."_chat_room + SET position = ".($row['max'] + 1)." + WHERE roomID = ?"; + $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) { + $editor = new ChatRoomEditor($roomList->search($roomID)); + $editor->update(array('position' => $i++)); + } + WCF::getDB()->commitTransaction(); + } }