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

Franck VILLAUME nerville at fusionforge.org
Tue Aug 2 17:45:34 CEST 2011


Author: nerville
Date: 2011-08-02 17:45:34 +0200 (Tue, 02 Aug 2011)
New Revision: 14048

Modified:
   trunk/src/plugins/projects_hierarchy/actions/validateRelationship.php
   trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php
   trunk/src/plugins/projects_hierarchy/view/admin_project_link.php
   trunk/src/plugins/projects_hierarchy/view/home_project_link.php
Log:
numerous enhancement in projects_hierarchy: simply getFamily to make it work correctly, validation relation handle parent or child

Modified: trunk/src/plugins/projects_hierarchy/actions/validateRelationship.php
===================================================================
--- trunk/src/plugins/projects_hierarchy/actions/validateRelationship.php	2011-08-02 15:38:17 UTC (rev 14047)
+++ trunk/src/plugins/projects_hierarchy/actions/validateRelationship.php	2011-08-02 15:45:34 UTC (rev 14048)
@@ -27,8 +27,9 @@
 
 $validation_id = getIntFromRequest('validation_id');
 $status = getStringFromRequest('validation_status');
+$relation = getStringFromRequest('relation');
 
-if ($projectsHierarchy->validateRelationship($validation_id, $id, $status))
+if ($projectsHierarchy->validateRelationship($id, $validation_id, $relation, $status))
 	$projectsHierarchy->redirect($_SERVER['HTTP_REFERER'], 'feedback', _('Task done.'));
 
 $projectsHierarchy->redirect($_SERVER['HTTP_REFERER'], 'error_msg', _('Failed to do task.'));

Modified: trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php
===================================================================
--- trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php	2011-08-02 15:38:17 UTC (rev 14047)
+++ trunk/src/plugins/projects_hierarchy/common/projects_hierarchyPlugin.class.php	2011-08-02 15:45:34 UTC (rev 14048)
@@ -227,33 +227,23 @@
 		}
 		if ($res && db_numrows($res) > 0) {
 			while ($arr = db_fetch_array($res)) {
-				$localFamily[] = array($arr['id']);
+				$localFamily[] = $arr['id'];
 			}
 		}
 
 		if ($deep) {
+			$nextFamily = array();
 			for ( $i = 0; $i < count($localFamily); $i++) {
-				$localFamily[$i][] = $this->getFamily($localFamily[$i], $order, $deep, $status);
+				$nextFamily = $this->getFamily($localFamily[$i], $order, $deep, $status);
 			}
 		}
+		if (isset($nextFamily) && sizeof($nextFamily))
+			$localFamily = array_merge($localFamily, $nextFamily);
+
 		return $localFamily;
 	}
 
 	/**
-	 * getFamilyID - returns a flatted array containing all ids of the family, based on getFamily function.
-	 *
-	 * @param	integer	group_id to search for
-	 * @param	string	parent or child ?
-	 * @param	boolean	recurcive or not ?
-	 * @param	string	validated or pending or any relation ?
-	 * @return	array	flatted array with group_id of parent or childs
-	 * @access	public
-	 */
-	function getFamilyID($group_id, $order, $deep = false, $status = 'any') {
-		return array_flatten($this->getFamily($group_id, $order, $deep, $status));
-	}
-
-	/**
 	 * getDocmanStatus - returns the docman status for this project
 	 *
 	 * @param	integer	group_id
@@ -474,28 +464,59 @@
 	 *
 	 * @param	integer	group_id
 	 * @param	integer	sub_group_id
+	 * @param	string	type of relation
 	 * @param	integer	status of the relation
 	 * @return	boolean	true on success
 	 * @access	public
 	 */
