[Fusionforge-commits] r10710 - trunk/src/common/include

Roland Mas lolando at libremir.placard.fr.eu.org
Sun Sep 26 11:50:32 CEST 2010


Author: lolando
Date: 2010-09-26 11:50:32 +0200 (Sun, 26 Sep 2010)
New Revision: 10710

Modified:
   trunk/src/common/include/Group.class.php
   trunk/src/common/include/User.class.php
Log:
Less SQL, more code reuse, and less user_group

Modified: trunk/src/common/include/Group.class.php
===================================================================
--- trunk/src/common/include/Group.class.php	2010-09-25 23:52:00 UTC (rev 10709)
+++ trunk/src/common/include/Group.class.php	2010-09-26 09:50:32 UTC (rev 10710)
@@ -2459,19 +2459,25 @@
 	 *	@access public
 	 */
 	function sendRejectionEmail($response_id, $message="zxcv") {
-		$res_admins = db_query_params ('
-			SELECT u.email, u.language, u.user_id
-			FROM users u, user_group ug
-			WHERE ug.group_id=$1
-			AND u.user_id=ug.user_id',
-					       array ($this->getID())) ;
-		if (db_numrows($res_admins) < 1) {
+		$submitters = array () ;
+		if (USE_PFO_RBAC) {
+			foreach (get_group_join_requests ($this) as $gjr) {
+				$submitters[] =  user_get_object($gjr->getUserID()) ;
+			}
+		} else {
+			$res = db_query_params("SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND u.user_id=ug.user_id",
+					       $this->getID());
+			while ($arr = db_fetch_array ($res)) {
+				$submitter[] =& user_get_object($arr['user_id']);
+			}
+		}
+
+		if (count ($submitters) < 1) {
 			$this->setError(_("Group does not have any administrators."));
 			return false;
 		}
-		
-		while ($row_admins = db_fetch_array($res_admins)) {
-			$admin =& user_get_object($row_admins['user_id']);
+
+		foreach ($submitters as $admin) {
 			setup_gettext_for_user ($admin) ;
 
 			$response=sprintf(_('Your project registration for %3$s has been denied.
@@ -2493,7 +2499,7 @@
 					"response_text");
 			}
 
-			util_send_message($row_admins['email'], sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
+			util_send_message($admin->getEmail(), sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
 			setup_gettext_from_context();
 		}
 
@@ -2512,17 +2518,23 @@
 	 */
 	function sendNewProjectNotificationEmail() {
 		// Get the user who wants to register the project
-		$res = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1',
-					array ($this->getID())) ;
-
-		if (db_numrows($res) < 1) {
+		$submitters = array () ;
+		if (USE_PFO_RBAC) {
+			foreach (get_group_join_requests ($this) as $gjr) {
+				$submitters[] =  user_get_object($gjr->getUserID()) ;
+			}
+		} else {
+			$res = db_query_params("SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND u.user_id=ug.user_id",
+					       $this->getID());
+			while ($arr = db_fetch_array ($res)) {
+				$submitter[] =& user_get_object($arr['user_id']);
+			}
+		}
+		if (count ($submitters) < 1) {
 			$this->setError(_("Could not find user who has submitted the project."));
 			return false;
 		}
 		
-		$submitter =& user_get_object(db_result($res,0,'user_id'));
-
-
 		$admins = RBACEngine::getInstance()->getUsersByAllowedAction ('project_approve', -1) ;
 
 		if (count($admins) < 1) {
@@ -2533,21 +2545,31 @@
 		foreach ($admins as $admin) {
 			$admin_email = $admin->getEmail () ;
 			setup_gettext_for_user ($admin) ;
+
+			foreach ($submitters as $u) {
+				$submitter_names[] = $u->getRealName() ;
+			}
 			
-			$message=sprintf(_('New %1$s Project Submitted
+			$message = sprintf(_('New %1$s Project Submitted
 
 Project Full Name:  %2$s
 Submitted Description: %3$s
-Submitter: %5$s (%6$s)
+'),
+					   forge_get_config ('forge_name'),
+					   htmlspecialchars_decode($this->getPublicName()),
+					   htmlspecialchars_decode($this->getRegistrationPurpose()));
+			
+			foreach ($submitters as $submitter) {
+				$message .= sprintf(_('Submitter: %1$s (%2$s)
+'),
+						    $submitter->getRealName(), 
+						    $submitter->getUnixName());
+			}
 
+			$message .= sprintf (_('
 Please visit the following URL to approve or reject this project:
-%4$s'),
-						       forge_get_config ('forge_name'),
-						       htmlspecialchars_decode($this->getPublicName()),
-						       htmlspecialchars_decode($this->getRegistrationPurpose()),
-						       util_make_url ('/admin/approve-pending.php'),
-						       $submitter->getRealName(), 
-						       $submitter->getUnixName());
+%1$s'),
+					    util_make_url ('/admin/approve-pending.php')) ;
 			util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
 			setup_gettext_from_context();
 		}

Modified: trunk/src/common/include/User.class.php
===================================================================
--- trunk/src/common/include/User.class.php	2010-09-25 23:52:00 UTC (rev 10709)
+++ trunk/src/common/include/User.class.php	2010-09-26 09:50:32 UTC (rev 10710)
@@ -1143,29 +1143,20 @@
 	 *	@return array	Array of groups.
 	 */
 	function &getGroups($onlylocal = true) {
-
-		if (USE_PFO_RBAC) {
-			$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($this) ;
-			$ids = array () ;
-			foreach ($roles as $r) {
-				if ($onlylocal) {
-					if ($r instanceof RoleExplicit
-					    && $r->getHomeProject() != NULL) {
-						$ids[] = $r->getHomeProject()->getID() ;
-					}
-				} else {
-					foreach ($r->getLinkedProjects() as $p) {
-						$ids[] = $p->getID() ;
-					}
+		$ids = array () ;
+		foreach ($this->getRoles() as $r) {
+			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)) ;
-		} else {
-			$res = db_query_params ('SELECT group_id FROM user_group WHERE user_id=$1',
-						array ($this->getID())) ;
-			$arr =& util_result_column_to_array($res,0);	
-			return group_get_objects($arr);
 		}
+		return group_get_objects(array_unique($ids)) ;
 	}
 
 	/**
@@ -1520,30 +1511,14 @@
 	 *  @return object  Role object
 	 */
 	function getRole(&$group) {
-		if (!$group || !is_object($group)) {
-			$this->setError('User::getRole : Unable to get group object');
-			return false;
+		foreach ($this->getRoles () as $r) {
+			if ($r instanceof RoleExplicit
+			    && $r->getHomeProject() != NULL
+			    && $r->getHomeProject()->getID() == $group->getID()) {
+				return $r ;
+			}
 		}
-		$res = db_query_params ('SELECT role_id FROM user_group WHERE user_id=$1 AND group_id=$2',
-					array ($this->getID(),
-					       $group->getID())) ;
-		if (!$res || db_numrows($res) < 1) {
-			$this->setError('User::getRole::DB - Could Not get role_id '.db_error());
-			return false;
-		}
-		$role_id = db_result($res,0,'role_id');
-		//
-		//  Role setup
-		//
-		$role = new Role($group,$role_id);
-		if (!$role || !is_object($role)) {
-			$this->setError('Error Getting Role Object');
-			return false;
-		} elseif ($role->isError()) {
-			$this->setError('User::getRole::roleget::'.$role->getErrorMessage());
-			return false;
-		}
-		return $role;
+		return false ;
 	}
 
 	function getRoles () {




More information about the Fusionforge-commits mailing list