[Fusionforge-commits] r13668 - in trunk/src/plugins/projects_hierarchy: common view

Franck VILLAUME nerville at fusionforge.org
Sat Jul 2 12:54:29 CEST 2011


Author: nerville
Date: 2011-07-02 12:54:29 +0200 (Sat, 02 Jul 2011)
New Revision: 13668

Modified:
   trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php
   trunk/src/plugins/projects_hierarchy/view/admin_project_link.php
Log:
fix son_box & better display

Modified: trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php
===================================================================
--- trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php	2011-07-01 18:20:22 UTC (rev 13667)
+++ trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php	2011-07-02 10:54:29 UTC (rev 13668)
@@ -177,25 +177,43 @@
 	 * @param	integer	group_id to serach for
 	 * @param	string	parent or child ?
 	 * @param	boolean	recurcive or not ?
-	 * @param	boolean validated or pending relation ?
+	 * @param	string validated or pending or any relation ?
 	 * @return	array	array of arrays with group_id of parent or childs
 	 * @access	public
 	 */
-	function getFamily($group_id, $order, $deep = false, $validated = true) {
+	function getFamily($group_id, $order, $deep = false, $status = 'any') {
 		$localFamily = array();
+		switch ($status) {
+			case "validated": {
+				$statusCondition = 't';
+				break;
+			}
+			case "pending": {
+				$statusCondition = 'f';
+				break;
+			}
+			case "any":
+			default: {
+				break;
+			}
+		}
 		switch ($order) {
 			case "parent": {
-				$res = db_query_params('SELECT project_id as id FROM plugin_projects_hierarchy_relationship
-							WHERE sub_project_id = $1
-							AND status = $2',
-							array($group_id, $validated ? 't' : 'f'));
+				$qpa = db_construct_qpa(false, 'SELECT project_id as id FROM plugin_projects_hierarchy_relationship
+							WHERE sub_project_id = $1 ', array($group_id));
+				if (isset($statusCondition)) {
+					db_construct_qpa($qpa, ' AND status = $1', array($statusCondition));
+				}
+				$res = db_query_qpa($qpa);
 				break;
 			}
 			case "child": {
-				$res = db_query_params('SELECT sub_project_id as id FROM plugin_projects_hierarchy_relationship
-							WHERE project_id = $1
-							AND status = $2',
-							array($group_id, $validated ? 't' : 'f'));
+				$qpa = db_construct_qpa(false, 'SELECT sub_project_id as id FROM plugin_projects_hierarchy_relationship
+							WHERE project_id = $1', array($group_id));
+				if (isset($statusCondition)) {
+					db_construct_qpa($qpa, ' AND status = $1', array($statusCondition));
+				}
+				$res = db_query_qpa($qpa);
 				break;
 			}
 			default: {
@@ -210,7 +228,7 @@
 
 		if ($deep) {
 			for ( $i = 0; $i < count($localFamily); $i++) {
-				$localFamily[$i][] = $this->getFamily($localFamily[$i], $order, $deep, $validated);
+				$localFamily[$i][] = $this->getFamily($localFamily[$i], $order, $deep, $status);
 			}
 		}
 		return $localFamily;
@@ -320,7 +338,7 @@
 	}
 
 	function addChild($project_id, $sub_project_id) {
-		if ($this->exists($project_id)) {
+		if ($this->exists($project_id) && $this->exists($sub_project_id)) {
 			$res = db_query_params('INSERT INTO plugin_projects_hierarchy_relationship (project_id, sub_project_id)
 						VALUES ($1, $2)', array($project_id, $sub_project_id));
 			if (!$res) {
@@ -336,7 +354,7 @@
 	}
 
 	function hasRelation($project_id, $sub_project_id) {
-		if ($this->exists($project_id)) {
+		if ($this->exists($project_id) && $this->exists($sub_project_id)) {
 			$res = db_query_params('SELECT * FROM plugin_projects_hierarchy_relationship
 						WHERE ( project_id = $1 AND sub_project_id = $2 )
 						OR ( project_id = $2 AND sub_project_id = $1 )',
@@ -348,7 +366,7 @@
 	}
 
 	function validateRelationship($project_id, $sub_project_id, $status) {
-		if ($this->exists($project_id)) {
+		if ($this->exists($project_id) && $this->exists($sub_project_id)) {
 			if ($this->hasRelation($project_id, $sub_project_id)) {
 				if ($status) {
 					$res = db_query_params('UPDATE plugin_projects_hierarchy_relationship
@@ -486,8 +504,8 @@
 	}
 
 	function son_box($group_id, $name, $selected = 'xzxzxz') {
-		$sons = $this->getFamily($group_id, 'child', true, false);
-		$parent = $this->getFamily($group_id, 'parent', true, false);
+		$sons = $this->getFamily($group_id, 'child', true, 'any');
+		$parent = $this->getFamily($group_id, 'parent', true, 'any');
 		$skipped = array();
 		$family = array_merge($parent, $sons);
 		if (sizeof($family)) {

Modified: trunk/src/plugins/projects_hierarchy/view/admin_project_link.php
===================================================================
--- trunk/src/plugins/projects_hierarchy/view/admin_project_link.php	2011-07-01 18:20:22 UTC (rev 13667)
+++ trunk/src/plugins/projects_hierarchy/view/admin_project_link.php	2011-07-02 10:54:29 UTC (rev 13668)
@@ -32,7 +32,7 @@
 echo '<input type="submit" value="'._('Add Child project').'">';
 echo '</form>';
 
-$child = $projectsHierarchy->getFamily($group_id, 'child');
+$child = $projectsHierarchy->getFamily($group_id, 'child', false, 'validated');
 if (sizeof($child)) {
 	echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=addChild&id='.$group_id.'">';
 	echo _('Select a project: ');
@@ -41,30 +41,30 @@
 	echo '</form>';
 }
 
-$parent = $projectsHierarchy->getFamily($group_id, 'parent');
+$parent = $projectsHierarchy->getFamily($group_id, 'parent', false, 'validated');
 if (sizeof($parent)) {
+	$parentGroup = group_get_object($parent[0][0]);
 	echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=addChild&id='.$group_id.'">';
-	echo _('Select a project: ');
+	echo $parentGroup->getPublicName();
 	//echo $projectsHierarchy->son_box($group_id, 'sub_project_id', '0');
 	echo '<input type="submit" value="'._('Remove parent project').'">';
 	echo '</form>';
 }
 
-$pendingParent = $projectsHierarchy->getFamily($group_id, 'parent', false, false);
+echo '<h3>'._('Pending hierarchy request').'</h3>';
+$pendingParent = $projectsHierarchy->getFamily($group_id, 'parent', false, 'pending');
 if (sizeof($pendingParent)) {
-	$parentGroup = group_get_object($pendingParent[0][0]);
-	echo '<h3>'._('Pending hierarchy request').'</h3>';
+	$pendingParentGroup = group_get_object($pendingParent[0][0]);
 	echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=validateRelationship&id='.$group_id.'">';
 	echo '<input type="hidden" name="validation_id" value="'.$pendingParent[0][0].'" />';
-	echo _('Validate parent').' '.$parentGroup->getPublicName();
+	echo _('Validate parent').' '.$pendingParentGroup->getPublicName();
 	echo html_build_select_box_from_arrays(array(1,0), array(_('Yes'), _('No')), 'validation_status', 'xzxz', false);
 	echo '<input type="submit" value="'. _('Send') .'" />';
 	echo '</form>';
 }
 
-$pendingChilds = $projectsHierarchy->getFamily($group_id, 'child', false, false);
+$pendingChilds = $projectsHierarchy->getFamily($group_id, 'child', false, 'pending');
 if (sizeof($pendingChilds)) {
-	echo '<h3>'._('Pending hierarchy request').'</h3>';
 	foreach ($pendingChilds as $pendingChild) {
 		$childGroup = group_get_object($pendingChild[0][0]);
 		echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=validateRelationship&id='.$group_id.'">';
@@ -76,4 +76,8 @@
 	}
 }
 
+if (!sizeof($pendingParent) && !sizeof($pendingChilds))
+	echo '<p class="information">'._('No pending requests').'</p>';
+
+
 ?>




More information about the Fusionforge-commits mailing list