[opw-web] manage_projects: Flag projects when there are potential duplicates
- From: Owen Taylor <otaylor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [opw-web] manage_projects: Flag projects when there are potential duplicates
- Date: Tue, 1 Apr 2014 14:59:32 +0000 (UTC)
commit 39180472e2ee09ae8f9c002372c03b02f04e62c3
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Tue Apr 1 10:26:55 2014 -0400
manage_projects: Flag projects when there are potential duplicates
When a student has submitted multiple projects, add a (Multiple) badge;
when the student has submitted multiple projects that organizations
are wanting to accept, make the badge red. Add a hover on the badge
to explain what it is about.
lang/en-gb.php | 4 +++
modules/mod_manage_projects.php | 47 ++++++++++++++++++++++++++++++++++----
utils.php | 20 +++++++++++++++-
3 files changed, 65 insertions(+), 6 deletions(-)
---
diff --git a/lang/en-gb.php b/lang/en-gb.php
index 973d8f5..eac69a2 100644
--- a/lang/en-gb.php
+++ b/lang/en-gb.php
@@ -162,6 +162,10 @@ $lang_data = array(
'opinion_g' => 'Will accept for GSoC',
'opinion_w' => 'Want to accept, need funding',
'opinion_f' => 'Will accept, have funding',
+ 'multiple_projects' => 'Multiple',
+ 'multiple_projects_submit' => 'Student has submitted multiple projects',
+ 'multiple_projects_accept' => 'Organizations are planning to accept multiple projects from this student',
+
/* Module: view_projects */
'edit_project' => 'Edit project',
diff --git a/modules/mod_manage_projects.php b/modules/mod_manage_projects.php
index 05f9317..4656483 100644
--- a/modules/mod_manage_projects.php
+++ b/modules/mod_manage_projects.php
@@ -53,15 +53,45 @@ $user->restrict($role == 'm', true);
$organization_select = build_organization_select($program_id, $organization_id, false, false,
false, null, "organizationSelect");
+// We want to be able to flag when the user has submitted multiple projects
+// and especially when multiple organizations want to accept the same student
+// 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 " .
"LEFT JOIN {$db->prefix}participants prt " .
"ON prj.id = prt.project_id " .
- "WHERE prj.organization_id = ? " .
- "AND prt.role = 's'";
- $list_data = $db->query($sql, $organization_id);
+ "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 " .
+ "ON prj.id = prt.project_id " .
+ "WHERE prj.organization_id = :organization_id " .
+ "AND prt.role = 's')";
+ $raw_data = $db->query($sql, array('program_id' => $program_id,
+ 'organization_id' => $organization_id));
} else {
- $list_data = array();
+ $raw_data = array();
+}
+
+$list_data = array();
+$user_submit_count = array();
+$user_accept_count = array();
+
+foreach ($raw_data as $row) {
+ if ($row['organization_id'] == $organization_id)
+ $list_data[] = $row;
+
+ $username = $row['username'];
+ if (!isset($user_submit_count[$username]))
+ $user_submit_count[$username] = 0;
+ if (!isset($user_accept_count[$username]))
+ $user_accept_count[$username] = 0;
+
+ if ($row['is_withdrawn'] != 1) {
+ $user_submit_count[$username]++;
+ if (opinion_is_accept ($row['org_opinion']))
+ $user_accept_count[$username]++;
+ }
}
// See if we need to save anything
@@ -101,6 +131,11 @@ if ($rankings_save && $can_edit) {
"WHERE id = :project_id";
$db->query($sql, array('org_opinion' => $value,
'project_id' => $project_id));
+
+ $old_accept_count = opinion_is_accept($row['org_opinion']) ? 1 : 0;
+ $new_accept_count = opinion_is_accept($value) ? 1 : 0;
+ $user_accept_count[$row['username']] += ($new_accept_count - $old_accept_count);
+
$row['org_opinion'] = $value;
}
}
@@ -142,6 +177,8 @@ foreach ($list_data as &$row)
{
$project_title = htmlspecialchars($row['title']);
$username = $row['username'];
+ $submit_count = $user_submit_count[$username];
+ $accept_count = $user_accept_count[$username];
$profile = $user->profile($username);
// Trim the title to 60 characters
@@ -163,7 +200,7 @@ foreach ($list_data as &$row)
'project_applicant' => $profile,
'ranking' => $ranking,
'ranking_name' => 'ranking' . $project_id,
- 'badges' => build_project_badges($role, $row),
+ 'badges' => build_project_badges($role, $row, $submit_count, $accept_count),
'disabled' => $can_edit ? '' : ' disabled',
'opinion_select' => build_opinion_select($row['org_opinion'], 'opinion' . $project_id,
!$can_edit),
'project_url' => "?q=view_projects&prg={$program_id}&p={$project_id}",
diff --git a/utils.php b/utils.php
index 05daf8a..a6fa436 100644
--- a/utils.php
+++ b/utils.php
@@ -40,6 +40,8 @@ function build_organization_select($program_id, $current, $include_other, $only_
}
$VALID_OPINIONS = array('n', 'y', 'c', 'x', 'g', 'w', 'f');
+# Opinions that indicate an interest in accepting a project
+$ACCEPT_OPINIONS = array('g', 'w', 'f');
function build_opinion_select($current, $name, $disabled=false) {
global $VALID_OPINIONS, $lang;
@@ -65,12 +67,28 @@ function opinion_is_valid($value) {
return in_array($value, $VALID_OPINIONS);
}
-function build_project_badges($role, $project_data) {
+function opinion_is_accept($value) {
+ global $ACCEPT_OPINIONS;
+
+ return in_array($value, $ACCEPT_OPINIONS);
+}
+
+function build_project_badges($role, $project_data, $submit_count, $accept_count) {
global $lang, $user;
$result = '';
if ($project_data['is_withdrawn'] == 1) {
$result .= ' <span class="badge">' . $lang->get('withdrawn') . '</span>';
+ } else if ($role == 'm' || $user->is_admin) {
+ if ($accept_count > 1 && opinion_is_accept($project_data['org_opinion'])) {
+ $result .= ' <span class="badge badge-important" title="' .
+ $lang->get('multiple_projects_accept') . '">' .
+ $lang->get('multiple_projects') . '</span>';
+ } else if ($submit_count > 1) {
+ $result .= ' <span class="badge badge-info" title="' .
+ $lang->get('multiple_projects_submit') . '">' .
+ $lang->get('multiple_projects') . '</span>';
+ }
}
if ($role == 'm' || $user->is_admin) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]