[evolvis-commits] r18255: small-fixes pending merges:↵ Thorsten Glaser 2012-04-07 [#2964] order elements upon cloning

mirabilos at evolvis.org mirabilos at evolvis.org
Sat Apr 7 15:41:35 CEST 2012


Author: mirabilos
Date: 2012-04-07 15:41:35 +0200 (Sat, 07 Apr 2012)
New Revision: 18255

Modified:
   trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactExtraField.class.php
   trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactType.class.php
Log:
small-fixes pending merges:
  Thorsten Glaser 2012-04-07 [#2964] order elements upon cloning


Modified: trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactExtraField.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactExtraField.class.php	2012-04-05 21:02:29 UTC (rev 18254)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactExtraField.class.php	2012-04-07 13:41:35 UTC (rev 18255)
@@ -35,6 +35,18 @@
 define('ARTIFACT_EXTRAFIELDTYPE_RELATION',9);
 define('ARTIFACT_EXTRAFIELDTYPE_INTEGER',10);
 
+function &ArtifactExtraField_getAvailableValues($id) {
+	$rv = array();
+	$res = db_query_params('SELECT * FROM artifact_extra_field_elements
+		WHERE extra_field_id = $1
+		ORDER BY element_pos ASC, element_id ASC',
+	    array($id));
+	while (($row = db_fetch_array($res))) {
+		$rv[] = $row;
+	}
+	return ($rv);
+}
+
 class ArtifactExtraField extends Error {
 
 	/** 
@@ -321,12 +333,7 @@
 	 *	@return array
 	 */
 	function getAvailableValues() {
-		$res = db_query_params ('SELECT * FROM artifact_extra_field_elements WHERE extra_field_id=$1',
-					array ($this->getID()));
-		$return = array();
-		while ($row = db_fetch_array($res)) {
-			$return[] = $row;
-		}
+		$return =& ArtifactExtraField_getAvailableValues($this->getID());
 		return $return;
 	}
 
@@ -552,24 +559,25 @@
 	}
 
 	function reorderValues($element_id, $new_pos) {
-
-		$res = db_query_params ('SELECT element_id FROM artifact_extra_field_elements WHERE extra_field_id=$1 ORDER BY element_pos ASC, element_id ASC',
-			array($this->getID()));
-		$max = db_numrows($res);
+		$res =& ArtifactExtraField_getAvailableValues($this->getID());
+		$max = count($res);
 		if ($new_pos < 1 || $new_pos > $max) {
 			$this->setError(_('Out of range value'));
 			return false;
 		}
+		$data = array();
 		$i = 1;
+		$j = 0;
 		while ($i <= $max) {
 			if ($i == $new_pos) {
 				$data[] = $element_id;
 				$i++;
 			}
-			if (($row = db_fetch_array($res)) && $row['element_id'] != $element_id) {
-				$data[] = $row['element_id'];
+			if ($res[$j]['element_id'] != $element_id) {
+				$data[] = $res[$j]['element_id'];
 				$i++;
 			}
+			$j++;
 		}
 		for ($i = 0; $i < count($data); $i++) {
 			if (! $this->updateOrder($data[$i], $i + 1))

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactType.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactType.class.php	2012-04-05 21:02:29 UTC (rev 18254)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/tracker/ArtifactType.class.php	2012-04-07 13:41:35 UTC (rev 18255)
@@ -26,6 +26,7 @@
  */
 
 require_once $gfcommon.'include/Error.class.php';
+require_once $gfcommon.'tracker/ArtifactExtraField.class.php';
 require_once $gfcommon.'tracker/ArtifactExtraFieldElement.class.php';
 
 	/**
@@ -510,7 +511,7 @@
 				$status_id=db_result($res,0,'status_id');
 			} else {
 				// custom status was not passed... use the first status from the database
-				$res = db_query_params ('SELECT status_id FROM artifact_extra_field_elements WHERE extra_field_id=$1 ORDER BY element_id ASC LIMIT 1 OFFSET 0',
+				$res = db_query_params ('SELECT status_id FROM artifact_extra_field_elements WHERE extra_field_id=$1 ORDER BY element_pos ASC, element_id ASC LIMIT 1 OFFSET 0',
 						       array ($csfield)) ;
 				if (db_numrows($res) == 0) {		// No values available
 					$this->setError('Error Remapping Status');
@@ -672,9 +673,8 @@
 			//
 			//	Iterate the elements
 			//
-			$resel = db_query_params ('SELECT * FROM artifact_extra_field_elements WHERE extra_field_id=$1 ORDER BY element_id',
-						  array ($ef['extra_field_id'])) ;
-			while ($el = db_fetch_array($resel)) {
+			$resel =& ArtifactExtraField_getAvailableValues($ef['extra_field_id']);
+			foreach ($resel as $el) {
 				//new element
 				$nel = new ArtifactExtraFieldElement($nef);
 				if (!$nel->create(util_unconvert_htmlspecialchars($el['element_name']), $el['status_id'] )) {
@@ -714,16 +714,7 @@
 			return false;
 		}
 		if (!isset($this->extra_field[$id])) {
-			$this->extra_field[$id] = array();
-			$res = db_query_params  ('SELECT element_id,element_name,status_id
-				FROM artifact_extra_field_elements
-				WHERE extra_field_id = $1
-				ORDER BY element_pos ASC, element_id ASC',
-						 array ($id)) ;
-			$i=0;
-			while($arr = db_fetch_array($res)) {
-				$this->extra_field[$id][$i++] = $arr;
-			}
+			$this->extra_field[$id] =& ArtifactExtraField_getAvailableValues($id);
 //			if (count($this->extra_field[$id]) == 0) {
 //				return;
 //			}



More information about the evolvis-commits mailing list