[xoops-cvslog 4361] CVS update: xoops2jp/html/modules/user/class

Back to archive index

Minahito minah****@users*****
2006年 8月 25日 (金) 19:17:15 JST


Index: xoops2jp/html/modules/user/class/users.php
diff -u xoops2jp/html/modules/user/class/users.php:1.1.2.6 xoops2jp/html/modules/user/class/users.php:1.1.2.7
--- xoops2jp/html/modules/user/class/users.php:1.1.2.6	Sat Aug  5 22:23:35 2006
+++ xoops2jp/html/modules/user/class/users.php	Fri Aug 25 19:17:15 2006
@@ -8,6 +8,7 @@
 	// TODO naming rule
 	//
 	var $Groups = array();
+	var $_mGroupsLoadedFlag = false;
 	
 	function UserUsersObject()
 	{
@@ -54,11 +55,15 @@
 	//
 	function _loadGroups()
 	{
-		$handler =& xoops_getmodulehandler('groups_users_link', 'user');
-		$links =& $handler->getObjects(new Criteria('uid', $this->get('uid')));
-		foreach ($links as $link) {
-			$this->Groups[] = $link->get('groupid');
+		if (!$this->_mGroupsLoadedFlag) {
+			$handler =& xoops_getmodulehandler('groups_users_link', 'user');
+			$links =& $handler->getObjects(new Criteria('uid', $this->get('uid')));
+			foreach ($links as $link) {
+				$this->Groups[] = $link->get('groupid');
+			}
 		}
+		
+		$this->_mGroupsLoadedFlag = true;
 	}
 
 }
@@ -147,19 +152,34 @@
 	{
 		if (parent::insert($user, $force)) {
 			$flag = true;
+			
+			$user->_loadGroups();
 
 			$handler =& xoops_getmodulehandler('groups_users_link', 'user');
-			$handler->deleteAll(new Criteria('uid', $user->get('uid')), $force);
+			$oldLinkArr =& $handler->getObjects(new Criteria('uid', $user->get('uid')), $force);
+			
+			//
+			// Delete
+			//
+			$oldGroupidArr = array();
+			foreach (array_keys($oldLinkArr) as $key) {
+				$oldGroupidArr[] = $oldLinkArr[$key]->get('groupid');
+				if (!in_array($oldLinkArr[$key]->get('groupid'), $user->Groups)) {
+					$handler->delete($oldLinkArr[$key], $force);
+				}
+			}
 
 			foreach ($user->Groups as $gid) {
-				$link =& $handler->create();
+				if (!in_array($gid, $oldGroupidArr)) {
+					$link =& $handler->create();
 				
-				$link->set('groupid', $gid);
-				$link->set('uid', $user->get('uid'));
+					$link->set('groupid', $gid);
+					$link->set('uid', $user->get('uid'));
 				
-				$flag &= $handler->insert($link, $force);
+					$flag &= $handler->insert($link, $force);
 				
-				unset($link);
+					unset($link);
+				}
 			}
 			
 			return $flag;


xoops-cvslog メーリングリストの案内
Back to archive index