From 5ea6afcf0fe077136d84c2150ae30e5ad50096c8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 8 Sep 2011 18:51:58 +0200 Subject: [PATCH] Assigning users to groups via clipboard now working --- .../install/files/acp/templates/success.tpl | 2 +- .../files/acp/templates/userAssignToGroup.tpl | 1 - .../acp/form/UserAssignToGroupForm.class.php | 50 +++++++++++++------ .../files/lib/data/user/User.class.php | 9 ++++ .../clipboard/ClipboardHandler.class.php | 16 ++++++ 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/wcfsetup/install/files/acp/templates/success.tpl b/wcfsetup/install/files/acp/templates/success.tpl index 8a495e8f2c..b0beac7ec7 100644 --- a/wcfsetup/install/files/acp/templates/success.tpl +++ b/wcfsetup/install/files/acp/templates/success.tpl @@ -1,4 +1,4 @@ -{include file='header'} +{include file='header' templateName='success'}

{lang}{@$message}{/lang}

diff --git a/wcfsetup/install/files/acp/templates/userAssignToGroup.tpl b/wcfsetup/install/files/acp/templates/userAssignToGroup.tpl index 7e110b1381..9c0cb2b23d 100644 --- a/wcfsetup/install/files/acp/templates/userAssignToGroup.tpl +++ b/wcfsetup/install/files/acp/templates/userAssignToGroup.tpl @@ -44,7 +44,6 @@ {@SID_INPUT_TAG} - diff --git a/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php b/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php index bd9f2b2eea..423f9a6d89 100755 --- a/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserAssignToGroupForm.class.php @@ -1,7 +1,9 @@ typeID = ClipboardHandler::getInstance()->getTypeID('com.woltlab.wcf.user'); + if ($this->typeID === null) { + throw new SystemException("clipboard item type 'com.woltlab.wcf.user' is unknown."); + } + + // get user ids + $users = ClipboardHandler::getInstance()->getMarkedItems($this->typeID); + if (!isset($users['com.woltlab.wcf.user']) || empty($users['com.woltlab.wcf.user'])) throw new IllegalLinkException(); + + // load users + $this->userIDs = array_keys($users['com.woltlab.wcf.user']); + $this->users = $users['com.woltlab.wcf.user']; + } + /** * @see wcf\form\IForm::readFormParameters() */ public function readFormParameters() { parent::readFormParameters(); - if (isset($_POST['userIDs'])) $this->userIDs = ArrayUtil::toIntegerArray(explode(',', $_POST['userIDs'])); if (isset($_POST['groupIDs']) && is_array($_POST['groupIDs'])) $this->groupIDs = ArrayUtil::toIntegerArray($_POST['groupIDs']); } @@ -94,14 +122,18 @@ class UserAssignToGroupForm extends ACPForm { throw new PermissionDeniedException(); } + $groupsIDs = array_merge($groups[$user->userID], $this->groupIDs); + $groupsIDs = array_unique($groupsIDs); + $userEditor = new UserEditor($user); - $userEditor->addToGroups($groups[$user->userID], false, false); + $userEditor->addToGroups($groupsIDs, true, false); } - // TODO: Implement unmarkAll() - //UserEditor::unmarkAll(); + ClipboardHandler::getInstance()->removeItems($this->typeID); SessionHandler::resetSessions($this->userIDs); + $this->saved(); + WCF::getTPL()->assign('message', 'wcf.acp.user.assignToGroup.success'); WCF::getTPL()->display('success'); exit; @@ -113,16 +145,6 @@ class UserAssignToGroupForm extends ACPForm { public function readData() { parent::readData(); - if (!count($_POST)) { - // get marked user ids - $markedUsers = WCF::getSession()->getVar('markedUsers'); - if (is_array($markedUsers)) { - $this->userIDs = $markedUsers; - } - if (empty($this->userIDs)) throw new IllegalLinkException(); - } - - $this->users = User::getUsers($this->userIDs); $this->readGroups(); } diff --git a/wcfsetup/install/files/lib/data/user/User.class.php b/wcfsetup/install/files/lib/data/user/User.class.php index 95e159bf2d..f6d993a5e6 100644 --- a/wcfsetup/install/files/lib/data/user/User.class.php +++ b/wcfsetup/install/files/lib/data/user/User.class.php @@ -291,4 +291,13 @@ class User extends DatabaseObject { return $userList->getObjects(); } + + /** + * Returns username. + * + * @return string + */ + public function __toString() { + return $this->username; + } } diff --git a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php index 21779bdc11..bba1af2fa0 100644 --- a/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php +++ b/wcfsetup/install/files/lib/system/clipboard/ClipboardHandler.class.php @@ -256,4 +256,20 @@ class ClipboardHandler extends SingletonFactory { return $editorData; } + + /** + * Removes items from clipboard. + * + * @param integer $typeID + */ + public function removeItems($typeID = null) { + $conditions = new PreparedStatementConditionBuilder(); + $conditions->add("userID = ?", array(WCF::getUser()->userID)); + if ($typeID !== null) $conditions->add("typeID = ?", array($typeID)); + + $sql = "DELETE FROM wcf".WCF_N."_clipboard_item + ".$conditions; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute($conditions->getParameters()); + } } -- 2.20.1