[Fusionforge-commits] r9592 - trunk/gforge/www/pm

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Apr 23 11:39:40 CEST 2010


Author: lolando
Date: 2010-04-23 11:39:39 +0200 (Fri, 23 Apr 2010)
New Revision: 9592

Modified:
   trunk/gforge/www/pm/index.php
Log:
Added ability to sort subprojects according to any column in the subproject listing page

Modified: trunk/gforge/www/pm/index.php
===================================================================
--- trunk/gforge/www/pm/index.php	2010-04-23 09:29:00 UTC (rev 9591)
+++ trunk/gforge/www/pm/index.php	2010-04-23 09:39:39 UTC (rev 9592)
@@ -68,12 +68,99 @@
 	/*
 		Put the result set (list of projects for this group) into a column with folders
 	*/
-	$tablearr=array(_('Subproject Name'),
-	_('Description'),
-	_('Open Tasks'),
-	_('Total Number of Tasks'));
+
+	$sortcol = util_ensure_value_in_set (getStringFromRequest ('sortcol'),
+					     array ('project_id',
+						    'project_description',
+						    'project_name',
+						    'open_count',
+						    'total_count')) ;
+	$sortorder = util_ensure_value_in_set (getStringFromRequest ('sortorder'),
+					       array ('a',
+						      'd')) ;
+
+	function build_column_sort_header ($group_id, $title, $val) {
+		global $sortcol, $sortorder ;
+
+		if ($sortcol != $val) {
+			return util_make_link ("/pm/?group_id=$group_id&sortcol=$val",
+					       $title) ;
+		} elseif ($sortorder == 'a') {
+			return util_make_link ("/pm/?group_id=$group_id&sortcol=$val&sortorder=d",
+					       $title.' ▴') ;
+		} else {
+			return util_make_link ("/pm/?group_id=$group_id&sortcol=$val&sortorder=a",
+					       $title.' ▾') ;
+		}
+	}
+
+	$tablearr = array () ;
+	$tablearr[] = build_column_sort_header ($group_id, _('ID'), 'project_id') ;
+	$tablearr[] = build_column_sort_header ($group_id, _('Subproject Name'), 'project_name') ;
+	$tablearr[] = build_column_sort_header ($group_id, _('Description'), 'project_description') ;
+	$tablearr[] = build_column_sort_header ($group_id, _('Open'), 'open_count') ;
+	$tablearr[] = build_column_sort_header ($group_id, _('Total'), 'total_count') ;
 	echo $HTML->listTableTop($tablearr);
 
+	function project_group_comparator ($a, $b) {
+		global $sortcol, $sortorder ;
+
+		switch ($sortcol) {
+		case 'project_name':
+			$sorttype = 'str' ;
+			$va = $a->getName() ;
+			$vb = $b->getName() ;
+			break;
+		case 'project_description':
+			$sorttype = 'str' ;
+			$va = $a->getDescription() ;
+			$vb = $b->getDescription() ;
+			break;
+		case 'project_id':
+			$sorttype = 'int' ;
+			$va = $a->getID();
+			$vb = $b->getID();
+			break;
+		case 'open_count':
+			$sorttype = 'int' ;
+			$va = $a->getOpenCount();
+			$vb = $b->getOpenCount();
+			break;
+		case 'total_count':
+			$sorttype = 'int' ;
+			$va = $a->getTotalCount();
+			$vb = $b->getTotalCount();
+			break;
+		default:
+			return 0;
+		}
+		
+		switch ($sorttype) {
+		case 'str':
+			$tmp = strcoll ($va, $vb) ;
+			break ;
+		case 'int':
+			if ($va < $vb) {
+				$tmp = -1 ;
+			} elseif ($va > $vb) {
+				$tmp = 1 ;
+			} else {
+				$tmp = 0 ;
+			}
+			break ;
+		default:
+			return 0;
+		}
+
+		if ($sortorder == 'd') {
+			return -$tmp ;
+		} else {
+			return $tmp ;
+		}
+	}
+		
+	usort (&$pg_arr, 'project_group_comparator') ;
+
 	for ($j = 0; $j < count($pg_arr); $j++) {
 		if (!is_object($pg_arr[$j])) {
 			//just skip it
@@ -83,7 +170,8 @@
 		echo '
 		<tr '. $HTML->boxGetAltRowStyle($j) . '>
 			<td><a href="'.util_make_url ('/pm/task.php?group_project_id='. $pg_arr[$j]->getID().'&amp;group_id='.$group_id.'&amp;func=browse').'">' .
-		html_image("ic/taskman20w.png","20","20",array("border"=>"0", "align"=>"middle")) . ' &nbsp;'.
+			html_image("ic/taskman20w.png","20","20",array("border"=>"0", "align"=>"middle")) . ' &nbsp;'.$pg_arr[$j]->getID() .'</a></td>
+			<td><a href="'.util_make_url ('/pm/task.php?group_project_id='. $pg_arr[$j]->getID().'&amp;group_id='.$group_id.'&amp;func=browse').'">' .
 		$pg_arr[$j]->getName() .'</a></td>
 			<td>'.$pg_arr[$j]->getDescription() .'</td>
 			<td style="text-align:right">'. (int) $pg_arr[$j]->getOpenCount().'</td>




More information about the Fusionforge-commits mailing list