[opw-web] Allow multiple mentors for a project



commit cc73b01b1de8e98d46a0089fd2cb665f14fe313f
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Mon May 5 14:31:53 2014 -0400

    Allow multiple mentors for a project
    
    Some of the OPW organizations desire or even require multiple mentors
    for a single project. Add the ability for users to add themselves as
    additional mentors for a project.

 lang/en-gb.php                                |    6 ++-
 modules/mod_view_projects.php                 |   57 ++++++++++++++++--------
 skins/easterngreen/html/tpl_view_project.html |    7 +++-
 3 files changed, 48 insertions(+), 22 deletions(-)
---
diff --git a/lang/en-gb.php b/lang/en-gb.php
index ba8a2c7..e33147e 100644
--- a/lang/en-gb.php
+++ b/lang/en-gb.php
@@ -184,8 +184,8 @@ $lang_data = array(
 
     'project_description'   => 'Application text',
     'proposal_submitted'    => 'Your proposal has been submitted successfully',
-    'mentor_submitted'      => 'You have been successfully added as the project mentor',
-    'mentor_removed'        => 'You are no longer the project mentor',
+    'mentor_submitted'      => 'You have been successfully added as a project mentor for this project',
+    'mentor_removed'        => 'You are no longer a project mentor for this project',
     'project_updated'       => 'Project updated successfully',
     'project_home'          => 'Program home',
     'project_complete'      => 'Project complete?',
@@ -201,6 +201,7 @@ $lang_data = array(
     'confirm_withdraw_exp'  => 'Are you sure you want to withdraw this application?',
     'confirm_project_del'   => 'Deletion of a project is irreversible. Are you sure you want to continue?',
     'mentor_project'        => 'Willing to mentor',
+    'mentor_project_additional' => 'Add myself as additional mentor',
     'mentor_remove'         => 'Remove myself as mentor',
     'view_project'          => 'View project details',
     'project_accepted'      => 'Project accepted?',
@@ -214,6 +215,7 @@ $lang_data = array(
     'apply'                 => 'Apply',
 
     'mentor'                => 'Mentor',
+    'mentors'               => 'Mentors',
     'no_projects'           => 'No projects were found in this category',
     'new_mentor'            => 'New mentor',
     'new_mentor_exp'        => 'Leave blank if you do not wish to change the mentor',
diff --git a/modules/mod_view_projects.php b/modules/mod_view_projects.php
index 4bec14a..0e945c5 100644
--- a/modules/mod_view_projects.php
+++ b/modules/mod_view_projects.php
@@ -464,8 +464,7 @@ else if ($action == 'view')
     $can_view_mentor = $project_data['is_accepted'] == 1 || $user->is_admin || $role == 'm';
 
     // Assign participant data
-    $mentor = null;
-    $has_mentor = false;
+    $mentors = array();
     $passed = -1;
 
     foreach ($participant_data as $participant)
@@ -477,8 +476,7 @@ else if ($action == 'view')
         }
         else if ($can_view_mentor && $participant['role'] == 'm')
         {
-            $has_mentor = true;
-            $mentor = $participant['username'];
+            array_push($mentors, $participant['username']);
         }
     }
 
@@ -519,7 +517,7 @@ else if ($action == 'view')
         $accepted = $lang->get('undecided');
     }
 
-    $can_remove_mentor = ($core->timestamp < $program_data['dl_mentor']) && $user->username == $mentor;
+    $can_remove_mentor = ($core->timestamp < $program_data['dl_mentor']) && in_array($user->username, 
$mentors);
 
     // User removed themselves as mentor
     if ($mentor_remove && $can_remove_mentor)
@@ -532,8 +530,9 @@ else if ($action == 'view')
                                'project_id' => $project_id));
 
         $success_message = $lang->get('mentor_removed');
-        $mentor = null;
-        $has_mentor = false;
+        $index = array_search($user->username, $mentors);
+        if ($index !== false)
+            unset($mentors[$index]);
         $can_remove_mentor = false;
         $is_owner = false;
 
@@ -543,17 +542,19 @@ else if ($action == 'view')
 
     // A user can choose to mentor if:
     //  1. He signed up as a mentor for the program, and
-    //  2. Project doesn't already have a mentor
-    //  3. Project hasn't passed mentor deadline
-    //
-    // We used to have
-    // $core->timestamp < $program_data['dl_mentor']
-    // but we want to allow late mentorship
+    //     is not already a mentor for it.
     //
     // KSoC had:
