[evolvis-commits] r6550: Merged sort-subprojects (item #573)

Roland Mas lolando at debian.org
Tue Apr 20 16:16:14 CEST 2010


Author: Roland Mas <lolando at debian.org>
Date: 2010-04-20 16:16:14 +0200 (Tue, 20 Apr 2010)
New Revision: 6550

Modified:
   trunk/gforge_base/evolvisforge/gforge/common/include/utils.php
   trunk/gforge_base/evolvisforge/gforge/www/pm/index.php
Log:
Merged sort-subprojects (item #573)

Modified: trunk/gforge_base/evolvisforge/gforge/common/include/utils.php
===================================================================
--- trunk/gforge_base/evolvisforge/gforge/common/include/utils.php	2010-04-20 14:16:11 UTC (rev 6549)
+++ trunk/gforge_base/evolvisforge/gforge/common/include/utils.php	2010-04-20 14:16:14 UTC (rev 6550)
@@ -1036,6 +1036,14 @@
 	return false;
 }
 
+function util_ensure_value_in_set ($value, $set) {
+        if (in_array ($value, $set)) {
+                return $value ;
+        } else {
+                return $set[0] ;
+        }
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"

Modified: trunk/gforge_base/evolvisforge/gforge/www/pm/index.php
===================================================================
--- trunk/gforge_base/evolvisforge/gforge/www/pm/index.php	2010-04-20 14:16:11 UTC (rev 6549)
+++ trunk/gforge_base/evolvisforge/gforge/www/pm/index.php	2010-04-20 14:16:14 UTC (rev 6550)
@@ -64,12 +64,99 @@
 	/*
 		Put the result set (list of projects for this group) into a column with folders
 	*/
-	$tablearr=array(_('Subproject Name'),
-	_('Description'),
-	_('Open'),
-	_('Total'));
+
+	$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
@@ -80,6 +167,8 @@
 		<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")) . ' &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:center">'. (int) $pg_arr[$j]->getOpenCount().'</td>




More information about the evolvis-commits mailing list