-	function validateRelationship($project_id, $sub_project_id, $status) {
+	function validateRelationship($project_id, $sub_project_id, $relation, $status) {
 		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
-								SET status = $1
-								WHERE project_id = $2 AND sub_project_id = $3',
-								array($status, $project_id, $sub_project_id));
+					$qpa = db_construct_qpa(false, 'UPDATE plugin_projects_hierarchy_relationship SET status = $1
+								WHERE ', array($status));
+					switch ($relation) {
+						case "parent": {
+							$qpa = db_construct_qpa($qpa, 'project_id = $1 AND sub_project_id = $2',
+										array($sub_project_id, $project_id));
+							break;
+						}
+						case "child": {
+							$qpa = db_construct_qpa($qpa, 'project_id = $1 AND sub_project_id = $2',
+										array($project_id, $sub_project_id));
+							break;
+						}
+						default: {
+							return false;
+							break;
+						}
+					}
+					$res = db_query_qpa($qpa);
 					if (!$res)
 						return false;
 
 					if (db_affected_rows($res))
 						return true;
 				} else {
-					$res = db_query_params('DELETE FROM plugin_projects_hierarchy_relationship
-								WHERE project_id = $1 AND sub_project_id = $2',
-								array($project_id, $sub_project_id));
-
+					$qpa = db_construct_qpa(false, 'DELETE FROM plugin_projects_hierarchy_relationship WHERE ',
+								array($status));
+					switch ($relation) {
+						case "parent": {
+							$qpa = db_construct_qpa($qpa, 'project_id = $1 AND sub_project_id = $2',
+										array($project_id, $sub_project_id));
+							break;
+						}
+						case "child": {
+							$qpa = db_construct_qpa($qpa, 'project_id = $1 AND sub_project_id = $2',
+										array($sub_project_id, $project_id));
+							break;
+						}
+						default: {
+							return false;
+							break;
+						}
+					}
+					$res = db_query_qpa($qpa);
 					if (!$res)
 						return false;
 
@@ -669,14 +690,13 @@
 	 * @access	public
 	 */
 	function son_box($group_id, $name, $selected = 'xzxzxz') {
-		$sons = $this->getFamilyID($group_id, 'child', true, 'any');
-		$parent = $this->getFamilyID($group_id, 'parent', true, 'any');
+		$sons = $this->getFamily($group_id, 'child', true, 'any');
+		$parent = $this->getFamily($group_id, 'parent', true, 'any');
 		$family = array_merge($parent, $sons);
 		$son = db_query_params('SELECT group_id, group_name FROM groups
 					WHERE status = $1
 					AND group_id != $2
 					AND group_id <> ALL ($3)
-					AND group_id NOT IN (SELECT sub_project_id FROM plugin_projects_hierarchy_relationship)
 					AND group_id IN (select group_id from group_plugin,plugins where group_plugin.plugin_id = plugins.plugin_id and plugins.plugin_name = $4);',
 					array('A',
 						$group_id,

Modified: trunk/src/plugins/projects_hierarchy/view/admin_project_link.php
===================================================================
--- trunk/src/plugins/projects_hierarchy/view/admin_project_link.php	2011-08-02 15:38:17 UTC (rev 14047)
+++ trunk/src/plugins/projects_hierarchy/view/admin_project_link.php	2011-08-02 15:45:34 UTC (rev 14048)
@@ -35,7 +35,7 @@
 $childs = $projectsHierarchy->getFamily($group_id, 'child', false, 'validated');
 if (sizeof($childs)) {
 	foreach ($childs as $child) {
-		$childGroup = group_get_object($child[0][0]);
+		$childGroup = group_get_object($child[0]);
 		echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=removeChild&id='.$group_id.'&child_id='.$childGroup->getID().'">';
 		echo util_make_link('/projects/'.$childGroup->getUnixName(),$childGroup->getPublicName(),array('title'=>_('Browse this project'), 'class'=>'tabtitle-nw'));
 		echo '<input type="submit" value="'._('Remove child project').'">';
@@ -45,7 +45,7 @@
 
 $parent = $projectsHierarchy->getFamily($group_id, 'parent', false, 'validated');
 if (sizeof($parent)) {
-	$parentGroup = group_get_object($parent[0][0]);
+	$parentGroup = group_get_object($parent[0]);
 	echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=removeParent&id='.$group_id.'&parent_id='.$parentGroup->getID().'">';
 	echo util_make_link('/projects/'.$parentGroup->getUnixName(),$parentGroup->getPublicName(),array('title'=>_('Browse this project'), 'class'=>'tabtitle-nw'));
 	echo '<input type="submit" value="'._('Remove parent project').'">';
@@ -55,9 +55,9 @@
 echo '<h3>'._('Pending hierarchy request').'</h3>';
 $pendingParent = $projectsHierarchy->getFamily($group_id, 'parent', false, 'pending');
 if (sizeof($pendingParent)) {
-	$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].'" />';
+	$pendingParentGroup = group_get_object($pendingParent[0]);
+	echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=validateRelationship&id='.$group_id.'&relation=parent">';
+	echo '<input type="hidden" name="validation_id" value="'.$pendingParent[0].'" />';
 	echo _('Validate parent').' '.util_make_link('/projects/'.$pendingParentGroup->getUnixName(), $pendingParentGroup->getPublicName(), array('title'=>_('Browse this project'), 'class'=>'tabtitle'));
 	echo html_build_select_box_from_arrays(array(1,0), array(_('Yes'), _('No')), 'validation_status', 'xzxz', false);
 	echo '<input type="submit" value="'. _('Send') .'" />';
@@ -68,8 +68,8 @@
 if (sizeof($pendingChilds)) {
 	foreach ($pendingChilds as $pendingChild) {
 		$pendingChildGroup = group_get_object($pendingChild[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="'.$pendingChild[0][0].'" />';
+		echo '<form method="post" action="/plugins/'.$projectsHierarchy->name.'/?type=group&pluginname='.$projectsHierarchy->name.'&action=validateRelationship&id='.$group_id.'&relation=child">';
+		echo '<input type="hidden" name="validation_id" value="'.$pendingChild[0].'" />';
 		echo _('Validate child').' '.util_make_link('/projects/'.$pendingChildGroup->getUnixName(), $pendingChildGroup->getPublicName(), array('title'=>_('Browse this project'), 'class'=>'tabtitle'));
 		echo html_build_select_box_from_arrays(array(1,0), array(_('Yes'), _('No')), 'validation_status', 'xzxz', false);
 		echo '<input type="submit" value="'. _('Send') .'" />';

Modified: trunk/src/plugins/projects_hierarchy/view/home_project_link.php
===================================================================
--- trunk/src/plugins/projects_hierarchy/view/home_project_link.php	2011-08-02 15:38:17 UTC (rev 14047)
+++ trunk/src/plugins/projects_hierarchy/view/home_project_link.php	2011-08-02 15:45:34 UTC (rev 14048)
@@ -32,7 +32,7 @@
 	echo $HTML->boxTop(_('Linked projects'));
 	if (sizeof($parent)) {
 		echo '<ul>';
-		$parentGroup = group_get_object($parent[0][0]);
+		$parentGroup = group_get_object($parent[0]);
 		echo '<li>'._('Parent Project:').' '.util_make_link('/projects/'.$parentGroup->getUnixName(), $parentGroup->getPublicName(), array('class' => 'tabtitle', 'title' => _('Direct link to project'))).'</li>';
 		echo '</ul>';
 	}
@@ -42,7 +42,7 @@
 
 		echo '<ul>';
 		foreach ($childs as $child) {
-			$childGroup = group_get_object($child[0][0]);
+			$childGroup = group_get_object($child[0]);
 			echo '<li>'._('Child project').' '.util_make_link('/projects/'.$childGroup->getUnixName(), $childGroup->getPublicName(), array('class' => 'tabtitle', 'title' => _('Direct link to project'))).'</li>';
 		}
 		echo '</ul>';




More information about the Fusionforge-commits mailing list