[Fusionforge-commits] r10652 - in trunk/src: common/include common/widget www/include www/my www/project/admin

Roland Mas lolando at libremir.placard.fr.eu.org
Thu Sep 23 16:13:32 CEST 2010


Author: lolando
Date: 2010-09-23 16:13:32 +0200 (Thu, 23 Sep 2010)
New Revision: 10652

Modified:
   trunk/src/common/include/Group.class.php
   trunk/src/common/include/RBAC.php
   trunk/src/common/widget/Widget_MyProjects.class.php
   trunk/src/www/include/role_utils.php
   trunk/src/www/my/index.php
   trunk/src/www/project/admin/users.php
Log:
Introduce smart comparators for groups and roles, and use them in a couple of places

Modified: trunk/src/common/include/Group.class.php
===================================================================
--- trunk/src/common/include/Group.class.php	2010-09-23 14:07:45 UTC (rev 10651)
+++ trunk/src/common/include/Group.class.php	2010-09-23 14:13:32 UTC (rev 10652)
@@ -2814,7 +2814,39 @@
 	}
 }
 
+class ProjectComparator {
+	var $criterion = 'name' ;
 
+	function Compare ($a, $b) {
+		switch ($this->criterion) {
+		case 'name':
+		default:
+			$namecmp = strcoll ($a->getPublicName(), $b->getPublicName()) ;
+			if ($namecmp != 0) {
+				return $namecmp ;
+			}
+			/* If several projects share a same public name */
+			return strcoll ($a->getUnixName(), $b->getUnixName()) ;
+			break ;
+		case 'id':
+			$aid = $a->getID() ;
+			$bid = $b->getID() ;
+			if ($a == $b) {
+				return 0;
+			}
+			return ($a < $b) ? -1 : 1;
+			break ;
+		}
+	}
+}
+
+function sortProjectList (&$list, $criterion='name') {
+	$cmp = new ProjectComparator () ;
+	$cmp->criterion = $criterion ;
+
+	return usort ($list, array ($cmp, 'Compare')) ;
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"

Modified: trunk/src/common/include/RBAC.php
===================================================================
--- trunk/src/common/include/RBAC.php	2010-09-23 14:07:45 UTC (rev 10651)
+++ trunk/src/common/include/RBAC.php	2010-09-23 14:13:32 UTC (rev 10652)
@@ -1324,6 +1324,73 @@
 	}
 }
 
+class RoleComparator {
+	var $criterion = 'composite' ;
+	var $reference_project = NULL ;
+
+	function Compare ($a, $b) {
+		switch ($this->criterion) {
+		case 'name':
+			return strcoll ($a->getName(), $b->getName()) ;
+			break ;
+		case 'id':
+			$aid = $a->getID() ;
+			$bid = $b->getID() ;
+			if ($a == $b) {
+				return 0;
+			}
+			return ($a < $b) ? -1 : 1;
+			break ;
+		case 'composite':
+		default:
+			if ($this->reference_project == NULL) {
+				return $this->CompareNoRef ($a, $b) ;
+			}
+			$rpid = $this->reference_project->getID () ;
+			$ap = $a->getHomeProject() ;
+			$bp = $b->getHomeProject() ;
+			$a_is_local = ($ap != NULL && $ap->getID() == $rpid) ; // Local
+			$b_is_local = ($bp != NULL && $bp->getID() == $rpid) ;
+
+			if ($a_is_local && !$b_is_local) {
+				return -1 ;
+			} elseif (!$a_is_local && $b_is_local) {
+				return 1 ;
+			}
+			return $this->CompareNoRef ($a, $b) ;
+		}
+	}
+
+	function CompareNoRef ($a, $b) {
+		$ap = $a->getHomeProject() ;
+		$bp = $b->getHomeProject() ;
+		if ($ap == NULL && $bp != NULL) {
+			return 1 ;
+		} elseif ($ap != NULL && $bp == NULL) {
+			return -1 ;
+		} elseif ($ap == NULL && $bp == NULL) {
+			$tmp = strcoll ($a->getName(), $b->getName()) ;
+			return $tmp ;
+		} else {
+			$projcmp = new ProjectComparator () ;
+			$projcmp->criterion = 'name' ;
+			$tmp = $projcmp->Compare ($ap, $bp) ;
+			if ($tmp) { /* Different projects, sort accordingly */
+				return $tmp ;
+			} 
+			return strcoll ($a->getName(), $b->getName()) ;
+		}
+	}
+}
+
+function sortRoleList (&$list, $relative_to = NULL, $criterion='composite') {
+	$cmp = new RoleComparator () ;
+	$cmp->criterion = $criterion ;
+	$cmp->reference_project = $relative_to ;
+
+	return usort ($list, array ($cmp, 'Compare')) ;
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"

Modified: trunk/src/common/widget/Widget_MyProjects.class.php
===================================================================
--- trunk/src/common/widget/Widget_MyProjects.class.php	2010-09-23 14:07:45 UTC (rev 10651)
+++ trunk/src/common/widget/Widget_MyProjects.class.php	2010-09-23 14:13:32 UTC (rev 10652)
@@ -38,7 +38,8 @@
 
 	$user = session_get_user () ;
 	$groups = $user->getGroups() ;
-            		$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
+	sortProjectList ($groups) ;
+	$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
 
 	if (count ($groups) < 1) {
 		$html_my_projects .= _("You're not a member of any project");

Modified: trunk/src/www/include/role_utils.php
===================================================================
--- trunk/src/www/include/role_utils.php	2010-09-23 14:07:45 UTC (rev 10651)
+++ trunk/src/www/include/role_utils.php	2010-09-23 14:13:32 UTC (rev 10652)
@@ -34,6 +34,8 @@
 		$roles = $roles2 ;
 	}
 
+	sortRoleList ($roles, $group, 'composite') ;
+
 	$ids = array () ;
 	$names = array () ;
 	
@@ -67,6 +69,8 @@
 		}
 	}
 
+	sortRoleList ($roles, $group, 'composite') ;
+
 	$ids = array () ;
 	$names = array () ;
 	foreach ($roles as $role) {
@@ -86,6 +90,8 @@
 	$ids = array () ;
 	$names = array () ;
 	
+	sortRoleList ($roles, NULL, 'composite') ;
+
 	foreach ($roles as $role) {
 		$ids[] = $role->getID ();
 		

Modified: trunk/src/www/my/index.php
===================================================================
--- trunk/src/www/my/index.php	2010-09-23 14:07:45 UTC (rev 10651)
+++ trunk/src/www/my/index.php	2010-09-23 14:13:32 UTC (rev 10652)
@@ -399,6 +399,7 @@
 	echo $HTML->listTableTop($order_name_arr);
 	
 	$groups = $user->getGroups() ;
+	sortProjectList ($groups) ;
 
 	if (count ($groups) < 1) {
 		echo '<tr><td colspan="3"><strong>'._('You\'re not a member of any active projects').'</strong></td></tr>';

Modified: trunk/src/www/project/admin/users.php
===================================================================
--- trunk/src/www/project/admin/users.php	2010-09-23 14:07:45 UTC (rev 10651)
+++ trunk/src/www/project/admin/users.php	2010-09-23 14:13:32 UTC (rev 10652)
@@ -81,6 +81,10 @@
 				$used_external_roles[] = $r ;
 			}
 		}
+
+		sortRoleList ($used_external_roles, $group, 'composite') ;
+		sortRoleList ($unused_external_roles, $group, 'composite') ;
+
 	}
 }
 




More information about the Fusionforge-commits mailing list