[Fusionforge-commits] r13762 - in trunk/src: common/include plugins/scmgit/common

Franck VILLAUME nerville at fusionforge.org
Tue Jul 12 16:43:54 CEST 2011


Author: nerville
Date: 2011-07-12 16:43:54 +0200 (Tue, 12 Jul 2011)
New Revision: 13762

Added:
   trunk/src/plugins/scmgit/common/scmgit_Widget_MyRepositories.class.php
Modified:
   trunk/src/common/include/SCMPlugin.class.php
   trunk/src/plugins/scmgit/common/GitPlugin.class.php
Log:
proof of concept of scm widget: simple list of git cloned personal repositories

Modified: trunk/src/common/include/SCMPlugin.class.php
===================================================================
--- trunk/src/common/include/SCMPlugin.class.php	2011-07-12 13:46:41 UTC (rev 13761)
+++ trunk/src/common/include/SCMPlugin.class.php	2011-07-12 14:43:54 UTC (rev 13762)
@@ -30,12 +30,13 @@
 	 */
 	function SCMPlugin () {
 		$this->Plugin() ;
-		$this->hooks[] = 'scm_plugin';
-		$this->hooks[] = 'scm_page';
-		$this->hooks[] = 'scm_admin_page';
-		$this->hooks[] = 'scm_admin_update';
- 		$this->hooks[] = 'scm_stats';
-		$this->hooks[] = 'scm_create_repo';
+		$this->_addHook('scm_plugin');
+		$this->_addHook('scm_page');
+		$this->_addHook('scm_admin_page');
+		$this->_addHook('scm_admin_update');
+ 		$this->_addHook('scm_stats');
+		$this->_addHook('scm_create_repo');
+
 		# Other common hooks that can be enabled per plugin:
 		# scm_generate_snapshots
 		# scm_gather_stats
@@ -47,43 +48,61 @@
 		global $HTML ;
 
 		switch ($hookname) {
-		case 'scm_plugin':
-			$scm_plugins=& $params['scm_plugins'];
-			$scm_plugins[]=$this->name;
-			break;
-		case 'scm_page':
-			$this->printPage ($params) ;
-			break ;
-		case 'scm_browser_page':
-			$this->printBrowserPage ($params) ;
-			break ;
-		case 'scm_admin_page':
-			$this->printAdminPage ($params) ;
-			break ;
-		case 'scm_admin_update':
-			$this->adminUpdate($params);
-			break ;
-		case 'scm_stats':
-			$this->printShortStats ($params) ;
-			break;
-		case 'scm_create_repo':
-			session_set_admin();
-			$this->createOrUpdateRepo($params);
-			break;
-		case 'scm_update_repolist':
-			session_set_admin () ;
-			$this->updateRepositoryList ($params) ;
-			break;
-		case 'scm_generate_snapshots': // Optional
-			session_set_admin () ;
-			$this->generateSnapshots ($params) ;
-			break;
-		case 'scm_gather_stats': // Optional
-			session_set_admin () ;
-			$this->gatherStats ($params) ;
-			break;
-		default:
-			// Forgot something
+			case 'scm_plugin': {
+				$scm_plugins=& $params['scm_plugins'];
+				$scm_plugins[]=$this->name;
+				break;
+			}
+			case 'scm_page': {
+				$this->printPage ($params) ;
+				break ;
+			}
+			case 'scm_browser_page': {
+				$this->printBrowserPage ($params) ;
+				break ;
+			}
+			case 'scm_admin_page': {
+				$this->printAdminPage ($params) ;
+				break ;
+			}
+			case 'scm_admin_update': {
+				$this->adminUpdate($params);
+				break ;
+			}
+			case 'scm_stats': {
+				$this->printShortStats ($params) ;
+				break;
+			}
+			case 'scm_create_repo': {
+				session_set_admin();
+				$this->createOrUpdateRepo($params);
+				break;
+			}
+			case 'scm_update_repolist': {
+				session_set_admin () ;
+				$this->updateRepositoryList ($params) ;
+				break;
+			}
+			case 'scm_generate_snapshots': {// Optional
+				session_set_admin () ;
+				$this->generateSnapshots ($params) ;
+				break;
+			}
+			case 'scm_gather_stats': { // Optional
+				session_set_admin () ;
+				$this->gatherStats ($params) ;
+				break;
+			}
+			case "widgets": { // Optional
+				$this->widgets($params);
+				break;
+			}
+			case "widget_instance": { // Optional
+				$this->myPageBox($params);
+				break;
+			}
+			default: { // Forgot something
+			}
 		}
 	}
 

