[opw-web] Allow mentors to add/remove themselves until their contract is approved



commit c7883f4883a1644f5358c3056ccc5e7228362af3
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Mon May 5 14:42:10 2014 -0400

    Allow mentors to add/remove themselves until their contract is approved
    
    Instead  of using the mentor deadline to keep mentors from confusing
    the situation, allow mentors to remove themselves at any time *until*
    their mentorship contract is approved.
    
    Once the mentorship contract is approved, a mentor also cannot add
    themselves for additional projects, since that would require changes
    to the contract.

 modules/mod_view_projects.php |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/modules/mod_view_projects.php b/modules/mod_view_projects.php
index 0e945c5..912853a 100644
--- a/modules/mod_view_projects.php
+++ b/modules/mod_view_projects.php
@@ -517,7 +517,20 @@ else if ($action == 'view')
         $accepted = $lang->get('undecided');
     }
 
-    $can_remove_mentor = ($core->timestamp < $program_data['dl_mentor']) && in_array($user->username, 
$mentors);
+    // Once a mentor's contract is approved, they can no longer add or remove
+    // themselves from mentors without administrative intervention.
+    $contract_approved = false;
+    if ($role == 'm') {
+        $sql = "SELECT contract_approved FROM {$db->prefix}roles r " .
+               "WHERE r.program_id = :program_id AND r.username = :username";
+        $row = $db->query($sql,
+                          array('program_id' => $program_id,
+                                'username' => $user->username),
+                          true);
+        $contract_approved = $row['contract_approved'] != 0;
+    }
+
+    $can_remove_mentor = in_array($user->username, $mentors) && !$contract_approved;
 
     // User removed themselves as mentor
     if ($mentor_remove && $can_remove_mentor)
@@ -543,6 +556,8 @@ else if ($action == 'view')
     // A user can choose to mentor if:
     //  1. He signed up as a mentor for the program, and
     //     is not already a mentor for it.
+    //  2. He doesn't have an approved mentor contract
+    //     for this program.
     //
     // KSoC had:
     //  XXXX 2. Project doesn't already have a mentor
@@ -554,7 +569,7 @@ else if ($action == 'view')
     //  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);
+    $can_mentor = ($role == 'm') && !in_array($user->username, $mentors) && !$contract_approved;
 
     // User applied as mentor
     if ($mentor_apply && $can_mentor)
@@ -570,7 +585,7 @@ else if ($action == 'view')
 
         $success_message = $lang->get('mentor_submitted');
         $can_mentor = false;
-        $can_remove_mentor = true;
+        $can_remove_mentor = !$contract_approved;
         // 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;


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