[Fusionforge-commits] r10678 - in trunk/src/common: include widget

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Sep 24 21:36:49 CEST 2010


Author: lolando
Date: 2010-09-24 21:36:49 +0200 (Fri, 24 Sep 2010)
New Revision: 10678

Modified:
   trunk/src/common/include/User.class.php
   trunk/src/common/widget/Widget_MyProjects.class.php
   trunk/src/common/widget/Widget_MySurveys.class.php
   trunk/src/common/widget/Widget_MyTasks.class.php
   trunk/src/common/widget/Widget_ProjectMembers.class.php
Log:
Less SQL (and fewer references to the user_group table), more code reuse

Modified: trunk/src/common/include/User.class.php
===================================================================
--- trunk/src/common/include/User.class.php	2010-09-24 19:06:56 UTC (rev 10677)
+++ trunk/src/common/include/User.class.php	2010-09-24 19:36:49 UTC (rev 10678)
@@ -1136,15 +1136,21 @@
 	 *
 	 *	@return array	Array of groups.
 	 */
-	function &getGroups() {
+	function &getGroups($onlylocal = true) {
 
 		if (USE_PFO_RBAC) {
 			$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($this) ;
 			$ids = array () ;
 			foreach ($roles as $r) {
-				if ($r instanceof RoleExplicit
-				    && $r->getHomeProject() != NULL) {
-					$ids[] = $r->getHomeProject()->getID() ;
+				if ($onlylocal) {
+					if ($r instanceof RoleExplicit
+					    && $r->getHomeProject() != NULL) {
+						$ids[] = $r->getHomeProject()->getID() ;
+					}
+				} else {
+					foreach ($r->getLinkedProjects() as $p) {
+						$ids[] = $p->getID() ;
+					}
 				}
 			}
 			return group_get_objects(array_unique($ids)) ;

Modified: trunk/src/common/widget/Widget_MyProjects.class.php
===================================================================
--- trunk/src/common/widget/Widget_MyProjects.class.php	2010-09-24 19:06:56 UTC (rev 10677)
+++ trunk/src/common/widget/Widget_MyProjects.class.php	2010-09-24 19:36:49 UTC (rev 10678)
@@ -112,43 +112,39 @@
 				    'copyright'   => 'Copyright Xerox',
 				    'pubDate'     => gmdate('D, d M Y G:i:s',time()).' GMT',
 				));
-	    $result = db_query_params("SELECT groups.group_name,"
-			    . "groups.group_id,"
-			    . "groups.unix_group_name,"
-			    . "groups.status,"
-			    . "groups.is_public,"
-			    . "user_group.admin_flags "
-			    . "FROM groups,user_group "
-			    . "WHERE groups.group_id=user_group.group_id "
-			    . "AND user_group.user_id=$1"
-			    . "AND groups.status='A' ORDER BY group_name",array(UserManager::instance()->getCurrentUser()->getID() ));
-	    $rows=db_numrows($result);
+	    $projects = UserManager::instance()->getCurrentUser()->getGroups() ;
+	    sortProjectList ($projects) ;
+
 	    if (!$result || $rows < 1) {
 		    $rss->addItem(array(
-					    'title'       => 'Error',
-					    'description' => _("You're not a member of any project") . db_error(),
-					    'link'        => util_make_url()
-				       ));
-	    } else {
-		    for ($i=0; $i<$rows; $i++) {
-			    $title = db_result($result,$i,'group_name');
-			    if ( db_result($result,$i,'is_public') == 0 ) {
-				    $title .= ' (*)';
-			    }
+					  'title'       => 'Error',
+					  'description' => _("You're not a member of any project") . db_error(),
+					  'link'        => util_make_url()
+					  ));
+		    $rss->display();
+		    return ;
+	    } 
 
-			    $desc = 'Project: '. util_make_url('/project/admin/?group_id='.db_result($result,$i,'group_id')) ."<br />\n";
-			    if ( strpos(db_result($result,$i,'admin_flags') , 'A')==0 ) {
-				    $desc .= 'Admin: '. util_make_url('/project/admin/?group_id='.db_result($result,$i,'group_id'));
-			    }
+	    foreach ($projects as $project) {
+		    $pid = $project->getID() ;
+		    $title = $project->getPublicName() ;
+		    $url = util_make_url('/projects/' . $project->getUnixName()) ;
 
-			    $rss->addItem(array(
-						    'title'       => $title,
-						    'description' => $desc,
-						    'link'        => util_make_url('/projects/'. db_result($result,$i,'unix_group_name'))
-					       ));
+		    if ( !RoleAnonymous::getInstance()->hasPermission('project_read',$pid)) {
+			    $title .= ' (*)';
 		    }
+		    
+		    $desc = "Project: $url\n";
+		    if (forge_check_perm ('project_admin', $pid)) {
+			    $desc .= '<br />Admin: '. util_make_url('/project/admin/?group_id='.$pid);
+		    }
+		    
+		    $rss->addItem(array(
+					  'title'       => $title,
+					  'description' => $desc,
+					  'link'        => $url)
+			    );
 	    }
-	    $rss->display();
     }
     function getDescription() {
 	    return _("List the projects you belong to. Selecting any of these projects brings you to the corresponding Project Summary page.");

Modified: trunk/src/common/widget/Widget_MySurveys.class.php
===================================================================
--- trunk/src/common/widget/Widget_MySurveys.class.php	2010-09-24 19:06:56 UTC (rev 10677)
+++ trunk/src/common/widget/Widget_MySurveys.class.php	2010-09-24 19:36:49 UTC (rev 10678)
@@ -36,24 +36,29 @@
 	function Widget_MySurveys() {
 		$this->Widget('mysurveys');
 		$no_survey = true;
-		$html_my_surveys = '';
-		$sql="SELECT groups.group_id, groups.group_name ".
-			"FROM groups,surveys,user_group ".
-			"WHERE groups.group_id=surveys.group_id ".
-			"AND user_group.group_id=groups.group_id ".
-			"AND groups.status = 'A' ".
-			"AND user_group.user_id=$1 ";
 
-		$result=db_query_params($sql,array(user_getid()));
-		$rows=db_numrows($result);
-		if (!$result || $rows < 1) {
+		$user = session_get_user () ;
+		$projects = $user->getGroups() ;
+		sortProjectList ($projects) ;
+		$tmp = array () ;
+		foreach ($projects as $p) {
+			$sf = new SurveyFactory($p);
+			foreach ($sf->getSurveys() as $s) {
+				$tmp[] = $p ;
+				break ;
+			}
+		}
+		$projects = $tmp ;
+		
+		$html_my_surveys = '';
+		if (count ($projects) < 1) {
 			$html_my_surveys .= _("<P>There are no surveys in your groups.<P><BR>&nbsp;");
 		} else {
 			$request =& HTTPRequest::instance();
 			$html_my_surveys .= '<table style="width:100%">';
-			for ($j=0; $j<$rows; $j++) {
-				$group_id = db_result($result,$j,'group_id');
-				$surveyfacto = new SurveyFactory(group_get_object($group_id));
+			foreach ($projects as $project) {
+				$group_id = $project->getID() ;
+				$surveyfacto = new SurveyFactory($project);
 				$surveys = $surveyfacto->getSurveys();
 				$vItemId = new Valid_UInt('hide_item_id');
 				$vItemId->required();
@@ -79,8 +84,9 @@
 
 				$html = '';
 				$count_new = max(0, $count_diff);
-				for ($i=0; $i<count($surveys); $i++) {
-					$survey=$surveys[$i];
+				$i = 0 ;
+				foreach ($surveys as $survey) {
+					$i++ ;
 					if (!$hide_now) {
 						if ($i % 2 == 0) {
 							$class="bgcolor-white";
@@ -110,24 +116,6 @@
 	$this->content = $html_my_surveys;
 	}
 
-	/*	$sql          = "SELECT * from surveys WHERE survey_id=$1";
-		$result       = db_query_params($sql,array($developer_survey_id));
-		$group_id     = db_result($result, 0, 'group_id');
-		$survey_title = $survey->getSurveyTitle(db_result($result, 0, 'survey_title'));
-
-	// Check that the survey is active
-	$devsurvey_is_active = db_result($result, 0, 'is_active');
-
-	if ($devsurvey_is_active==1) {
-
-	$sql="SELECT * FROM survey_responses ".
-	"WHERE survey_id=$1 AND user_id=$2";
-	$result = db_query_params($sql,array($developer_survey_id,user_getid()));
-
-	if (db_numrows($result) < 1) {
-	$no_survey = false;
-	$this->content .= '<a href="/survey/survey.php?group_id='. $group_id .'&survey_id='. $developer_survey_id .'">'. $survey_title .'</a>';
-	}          */   
 	function getTitle() {
 		return _("Quick Survey");
 	}

Modified: trunk/src/common/widget/Widget_MyTasks.class.php
===================================================================
--- trunk/src/common/widget/Widget_MyTasks.class.php	2010-09-24 19:06:56 UTC (rev 10677)
+++ trunk/src/common/widget/Widget_MyTasks.class.php	2010-09-24 19:36:49 UTC (rev 10678)
@@ -125,15 +125,16 @@
         return $this->content;
     }
     function isAvailable() {
-        $sql = "SELECT * 
-        FROM groups g, user_group ug 
-        WHERE g.group_id = ug.group_id
-        AND ug.user_id = $1
-        AND g.status = 'A'
-        AND g.use_pm = '1'
-        LIMIT 1";
-        $result=db_query_params($sql,array($this->owner_id));
-        return $result && db_numrows($result) > 0 && forge_get_config('use_pm');
+	    if (!forge_get_config('use_pm')) {
+		    return false ;
+	    }
+
+	    foreach (UserManager::instance()->getCurrentUser()->getGroups(false) as $p) {
+		    if ($p->usesPM()) {
+			    return true ;
+		    }
+	    }
+	    return false ;
     }
     
     function getDescription() {

Modified: trunk/src/common/widget/Widget_ProjectMembers.class.php
===================================================================
--- trunk/src/common/widget/Widget_ProjectMembers.class.php	2010-09-24 19:06:56 UTC (rev 10677)
+++ trunk/src/common/widget/Widget_ProjectMembers.class.php	2010-09-24 19:36:49 UTC (rev 10678)
@@ -112,27 +112,6 @@
 		if (!$iam_member) {
 			echo '<p>'.util_make_link ('/project/request.php?group_id='.$group_id,_('Request to join')).'</p>';
 		}
-		/*echo '<span class="develtitle">' . _('Project admins').':</span><br />';
-		  while ($row_admin = db_fetch_array($res_admin)) {
-		  $display_name = '';
-		  $em->processEvent('get_user_display_name', array(
-		  'user_id'           => $row_admin['user_id'],
-		  'user_name'         => $row_admin['user_name'],
-		  'realname'          => $row_admin['realname'],
-		  'user_display_name' => &$display_name
-		  ));
-		  if (!$display_name) {
-		  $display_name = $user_helper->getDisplayNameFromUserId($row_admin['user_id']);
-		  }
-		  echo '<a href="/users/'.$row_admin['user_name'].'/">'. $display_name .'</a><br />';
-		  }
-		  echo '<hr width="100%" size="1" NoShade>';
-		  }
-		  echo '<span class="develtitle">' . _('Developers') . ':</span><br />';
-		// count of developers on this project
-		$res_count = db_query_params("SELECT user_id FROM user_group WHERE group_id=$1",array($group_id));
-		echo db_numrows($res_count);
-		echo ' <a href="/project/memberlist.php?group_id=' . $group_id . '">[' . _('View members') . ']</a>';*/
 }
 public function canBeUsedByProject(&$project) {
 	return true;




More information about the Fusionforge-commits mailing list