-    // XXXX 4. Projest has passed student deadline
-    // $core->timestamp > $program_data['dl_student'] &&
-    $can_mentor = ($role == 'm' && !$has_mentor);
+    //  XXXX 2. Project doesn't already have a mentor
+    //       (!$has_mentor)
+    //    We allow multiple mentors
+    //  XXXX 3. Project hasn't passed mentor deadline
+    //       $core->timestamp < $program_data['dl_mentor']
+    //    We allow late mentorship
+    //  XXXX 4. Project has passed student deadline
+    //       $core->timestamp > $program_data['dl_student']
+    //    We alloe mentors to sign up early
+    $can_mentor = ($role == 'm') && !in_array($user->username, $mentors);
 
     // User applied as mentor
     if ($mentor_apply && $can_mentor)
@@ -573,7 +574,7 @@ else if ($action == 'view')
         // Message to subscribe to a mailing list - should be a config variable
         // note confusing use of isset() below - = false won't work
         //$show_subscribe = true;
-        $mentor = $user->username;
+        array_push($mentors, $user->username);
         $is_owner = $project_data['is_accepted'] == 1;
 
         // Purge project data
@@ -618,6 +619,22 @@ else if ($action == 'view')
         $attachments_list .= $skin->output('tpl_view_project_attachment');
     }
 
+    $has_mentor = count($mentors) > 0;
+
+    if ($has_mentor) {
+        $mentor_string = null;
+        foreach ($mentors as $mentor) {
+            if ($mentor_string != null) {
+                $mentor_string .= ", ";
+            }
+            $mentor_string .= $user->profile($mentor, true);
+        }
+    } else {
+        $mentor_string = "-";
+    }
+
+    $mentor_label = count($mentors) > 1 ? $lang->get('mentors') : $lang->get('mentor');
+
     // Assign final skin data
     $skin->assign(array(
         'program_id'                => $program_id,
@@ -626,7 +643,8 @@ else if ($action == 'view')
         'project_organization'      => htmlspecialchars($organization_data ? $organization_data['title'] : 
''),
         'project_description'       => nl2br(htmlspecialchars($project_data['description'])),
         'project_student'           => $user->profile($student, true),
-        'project_mentor'            => $mentor ? $user->profile($mentor, true) : '-',
+        'mentor_label'              => $mentor_label,
+        'project_mentor'            => $mentor_string,
         'project_accepted'          => $accepted,
         'project_complete'          => $complete,
         'project_result'            => $result,
@@ -642,7 +660,8 @@ else if ($action == 'view')
         'delete_visibility'         => $skin->visibility($project_permissions->can_delete),
         'withdraw_visibility'       => $skin->visibility($project_permissions->can_withdraw),
         'resubmit_visibility'       => $skin->visibility($project_permissions->can_resubmit),
-        'mentor_project_visibility' => $skin->visibility($can_mentor),
+        'mentor_project_visibility' => $skin->visibility($can_mentor && !$has_mentor),
+        'mentor_project_additional_visibility' => $skin->visibility($can_mentor && $has_mentor),
         'mentor_remove_visibility'  => $skin->visibility($can_remove_mentor),
         'actions_visibility'        => $skin->visibility(($is_owner && $project_permissions->can_edit) ||
                                                          $can_mentor || $can_remove_mentor || 
$user->is_admin),
diff --git a/skins/easterngreen/html/tpl_view_project.html b/skins/easterngreen/html/tpl_view_project.html
index 253755d..f4cfefc 100644
--- a/skins/easterngreen/html/tpl_view_project.html
+++ b/skins/easterngreen/html/tpl_view_project.html
@@ -42,7 +42,7 @@
     </div>
 
     <div class="row [[mentor_visibility]]">
-        <div class="span2">{{mentor}}</div>
+        <div class="span2">[[mentor_label]]</div>
         <div class="span8">[[project_mentor]]</div>
     </div>
 
@@ -79,6 +79,11 @@
             {{mentor_project}}
         </button>
 
+        <button type="submit" name="mentor_apply" class="btn [[mentor_project_additional_visibility]]">
+            <i class="icon-briefcase icon-black"></i>
+            {{mentor_project_additional}}
+        </button>
+
         <button type="submit" name="mentor_remove" class="btn [[mentor_remove_visibility]]">
             <i class="icon-briefcase icon-black"></i>
             {{mentor_remove}}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]