[Fusionforge-commits] r8574 - in trunk/gforge: packaging/install plugins/contribtracker/common plugins/contribtracker/lib plugins/contribtracker/www

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Dec 18 18:39:39 CET 2009


Author: lolando
Date: 2009-12-18 18:39:39 +0100 (Fri, 18 Dec 2009)
New Revision: 8574

Modified:
   trunk/gforge/packaging/install/plugin-contribtracker
   trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
   trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql
   trunk/gforge/plugins/contribtracker/www/index.php
Log:
API tweaks and a basic display of existing contributions

Modified: trunk/gforge/packaging/install/plugin-contribtracker
===================================================================
--- trunk/gforge/packaging/install/plugin-contribtracker	2009-12-18 17:39:31 UTC (rev 8573)
+++ trunk/gforge/packaging/install/plugin-contribtracker	2009-12-18 17:39:39 UTC (rev 8574)
@@ -1,3 +1,4 @@
 plugins/contribtracker/bin/*                   usr/share/gforge/plugins/contribtracker/bin/
 plugins/contribtracker/common/*                usr/share/gforge/plugins/contribtracker/common/
 plugins/contribtracker/lib/*                   usr/share/gforge/plugins/contribtracker/lib/
+plugins/contribtracker/www/*                usr/share/gforge/www/plugins/contribtracker/

Modified: trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php
===================================================================
--- trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php	2009-12-18 17:39:31 UTC (rev 8573)
+++ trunk/gforge/plugins/contribtracker/common/ContribTrackerPlugin.class.php	2009-12-18 17:39:39 UTC (rev 8574)
@@ -161,31 +161,15 @@
 		return $results ;
 	}
 
-	function getParticipationsByActor ($actor) {
-		$res = db_query_params ('SELECT participation_id FROM plugin_contribtracker_participation WHERE actor_id = $1',
-					array ($actor->getId())) ;
-		$ids = util_result_column_to_array ($res, 0) ;
-		
-		$results = array () ;
-		foreach ($ids as $id) {
-			$results[] = new ContribTrackerParticipation ($id) ;
+	function ContribComparator ($a, $b) {
+		if ($a->getDate() != $b->getDate()) {
+			return ($a->getDate() < $b->getDate()) ? -1 : 1 ;
+		} elseif ($a->getName() != $b->getName()) {
+			return ($a->getName() < $b->getName()) ? -1 : 1 ;
+		} else {
+			return 0 ;
 		}
-
-		return $results ;
 	}
-
-	function getParticipationsByContribution ($contrib) {
-		$res = db_query_params ('SELECT participation_id FROM plugin_contribtracker_participation WHERE contrib_id = $1',
-					array ($contrib->getId())) ;
-		$ids = util_result_column_to_array ($res, 0) ;
-		
-		$results = array () ;
-		foreach ($ids as $id) {
-			$results[] = new ContribTrackerParticipation ($id) ;
-		}
-
-		return $results ;
-	}
 }
 
 class ContribTrackerRole extends Error {
@@ -516,6 +500,20 @@
 	function getLegalStructure () {
 		return new ContribTrackerLegalStructure ($this->data_array['struct_id']) ;
 	}
+
+	function getParticipations () {
+		$res = db_query_params ('SELECT participation_id FROM plugin_contribtracker_participation WHERE actor_id = $1',
+					array ($this->getId())) ;
+		$ids = util_result_column_to_array ($res, 0) ;
+		
+		$results = array () ;
+		foreach ($ids as $id) {
+			$results[] = new ContribTrackerParticipation ($id) ;
+		}
+
+		return $results ;
+	}
+
 }
 
 class ContribTrackerContribution extends Error {
@@ -631,6 +629,19 @@
 	function getGroup () {
 		return group_get_object ($this->data_array['group_id']) ;
 	}
+
+	function getParticipations () {
+		$res = db_query_params ('SELECT participation_id FROM plugin_contribtracker_participation WHERE contrib_id = $1',
+					array ($this->getId())) ;
+		$ids = util_result_column_to_array ($res, 0) ;
+		
+		$results = array () ;
+		foreach ($ids as $id) {
+			$results[] = new ContribTrackerParticipation ($id) ;
+		}
+
+		return $results ;
+	}
 }
 
 class ContribTrackerParticipation extends Error {

Modified: trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql
===================================================================
--- trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql	2009-12-18 17:39:31 UTC (rev 8573)
+++ trunk/gforge/plugins/contribtracker/lib/contribtracker-init.sql	2009-12-18 17:39:39 UTC (rev 8574)
@@ -18,7 +18,7 @@
        address text DEFAULT '' NOT NULL,
        email text DEFAULT '' NOT NULL,
        description text DEFAULT '' NOT NULL,
-       struct_id integer REFERENCES plugin_contribtracker_legal_structure
+       struct_id integer NOT NULL REFERENCES plugin_contribtracker_legal_structure
 ) ;
 
 CREATE SEQUENCE plugin_contribtracker_contribution_pk_seq ;
@@ -27,13 +27,13 @@
        name text DEFAULT '' NOT NULL,
        date int,
        description text DEFAULT '' NOT NULL,
-       group_id integer REFERENCES groups ON DELETE CASCADE
+       group_id integer NOT NULL REFERENCES groups ON DELETE CASCADE
 ) ;
 
 CREATE SEQUENCE plugin_contribtracker_participation_pk_seq ;
 CREATE TABLE plugin_contribtracker_participation (
        participation_id integer DEFAULT nextval('plugin_contribtracker_participation_pk_seq') PRIMARY KEY,
-       contrib_id integer REFERENCES plugin_contribtracker_contribution ON DELETE CASCADE,
-       actor_id integer REFERENCES plugin_contribtracker_actor,
-       role_id integer REFERENCES plugin_contribtracker_role
+       contrib_id integer NOT NULL REFERENCES plugin_contribtracker_contribution ON DELETE CASCADE,
+       actor_id integer NOT NULL REFERENCES plugin_contribtracker_actor,
+       role_id integer NOT NULL REFERENCES plugin_contribtracker_role
 ) ;

Modified: trunk/gforge/plugins/contribtracker/www/index.php
===================================================================
--- trunk/gforge/plugins/contribtracker/www/index.php	2009-12-18 17:39:31 UTC (rev 8573)
+++ trunk/gforge/plugins/contribtracker/www/index.php	2009-12-18 17:39:39 UTC (rev 8574)
@@ -1,110 +1,48 @@
 <?php
 
 /*
- * HelloWorld plugin
+ * ContribTracker plugin
  *
- * Daniel Perez <danielperez.arg at gmail.com>
+ * Copyright 2009, Roland Mas
  *
- * This is an example to watch things in action. You can obviously modify things and logic as you see fit
  */
 
 require_once('../../env.inc.php');
 require_once $gfwww.'include/pre.php';
