[Fusionforge-commits] r13178 - in trunk/src: common/include plugins/oslc/include

Olivier Berger olberger at fusionforge.org
Wed Apr 20 18:40:00 CEST 2011


Author: olberger
Date: 2011-04-20 18:39:59 +0200 (Wed, 20 Apr 2011)
New Revision: 13178

Modified:
   trunk/src/common/include/utils.php
   trunk/src/plugins/oslc/include/compactResource.class.php
   trunk/src/plugins/oslc/include/oslcPlugin.class.php
Log:
Improve slightly the compactresource

Modified: trunk/src/common/include/utils.php
===================================================================
--- trunk/src/common/include/utils.php	2011-04-19 21:00:55 UTC (rev 13177)
+++ trunk/src/common/include/utils.php	2011-04-20 16:39:59 UTC (rev 13178)
@@ -1144,19 +1144,20 @@
  * @param string $size
  * @return string
  */
-function util_display_user($username, $user_id,$text, $size='xs') {
-	$hook_params = array();
-	$hook_params['resource_type'] = 'user';
-        $hook_params['username'] = $username;
-        $hook_params['user_id'] = $user_id;
-        $hook_params['user_link'] = '';
-        plugin_hook_by_reference("user_link_with_tooltip", $hook_params);
+function util_display_user($username, $user_id, $text, $size='xs') {
+		// Invoke user_link_with_tooltip plugin
+  		$hook_params = array('resource_type' => 'user', 'username' => $username, 'user_id' => $user_id, 'size' => $size, 'user_link' => '');
+        plugin_hook_by_reference('user_link_with_tooltip', $hook_params);
         if($hook_params['user_link'] != ''){
                 return $hook_params['user_link'];
         }
 
+        // If no plugin replaced it, then back to default standard link
+        
+        // Invoke user_logo plugin (see gravatar plugin for instance)
         $params = array('user_id' => $user_id, 'size' => $size, 'content' => '');
         plugin_hook_by_reference('user_logo', $params);
+        
         $url = '<a href="' . util_make_url_u ($username, $user_id) . '">' . $text . '</a>';
         if ($params['content']) {
                 return $params['content'].$url.'<div class="new_line"></div>';
@@ -1265,6 +1266,10 @@
 	return true;
 }
 
+/**
+ * Adds the Javascript file to the lits to be used
+ * @param unknown_type $js
+ */
 function use_javascript($js) {
 	return $GLOBALS['HTML']->addJavascript($js);
 }

Modified: trunk/src/plugins/oslc/include/compactResource.class.php
===================================================================
--- trunk/src/plugins/oslc/include/compactResource.class.php	2011-04-19 21:00:55 UTC (rev 13177)
+++ trunk/src/plugins/oslc/include/compactResource.class.php	2011-04-20 16:39:59 UTC (rev 13178)
@@ -18,43 +18,66 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  *
- * This program has been developed in the frame of the HELIOS
+ * This program has been developed in the frame of the COCLICO
  * project with financial support of its funders.
  *
  */
 
+/**
+ * Enter description here ...
+ * @param unknown_type $params
+ */
 class compactResource {
 	public $params;
 	
+	
 	public function __construct($params) {
 		$this->params = $params;
 	}
 	
 	public function getResourceLink() {
-		if($this->params['resource_type'] == 'user') {
-			return $this->getUserLink($this->params['username'], $this->params['user_id']);
-		} elseif($this->params['resource_type'] == 'group') {
-			return $this->getProjectLink($this->params['group_name'], $this->params['group_id'], $this->params['link_text']);
-		} elseif($this->params['resource_type'] == 'artifact') {
-			return $this->getArtifactLink();
-		} else {
-			return 'Unknown resource type !';
+		// TBD.
+	}
+	
+	public static function createCompactResource($params) {
+		switch ($params['resource_type']) {
+			case 'user' :
+				return new UserCompactResource($params);
+				break;
+			case 'group' :
+				return new GroupCompactResource($params);
+				break;
+			case 'artifact' :
+				return new compatResource($params);
+				break;
+			default :
+				return 'Unknown resource type !';
+				break;
 		}
 	}
-	
-	public function getUserLink($username, $user_id) {
+}
+
+class UserCompactResource extends compactResource {
+
+	public function getResourceLink() {
+		$username = $this->params['username'];
+		$user_id = $this->params['user_id'];
 		return '<a class="resourcePopupTrigger" href="'. util_make_url_u ($username, $user_id) .
 				'" rel="user,' . $username . '">'. $username . '</a>';
 	}	
 	
-	public function getProjectLink($group_name, $group_id, $link_text) {
+}
+
+class GroupCompactResource extends compactResource {
+	
+	public function getResourceLink() {
+		$group_name = $this->params['group_name'];
+		$group_id = $this->params['group_id'];
+		$link_text = $this->params['link_text'];
 		return '<a class="resourcePopupTrigger" href="'. util_make_url_g ($group_name, $group_id) .
 				'" rel="project,' . $group_name . '">'. $link_text . '</a>';
 	}
 	
-	public function getArtifactLink() {
-		// TBD.
-	}
-} 
+}
 
 ?>
\ No newline at end of file

Modified: trunk/src/plugins/oslc/include/oslcPlugin.class.php
===================================================================
--- trunk/src/plugins/oslc/include/oslcPlugin.class.php	2011-04-19 21:00:55 UTC (rev 13177)
+++ trunk/src/plugins/oslc/include/oslcPlugin.class.php	2011-04-20 16:39:59 UTC (rev 13178)
@@ -160,15 +160,33 @@
 		}
 		elseif ($hookname == "user_link_with_tooltip"){
 			require_once dirname( __FILE__ ) . '/compactResource.class.php';
-			$cR = new compactResource($params);
+			$cR = compactResource::createCompactResource($params);
 			$params['user_link'] = $cR->getResourceLink();
 		}
 		elseif ($hookname == "project_link_with_tooltip") {
 			require_once dirname( __FILE__ ) . '/compactResource.class.php';
-			$cR = new compactResource($params);
+			$cR = compactResource::createCompactResource($params);
 			$params['group_link'] = $cR->getResourceLink();			
+			/*
+			// replace behaviour of util_display_user()
+		
+			// invoke user_logo hook
+			$logo_params = array('user_id' => $params['user_id'], 'size' => $params['size'], 'content' => '');
+        	plugin_hook_by_reference('user_logo', $logo_params);
+        
+        	// construct a link that is the base for a hover popup.
+        	$url = '<a class="personPopupTrigger" href="'. util_make_url_u ($params['username'], $params['user_id']) .
+				'" rel="' . $params['username'] . '">'. $params['username'] . '</a>';
+        	if ($logo_params['content']) {
+                $params['user_link'] = $logo_params['content'] . $url .'<div class="new_line"></div>';
+        	}
+			else {
+				$params['user_link'] = $url;
+			}
+			*/
 		}
 		elseif ($hookname == "javascript_file") {
+			// The userTooltip.js script is used by the compact preview feature (see content_negociated_user_home)
 			use_javascript('/scripts/jquery/jquery.js');
 			use_javascript('/plugins/oslc/scripts/oslcTooltip.js');
 		}




More information about the Fusionforge-commits mailing list