[opw-web] Allow mentors to remove themselves (before mentorship deadline)



commit 4f4118820b821bba8881ecd42dc7c2cf0642a391
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Mon Mar 10 15:01:06 2014 -0400

    Allow mentors to remove themselves (before mentorship deadline)
    
    Allow users to remove themselves as mentors (up to the point where
    where the accepted projects are announced.)

 lang/en-gb.php                                |    4 ++-
 modules/mod_view_projects.php                 |   29 ++++++++++++++++++++++--
 skins/easterngreen/html/tpl_view_project.html |    5 ++++
 3 files changed, 34 insertions(+), 4 deletions(-)
---
diff --git a/lang/en-gb.php b/lang/en-gb.php
index 838e1f6..6ef1b78 100644
--- a/lang/en-gb.php
+++ b/lang/en-gb.php
@@ -155,6 +155,7 @@ $lang_data = array(
     'edit_project'          => 'Edit project',
     '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',
     'project_updated'       => 'Project updated successfully',
     'project_home'          => 'Program home',
     'project_complete'      => 'Project complete?',
@@ -163,7 +164,8 @@ $lang_data = array(
     'failed'                => 'Failed',
     'undecided'             => 'Undecided',
     'confirm_project_del'   => 'Deletion of a project is irreversible. Are you sure you want to continue?',
-    'mentor_project'        => 'Mentor this project',
+    'mentor_project'        => 'Willing to mentor',
+    'mentor_remove'         => 'Remove myself as mentor',
     'view_project'          => 'View project details',
     'project_accepted'      => 'Project accepted?',
     'your_projects'         => 'Your projects',
diff --git a/modules/mod_view_projects.php b/modules/mod_view_projects.php
index a91fe5e..5ce61e8 100644
--- a/modules/mod_view_projects.php
+++ b/modules/mod_view_projects.php
@@ -24,6 +24,7 @@ $page = $core->variable('pg', 1);
 $limit_start = ($page - 1) * $config->per_page;
 
 $mentor_apply = isset($_POST['mentor_apply']);
+$mentor_remove = isset($_POST['mentor_remove']);
 $project_save = isset($_POST['project_save']);
 $confirm = isset($_POST['yes']);
 
@@ -443,7 +444,7 @@ else if ($action == 'view')
     $can_view_mentor = $project_data['is_accepted'] == 1 || $user->is_admin || $role == 'm';
 
     // Assign participant data
-    $mentor = '-';
+    $mentor = null;
     $has_mentor = false;
     $passed = -1;
 
@@ -504,6 +505,26 @@ else if ($action == 'view')
         $accepted = $lang->get('undecided');
     }
 
+    $can_remove_mentor = ($core->timestamp < $program_data['dl_mentor']) && $user->username == $mentor;
+
+    // User removed themselves as mentor
+    if ($mentor_remove && $can_remove_mentor)
+    {
+        $sql = "DELETE FROM {$db->prefix}participants " .
+               "WHERE username = :username AND project_id = :project_id";
+        $db->query($sql, array('username' => $user->username,
+                               'project_id' => $project_id));
+
+        $success_message = $lang->get('mentor_removed');
+        $mentor = null;
+        $has_mentor = false;
+        $can_remove_mentor = false;
+        $is_owner = false;
+
+        // Purge project data
+        $cache->purge('projects');
+    }
+
     // 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
@@ -527,6 +548,7 @@ else if ($action == 'view')
 
         $success_message = $lang->get('mentor_submitted');
         $can_mentor = false;
+        $can_remove_mentor = true;
         // 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;
@@ -583,7 +605,7 @@ 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'            => $user->profile($mentor, true),
+        'project_mentor'            => $mentor ? $user->profile($mentor, true) : '-',
         'project_accepted'          => $accepted,
         'project_complete'          => $complete,
         'project_result'            => $result,
@@ -597,7 +619,8 @@ else if ($action == 'view')
         'attachments_visibility'    => $skin->visibility(count($attachment_data) > 0),
         'delete_visibility'         => $skin->visibility($user->is_admin),
         'mentor_project_visibility' => $skin->visibility($can_mentor),
-        'actions_visibility'        => $skin->visibility($is_owner || $can_mentor || $user->is_admin),
+        'mentor_remove_visibility'  => $skin->visibility($can_remove_mentor),
+        'actions_visibility'        => $skin->visibility($is_owner || $can_mentor || $can_remove_mentor || 
$user->is_admin),
         'subscribe_visibility'      => $skin->visibility(isset($show_subscribe)),
         'approve_visibility'        => $skin->visibility($can_approve),
         'reject_visibility'         => $skin->visibility($can_reject),
diff --git a/skins/easterngreen/html/tpl_view_project.html b/skins/easterngreen/html/tpl_view_project.html
index 3d5f582..e9ac7b5 100644
--- a/skins/easterngreen/html/tpl_view_project.html
+++ b/skins/easterngreen/html/tpl_view_project.html
@@ -75,6 +75,11 @@
             {{mentor_project}}
         </button>
 
+        <button type="submit" name="mentor_remove" class="btn [[mentor_remove_visibility]]">
+            <i class="icon-briefcase icon-black"></i>
+            {{mentor_remove}}
+        </button>
+
         <a href="?q=view_projects&amp;a=delete&amp;prg=[[program_id]]&amp;p=[[project_id]]"
            class="btn btn-danger delete-button [[delete_visibility]]">
             <i class="icon-trash icon-white"></i>


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