[opw-web] Fix visibility of apply_student/apply_mentor on front page



commit 8ee7ede7cb20f0f8497452f67d0b597f79dd471d
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Wed Mar 19 11:20:15 2014 -0400

    Fix visibility of apply_student/apply_mentor on front page
    
    Things got confused so that apply_student was only shown to people
    that were already students. Fix.

 modules/mod_program_home.php                  |    2 +
 skins/easterngreen/html/tpl_program_home.html |    4 +-
 utils.php                                     |   33 ++++++++++++++++++++----
 3 files changed, 31 insertions(+), 8 deletions(-)
---
diff --git a/modules/mod_program_home.php b/modules/mod_program_home.php
index dc82adf..efdf2c3 100644
--- a/modules/mod_program_home.php
+++ b/modules/mod_program_home.php
@@ -52,6 +52,8 @@ if ($program_data != null)
         'prg_student_visibility'   => $skin->visibility($role == 's'),
         'prg_interm_visibility'    => $skin->visibility($role == 'i'),
         'prg_mentor_visibility'    => $skin->visibility($role == 'm'),
+        'apply_student_visibility' => $skin->visibility($project_permissions->can_apply_student),
+        'apply_mentor_visibility' => $skin->visibility($project_permissions->can_apply_mentor),
         'dl_student_visibility'    => $skin->visibility($show_student),
         'late_submission_visibility' => $skin->visibility($late_submission),
         'dl_mentor_visibility'     => $skin->visibility($show_mentor),
diff --git a/skins/easterngreen/html/tpl_program_home.html b/skins/easterngreen/html/tpl_program_home.html
index d87f0da..0394282 100644
--- a/skins/easterngreen/html/tpl_program_home.html
+++ b/skins/easterngreen/html/tpl_program_home.html
@@ -61,13 +61,13 @@
     <div class="program-actions [[user_visibility]]">
         <div class="[[prg_guest_visibility]]">
             <a href="#" onclick="submitForm(event, 
'?q=view_projects&amp;prg=[[program_id]]&amp;a=apply&amp;c=student')"
-               class="btn btn-large [[dl_student_visibility]]">
+               class="btn btn-large [[apply_student_visibility]]">
                 <img src="[[skin_path]]/images/submit-project.png" width="26" height="26" alt="" />
                 {{apply_student}}
             </a>
 
             <a href="#" onclick="submitForm(event, 
'?q=view_projects&amp;prg=[[program_id]]&amp;a=apply&amp;c=mentor')"
-               class="btn btn-large [[dl_mentor_visibility]]">
+               class="btn btn-large [[apply_mentor_visibility]]">
                 <img src="[[skin_path]]/images/mentor-project.png" width="26" height="26" alt="" />
                 {{apply_mentor}}
             </a>
diff --git a/utils.php b/utils.php
index 860dd0a..c521da6 100644
--- a/utils.php
+++ b/utils.php
@@ -87,6 +87,8 @@ function build_project_badges($role, $project_data) {
 
 class ProjectPermissions {
 
+    public $can_apply_student;
+    public $can_apply_mentor;
     public $can_submit;
     public $late_submission;
     public $is_owner;
@@ -94,9 +96,20 @@ class ProjectPermissions {
     public $can_edit;
     public $can_change_organization;
 
+    private function any_late_submissions($program_data) {
+        global $db;
+
+        $sql = "SELECT COUNT(*) AS count from {$db->prefix}organizations " .
+               "WHERE program_id = ? AND late_submission = 1";
+        $row = $db->query($sql, $program_data['id'], true);
+        return $row['count'] > 0;
+    }
+
     function __construct($program_data, $role, $project_data) {
         global $cache, $core, $db, $user;
 
+        $can_apply_student = false;
+        $can_apply_mentor = false;
         $can_submit = false;
         $late_submission = false;
         $is_owner = false;
@@ -115,14 +128,20 @@ class ProjectPermissions {
                 $can_submit = false;
 
                 if ($core->timestamp < $program_data['dl_mentor']) {
-                    $sql = "SELECT COUNT(*) AS count from {$db->prefix}organizations " .
-                               "WHERE program_id = ? AND late_submission = 1";
-                    $row = $db->query($sql, $program_data['id'], true);
-                    $late_submission = $row['count'] > 0;
-                    if ($late_submission)
-                        $can_submit = true;
+                    $late_submission = $this->any_late_submissions($program_data);
                 }
             }
+        } else if ($role == 'g' || $role == 'r') {
+            if ($core->timestamp <= $program_data['dl_student']) {
+                $can_apply_student = true;
+                $can_apply_mentor = true;
+            } else if ($core->timestamp <= $program_data['dl_mentor']) {
+                $can_apply_student = $this->any_late_submissions($program_data);
+                $can_apply_mentor = true;
+            } else {
+                $can_apply_student = false;
+                $can_apply_mentor = false;
+            }
         }
 
         if ($project_data !== null) {
@@ -184,6 +203,8 @@ class ProjectPermissions {
             }
         }
 
+        $this->can_apply_student = $can_apply_student;
+        $this->can_apply_mentor = $can_apply_mentor;
         $this->can_submit = $can_submit;
         $this->late_submission = $late_submission;
         $this->is_owner = $is_owner;


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