Author: david
Date: Tue Sep 15 16:09:18 2009
New Revision: 3324

Log:
Enable removing user from groups.

Modified:
   trunk/apps/qubit/modules/user/actions/editAction.class.php

Modified: trunk/apps/qubit/modules/user/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/user/actions/editAction.class.php  Tue Sep 15 
15:51:05 2009        (r3323)
+++ trunk/apps/qubit/modules/user/actions/editAction.class.php  Tue Sep 15 
16:09:18 2009        (r3324)
@@ -129,27 +129,35 @@
 
   protected function updateUserGroups()
   {
-    // Don't duplicate existing user->group relations
-    $currentGroupIds = array();
-    foreach ($this->user->aclUserGroups as $userGroup)
+    $newGroupIds = $formGroupIds = array();
+
+    foreach ($this->form->getValue('groups') as $groupId)
     {
-      $currentGroupIds[] = $userGroup->groupId;
+      $newGroupIds[$groupId] = $formGroupIds[$groupId] = $groupId;
     }
 
-    if (is_array($groupIds = $this->form->getValue('groups')))
+    // Don't re-add existing groups + delete exiting groups that are no longer
+    // in groups list
+    foreach ($this->user->aclUserGroups as $existingUserGroup)
     {
-      foreach ($groupIds as $groupId)
+      if (in_array($existingUserGroup->groupId, $formGroupIds))
+      {
+        unset($newGroupIds[$existingUserGroup->groupId]);
+      }
+      else
       {
-        if (!in_array($groupId, $currentGroupIds))
-        {
-          $userGroup = new QubitAclUserGroup;
-          $userGroup->userId = $this->user->id;
-          $userGroup->groupId = $groupId;
-          $userGroup->save();
-        }
+        $existingUserGroup->delete();
       }
     }
 
+    foreach ($newGroupIds as $groupId)
+    {
+      $userGroup = new QubitAclUserGroup;
+      $userGroup->userId = $this->user->id;
+      $userGroup->groupId = $groupId;
+      $userGroup->save();
+    }
+
     return $this;
   }
 }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to