Modified: trunk/src/plugins/scmgit/common/GitPlugin.class.php
===================================================================
--- trunk/src/plugins/scmgit/common/GitPlugin.class.php	2011-07-12 13:46:41 UTC (rev 13761)
+++ trunk/src/plugins/scmgit/common/GitPlugin.class.php	2011-07-12 14:43:54 UTC (rev 13762)
@@ -33,7 +33,8 @@
 		$this->_addHook('scm_update_repolist');
 		$this->_addHook('scm_generate_snapshots');
 		$this->_addHook('scm_gather_stats');
-
+		$this->_addHook('widget_instance', 'myPageBox', false);
+		$this->_addHook('widgets', 'widgets', false);
 		$this->register();
 	}
 
@@ -594,6 +595,27 @@
 		unlink ("$tmp/tarball") ;
 		system ("rm -rf $tmp") ;
 	}
+
+	function widgets($params) {
+ 		require_once('common/widget/WidgetLayoutManager.class.php');
+		if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) {
+			$params['fusionforge_widgets'][] = 'plugin_scmgit_project_latestcommits';
+		}
+		if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_USER) {
+			$params['fusionforge_widgets'][] = 'plugin_scmgit_user_myrepositories';
+		}
+		return true;
+	}
+
+	function myPageBox($params) {
+		global $gfplugins;
+		$user = UserManager::instance()->getCurrentUser();
+		require_once('common/widget/WidgetLayoutManager.class.php');
+		if ($params['widget'] == 'plugin_scmgit_user_myrepositories') {
+			require_once $gfplugins.$this->name.'/common/scmgit_Widget_MyRepositories.class.php';
+			$params['instance'] = new scmgit_Widget_MyRepositories(WidgetLayoutManager::OWNER_TYPE_USER, $user->getId());
+		}
+	}
 }
 
 // Local Variables:

Copied: trunk/src/plugins/scmgit/common/scmgit_Widget_MyRepositories.class.php (from rev 13754, trunk/src/plugins/mantisbt/common/mantisbt_Widget_ProjectLastIssues.class.php)
===================================================================
--- trunk/src/plugins/scmgit/common/scmgit_Widget_MyRepositories.class.php	                        (rev 0)
+++ trunk/src/plugins/scmgit/common/scmgit_Widget_MyRepositories.class.php	2011-07-12 14:43:54 UTC (rev 13762)
@@ -0,0 +1,75 @@
+<?php
+/**
+ * Copyright 2011, Franck Villaume - Capgemini
+ * http://fusionforge.org
+ *
+ * This file is part of FusionForge. FusionForge is free software;
+ * you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the Licence, or (at your option)
+ * any later version.
+ *
+ * FusionForge is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FusionForge; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+require_once('common/widget/Widget.class.php');
+require_once('common/widget/WidgetLayoutManager.class.php');
+
+class scmgit_Widget_MyRepositories extends Widget {
+	function scmgit_Widget_MyRepositories($owner_type, $owner_id) {
+		$this->Widget('plugin_scmgit_user_myrepositories');
+		$this->setOwner($owner_id, $owner_type);
+	}
+
+	function getTitle() {
+		return _("SCMGit Repository List");
+	}
+
+	function getCategory() {
+		return _('SCM');
+	}
+
+	function getDescription() {
+		return _("Get the list of URLS of your personal Git repository cloned from projects.");
+	}
+
+	function getContent() {
+		$user = UserManager::instance()->getCurrentUser();
+		$scmgitplugin = plugin_get_object('scmgit');
+		$GitRepositories = $this->getMyRepositoriesList();
+		if (count($GitRepositories)) {
+			$returnhtml = '<table>';
+			foreach ($GitRepositories as $GitRepository) {
+				$project = group_get_object($GitRepository);
+				$returnhtml .= '<tr><td><tt>git clone git+ssh://'.$user->getUnixName().'@' . $scmgitplugin->getBoxForProject($project) . forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/users/'. $user->getUnixName() .'.git</tt></p></td><tr>';
+			}
+			$returnhtml .= '</table>';
+			return $returnhtml;
+		} else {
+			return '<p class="information">'._('No personal git repository').'</div>';
+		}
+	}
+
+	function getMyRepositoriesList() {
+		$returnedArray = array();
+		$res = db_query_params('SELECT p.group_id FROM plugin_scmgit_personal_repos p, users u WHERE u.user_id=p.user_id AND u.unix_status = $1 AND u.user_id = $2',
+					array('A',$this->owner_id));
+		if (!$res) {
+			return $returnedArray;
+		} else {
+			$rows = db_numrows($res);
+			for ($i=0; $i<$rows; $i++) {
+				$returnedArray[] = db_result($res,$i,'group_id');
+			}
+		}
+		return $returnedArray;
+	}
+}
+
+?>




More information about the Fusionforge-commits mailing list