Enables survey for oranges. Closes #993
authorPascal Corpet <pascal.corpet@m4x.org>
Sun, 6 Jun 2010 12:50:20 +0000 (14:50 +0200)
committerPascal Corpet <pascal.corpet@m4x.org>
Sun, 6 Jun 2010 12:50:20 +0000 (14:50 +0200)
ChangeLog
classes/profile.php
modules/survey.php

index 485b94e..e88c01b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,6 +32,7 @@ Bug/Wish:
         - #1081: Sorts language alphabetically in skill tab                -Car
 
     * Survey:
+        - #993: Enables survey for oranges                                 -Car
         - #1002: Lets the user set promo interval in both ways             -Car
 
     * XnetLists:
index 4b0f30f..663f2f7 100644 (file)
@@ -195,6 +195,25 @@ class Profile
         return intval(substr($this->promo, 1, 4));
     }
 
+    /** Check if user is an orange (associated with several promos)
+     */
+    public function isMultiPromo()
+    {
+        return $this->grad_year != $this->entry_year + $this->mainEducationDuration();
+    }
+
+    /** Returns an array with all associated promo years.
+     */
+    public function yearspromo()
+    {
+        $promos = array();
+        $d = -$this->deltaPromoToGradYear();
+        for ($g = $this->entry_year + $this->mainEducationDuration(); $g <= $this->grad_year; ++$g) {
+            $promos[] = $g + $d;
+        }
+        return $promos;
+    }
+
     public function mainEducation()
     {
         if (empty($this->promo)) {
@@ -232,6 +251,18 @@ class Profile
         }
     }
 
+    /** Number of years between the promotion year until the
+     * graduation year. In standard schools it's 0, but for
+     * Polytechnique the promo year is the entry year.
+     */
+    public function deltaPromoToGradYear()
+    {
+        if ($this->mainEducation() == 'X') {
+            return $this->mainEducationDuration();
+        }
+        return 0;
+    }
+
     /** Print a name with the given formatting:
      * %s = • for women
      * %f = firstname
index 94b39b9..f74f222 100644 (file)
@@ -403,7 +403,20 @@ class SurveyModule extends PLModule
             if (!S::logged()) {
                 return false;
             }
-            if (!$survey->checkPromo(S::v('promo'))) { // checks promotion
+            $profile = S::user()->profile();
+            if (!$profile) {
+                return false;
+            }
+            // checks promotion
+            $allowed = false;
+            foreach ($profile->yearspromo() as $p) {
+                var_dump($p);
+                if ($survey->checkPromo($p)) {
+                    $allowed = true;
+                    break;
+                }
+            }
+            if (!$allowed) {
                 $page->kill("Tu n'as pas accès à ce sondage car il est réservé à d'autres promotions.");
             }
         }