[opw-web] Allow passing the fullname when building profile links
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [opw-web] Allow passing the fullname when building profile links
- Date: Fri, 4 Apr 2014 14:44:55 +0000 (UTC)
commit b6af1f0d8cc82155c8e25a7220f70eea522e4788
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Fri Apr 4 10:42:55 2014 -0400
Allow passing the fullname when building profile links
Instead of necessarily doing a database query, allow the user's
fullname to be passed in to $user->profile(). Use this to optimize
lists of mentors/project proposers/participants.
classes/class_user.php | 13 ++++++++-----
modules/mod_approve_mentors.php | 4 +++-
modules/mod_manage_projects.php | 6 ++++--
modules/mod_view_participants.php | 7 +++++--
4 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/classes/class_user.php b/classes/class_user.php
index 935b6c5..fb427ee 100644
--- a/classes/class_user.php
+++ b/classes/class_user.php
@@ -491,16 +491,19 @@ class user
}
// Gets the profile link for a user
- function profile($username, $return = false)
+ function profile($username, $return = false, $fullname = null)
{
global $core;
if ($username == '-')
return $username;
- $info = $this->lookup_user($username);
- if ($info === null)
- return htmlspecialchars($username);
+ if ($fullname === null) {
+ $info = $this->lookup_user($username);
+ if ($info === null)
+ return htmlspecialchars($username);
+ $fullname = $info['fullname'];
+ }
$username_url = urlencode($username);
$profile_url = "?q=user_profile&u={$username_url}";
@@ -511,7 +514,7 @@ class user
$profile_url .= '&r=' . urlencode($redir_url);
}
- return '<a href="' . htmlspecialchars($profile_url) . '">' . htmlspecialchars($info['fullname']) .
'</a>';
+ return '<a href="' . htmlspecialchars($profile_url) . '">' . htmlspecialchars($fullname) . '</a>';
}
// Get the role and organization of the current user
diff --git a/modules/mod_approve_mentors.php b/modules/mod_approve_mentors.php
index e7721f6..6e40b60 100644
--- a/modules/mod_approve_mentors.php
+++ b/modules/mod_approve_mentors.php
@@ -46,8 +46,10 @@ if (!empty($action) && !empty($username))
// Get the proposed mentors list
$sql = "SELECT ".
"r.username as username, " .
+ "pf.fullname as fullname, " .
"o.title as organization_title " .
"FROM {$db->prefix}roles r " .
+ "LEFT JOIN {$db->prefix}profiles pf on pf.username = r.username " .
"LEFT JOIN {$db->prefix}organizations o on o.id = r.organization_id " .
"WHERE role = 'i'";
$list_data = $db->query($sql);
@@ -61,7 +63,7 @@ foreach ($list_data as $row)
// Assign data for each mentor
$skin->assign(array(
- 'mentor_name' => $user->profile($row['username'], true),
+ 'mentor_name' => $user->profile($row['username'], true, $row['fullname']),
'organization' => htmlspecialchars($row['organization_title']),
'approve_url' => "?q=approve_mentors&a=approve&u={$mentor_url}",
'reject_url' => "?q=approve_mentors&a=reject&u={$mentor_url}",
diff --git a/modules/mod_manage_projects.php b/modules/mod_manage_projects.php
index 4656483..834a193 100644
--- a/modules/mod_manage_projects.php
+++ b/modules/mod_manage_projects.php
@@ -58,9 +58,11 @@ $organization_select = build_organization_select($program_id, $organization_id,
// so we query for all projects submitted by users that have submitted
// projects to this organization, and sort out the projects to display afterwards.
if ($organization_id > 0) {
- $sql = "SELECT * FROM {$db->prefix}projects prj " .
+ $sql = "SELECT prj.*, prt.*, pf.fullname FROM {$db->prefix}projects prj " .
"LEFT JOIN {$db->prefix}participants prt " .
"ON prj.id = prt.project_id " .
+ "LEFT JOIN {$db->prefix}profiles pf " .
+ "ON prt.username = pf.username " .
"WHERE prt.program_id = :program_id AND prt.role = 's' AND prt.username IN (" .
"SELECT prt.username from {$db->prefix}projects prj " .
"LEFT JOIN {$db->prefix}participants prt " .
@@ -179,7 +181,7 @@ foreach ($list_data as &$row)
$username = $row['username'];
$submit_count = $user_submit_count[$username];
$accept_count = $user_accept_count[$username];
- $profile = $user->profile($username);
+ $profile = $user->profile($username, true, $row['fullname']);
// Trim the title to 60 characters
if (strlen($project_title) > 60)
diff --git a/modules/mod_view_participants.php b/modules/mod_view_participants.php
index 7352db5..910f85b 100644
--- a/modules/mod_view_participants.php
+++ b/modules/mod_view_participants.php
@@ -12,13 +12,16 @@ $program_id = $core->variable('prg', '');
// Get the program's participant list
$sql = "SELECT r.username, r.role AS role, " .
- "pr.id AS project_id, pr.title AS project_title " .
+ "pr.id AS project_id, pr.title AS project_title, " .
+ "pf.fullname " .
"FROM {$db->prefix}roles r " .
"LEFT JOIN {$db->prefix}participants p " .
"ON r.program_id = p.program_id " .
"AND r.username = p.username " .
"LEFT JOIN {$db->prefix}projects pr " .
"ON p.project_id = pr.id ".
+ "LEFT JOIN {$db->prefix}profiles pf " .
+ "ON p.username = pf.username ".
"WHERE r.program_id = {$program_id} " .
"ORDER BY r.role, r.username";
$list_data = $db->query($sql);
@@ -57,7 +60,7 @@ foreach ($list_data as $row)
$list[] = array(
'username' => $row['username'],
- 'profile' => $user->profile($row['username'], true),
+ 'profile' => $user->profile($row['username'], true, $row['fullname']),
'role' => $lang->get('role_' . $row['role']),
'projects' => $project,
);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]