From: Alexander Ebert Date: Wed, 24 Aug 2011 13:34:45 +0000 (+0200) Subject: Extended User-classes to provide more group-related functions X-Git-Tag: 2.0.0_Beta_1~1827 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=835fa8c2349afd53d3c7b35e9690f70be432a17b;p=GitHub%2FWoltLab%2FWCF.git Extended User-classes to provide more group-related functions --- diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index 83d3444b89..766177ffea 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -116,4 +116,24 @@ class UserAction extends AbstractDatabaseObjectAction { return $user; } + + /** + * @see wcf\data\AbstractDatabaseObjectAction::update() + */ + public function update() { + parent::update(); + + $groupIDs = (isset($this->parameters['groups'])) ? $this->parameters['groups'] : array(); + $removeGroups = (isset($this->parameters['removeGroups'])) ? $this->parameters['removeGroups'] : array(); + + foreach ($this->objects as $userEditor) { + if (count($groupIDs)) { + $userEditor->addToGroups($groupIDs, false, false); + } + + if (count($removeGroups)) { + $userEditor->removeFromGroups($removeGroups); + } + } + } } diff --git a/wcfsetup/install/files/lib/data/user/UserEditor.class.php b/wcfsetup/install/files/lib/data/user/UserEditor.class.php index 0eb35564ac..945e475b86 100644 --- a/wcfsetup/install/files/lib/data/user/UserEditor.class.php +++ b/wcfsetup/install/files/lib/data/user/UserEditor.class.php @@ -186,6 +186,24 @@ class UserEditor extends DatabaseObjectEditor { $statement->execute(array($this->userID, $groupID)); } + /** + * Removes a user from multiple user groups. + * + * @param array $groupIDs + */ + public function removeFromGroups(array $groupIDs) { + $sql = "DELETE FROM wcf".WCF_N."_user_to_group + WHERE userID = ? + AND groupID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + foreach ($groupIDs as $groupID) { + $statement->execute(array( + $this->userID, + $groupID + )); + } + } + /** * Saves the visible languages of a user. *