Extended User-classes to provide more group-related functions
authorAlexander Ebert <ebert@woltlab.com>
Wed, 24 Aug 2011 13:34:45 +0000 (15:34 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 24 Aug 2011 13:34:45 +0000 (15:34 +0200)
wcfsetup/install/files/lib/data/user/UserAction.class.php
wcfsetup/install/files/lib/data/user/UserEditor.class.php

index 83d3444b89f4796ffcb27d4ffe76478f69918614..766177ffea759806b3486de39f1a078eac4f6cf6 100644 (file)
@@ -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);
+                       }
+               }
+       }
 }
index 0eb35564ac1c9b7d3671810deb6659e871205091..945e475b868c121ffa345b32000036521364a50d 100644 (file)
@@ -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.
         *