-require_once $gfconfig.'plugins/helloworld/config.php';
 
-// the header that displays for the user portion of the plugin
-function helloworld_Project_Header($params) {                                                                                                                                         
-	global $DOCUMENT_ROOT,$HTML,$id;                                                                            
-	$params['toptab']='helloworld'; 
-	$params['group']=$id;
-	/*                                                                                                                                                              
-		Show horizontal links                                                                                                                                   
-	*/                                                                                                                                                              
-	site_project_header($params);														
-}
+$HTML->header(array('title'=>_('Contributions'),'pagename'=>'contribtracker'));
 
-// the header that displays for the project portion of the plugin
-function helloworld_User_Header($params) {
-	global $DOCUMENT_ROOT,$HTML,$user_id;                                                                            
-	$params['toptab']='helloworld'; 
-	$params['user']=$user_id;
-	/*                                                                                                                                                              
-	 Show horizontal links                                                                                                                                   
-	 */                                                                                                                                                              
-	site_user_header($params);    
-}
+$plugin = plugin_get_object ('contribtracker') ;
 
+$contribs = $plugin->getContributions () ;
 
-	$user = session_get_user(); // get the session user
+usort ($contribs, "ContribTrackerPlugin::ContribComparator") ;
 
-	if (!$user || !is_object($user) || $user->isError() || !$user->isActive()) {
-		exit_error("Invalid User", "Cannot Process your request for this user.");
-	}
+if (count ($contribs) == 0) {
+	print '<h1>'._('No contributions').'</h1>' ;
+	print _('No contributions have been recorded yet.') ;
+} else {
+	print '<h1>'._('Latest contributions').'</h1>' ;
 
-	$type = getStringFromRequest('type');
-	$id = getStringFromRequest('id');
-	$pluginname = getStringFromRequest('pluginname');
-	
-	if (!$type) {
-		exit_error("Cannot Process your request","No TYPE specified"); // you can create items in Base.tab and customize this messages
-	} elseif (!$id) {
-		exit_error("Cannot Process your request","No ID specified");
-	} else {
-		if ($type == 'group') {
-			$group = group_get_object($id);
-			if ( !$group) {
-				exit_error("Invalid Project", "Inexistent Project");
-			}
-			if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the HelloWorld plugin active
-				exit_error("Error", "First activate the $pluginname plugin through the Project's Admin Interface");			
-			}
-			$userperm = $group->getPermission($user);//we'll check if the user belongs to the group (optional)
-			if ( !$userperm->IsMember()) {
-				exit_error("Access Denied", "You are not a member of this project");
-			}
-			// other perms checks here...
-			helloworld_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));    
-			// DO THE STUFF FOR THE PROJECT PART HERE
-			echo "We are in the Project HelloWorld plugin <br>";
-			echo "Greetings from planet " . $world; // $world comes from the config file in /etc
-		} elseif ($type == 'user') {
-			$realuser = user_get_object($id);// 
-			if (!($realuser) || !($realuser->usesPlugin($pluginname))) {
-				exit_error("Error", "First activate the User's $pluginname plugin through Account Manteinance Page");
-			}
-			if ( (!$user) || ($user->getID() != $id)) { // if someone else tried to access the private HelloWorld part of this user
-				exit_error("Access Denied", "You cannot access other user's personal $pluginname");
-			}
-			helloworld_User_Header(array('title'=>'My '.$pluginname,'pagename'=>"$pluginname",'sectionvals'=>array($realuser->getUnixName())));    
-			// DO THE STUFF FOR THE USER PART HERE
-			echo "We are in the User HelloWorld plugin <br>";
-			echo "Greetings from planet " . $world; // $world comes from the config file in /etc
-		} elseif ($type == 'admin') {
-			$group = group_get_object($id);
-			if ( !$group) {
-				exit_error("Invalid Project", "Inexistent Project");
-			}
-			if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the HelloWorld plugin active
-				exit_error("Error", "First activate the $pluginname plugin through the Project's Admin Interface");			
-			}
-			$userperm = $group->getPermission($user);//we'll check if the user belongs to the group
-			if ( !$userperm->IsMember()) {
-				exit_error("Access Denied", "You are not a member of this project");
-			}
-			//only project admin can access here
-			if ( $userperm->isAdmin() ) {
-				helloworld_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));    
-				// DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
-				echo "We are in the Project HelloWorld plugin <font color=\"#ff0000\">ADMINISTRATION</font> <br>";
-				echo "Greetings from planet " . $world; // $world comes from the config file in /etc
-			} else {
-				exit_error("Access Denied", "You are not a project Admin");
-			}
+
+	foreach ($contribs as $c) {
+		print '<h3>'.$c->getName().'</h3>' ;
+		print '<h4>'.$c->getGroup()->getPublicName().'</h4>' ;
+
+		$parts = $c->getParticipations () ;
+		foreach ($parts as $p) {
+			print $p->getActor()->getName() ;
+			print " (" ;
+			print $p->getActor()->getLegalStructure()->getName() ;
+			print ") as " ;
+			print $p->getRole()->getName() ;
+			print '<br />' ;
 		}
-	}	 
-	
-	site_project_footer(array());
+	}
+}
 
+site_project_footer(array());
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"




More information about the Fusionforge-commits mailing list