Author: david
Date: Tue Sep 15 15:51:05 2009
New Revision: 3323

Log:
Move userGroup update to it's own method.

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:46:56 2009        (r3322)
+++ trunk/apps/qubit/modules/user/actions/editAction.class.php  Tue Sep 15 
15:51:05 2009        (r3323)
@@ -120,18 +120,35 @@
   {
     $this->user->username = $this->form->getValue('username');
     $this->user->email = $this->form->getValue('email');
+    $this->user->save();
+
+    $this->updateUserGroups();
+
+    return $this;
+  }
 
-    if (is_array($groups = $this->form->getValue('groups')))
+  protected function updateUserGroups()
+  {
+    // Don't duplicate existing user->group relations
+    $currentGroupIds = array();
+    foreach ($this->user->aclUserGroups as $userGroup)
     {
-      foreach ($groups as $groupId)
+      $currentGroupIds[] = $userGroup->groupId;
+    }
+
+    if (is_array($groupIds = $this->form->getValue('groups')))
+    {
+      foreach ($groupIds as $groupId)
       {
-        $userGroup = new QubitAclUserGroup;
-        $userGroup->userId = $this->user->id;
-        $userGroup->groupId = $groupId;
-        $userGroup->save();
+        if (!in_array($groupId, $currentGroupIds))
+        {
+          $userGroup = new QubitAclUserGroup;
+          $userGroup->userId = $this->user->id;
+          $userGroup->groupId = $groupId;
+          $userGroup->save();
+        }
       }
     }
-    $this->user->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