Moves getXorgId and getSchoolId to Profile.
authorStéphane Jacob <sj@m4x.org>
Sat, 20 Feb 2010 00:48:49 +0000 (01:48 +0100)
committerStéphane Jacob <sj@m4x.org>
Sat, 20 Feb 2010 20:17:05 +0000 (21:17 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/profile.php
include/user.func.inc.php
include/vcard.inc.php
modules/admin.php
modules/lists.php
modules/marketing.php
modules/profile.php
modules/xnetgrp.php

index ad80d8a..f1dc23d 100644 (file)
@@ -607,8 +607,50 @@ class Profile
                 $first = 0;
             }
         }
+    }
+
+    /** The school identifier consists of 6 digits. The first 3 represent the
+     * promotion entry year. The last 3 indicate the student's rank.
+     * 
+     * Our identifier consists of 8 digits and both half have the same role.
+     * This enables us to deal with bigger promotions and with a wider range
+     * of promotions.
+     *
+     * getSchoolId returns a school identifier given one of ours.
+     * getXorgId returns a X.org identifier given a school identifier.
+     */
+    public static function getSchoolId($xorgId)
+    {
+        if (!preg_match('/^[0-9]{8}$/', $xorgId)) {
+            return null;
+        }
+
+        $year = intval(substr($xorgId, 0, 4));
+        $rank = intval(substr($xorgId, 5, 3));
+        if ($year < 1996) {
+            return null;
+        } elseif ($year < 2000) {
+            $year = intval(substr(1900 - $year, 1, 3));
+            return sprintf('%02u0%03u', $year, $rank);
+        } else {
+            $year = intval(substr(1900 - $year, 1, 3));
+            return sprintf('%03u%03u', $year, $rank);
+        }
+    }
 
+    public static function getXorgId($schoolId)
+    {
+        $year = intval(substr($schoolId, 0, 3));
+        $rank = intval(substr($schoolId, 3, 3));
 
+        if ($year > 200) {
+            $year /= 10;
+        }
+        if ($year < 96) {
+            return null;
+        } else {
+            return sprintf('%04u%04u', 1900 + $year, $rank);
+        }
     }
 }
 
index ef0e133..33869a6 100644 (file)
@@ -84,28 +84,6 @@ function user_clear_all_subs($user_id, $really_del=true)
 }
 
 // }}}
-// {{{ function get_X_mat
-function get_X_mat($ourmat)
-{
-    if (!preg_match('/^[0-9]{8}$/', $ourmat)) {
-        // le matricule de notre base doit comporter 8 chiffres
-        return 0;
-    }
-
-    $year = intval(substr($ourmat, 0, 4));
-    $rang = intval(substr($ourmat, 5, 3));
-    if ($year < 1996) {
-        return;
-    } elseif ($year < 2000) {
-        $year = intval(substr(1900 - $year, 1, 3));
-        return sprintf('%02u0%03u', $year, $rang);
-    } else {
-        $year = intval(substr(1900 - $year, 1, 3));
-        return sprintf('%03u%03u', $year, $rang);
-    }
-}
-
-// }}}
 
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index ecf6d2a..9026171 100644 (file)
@@ -19,8 +19,6 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require_once('user.func.inc.php');
-
 class VCard extends PlVCard
 {
     private $profile_list = array();
index f5ec942..b364b3b 100644 (file)
@@ -653,18 +653,6 @@ class AdminModule extends PLModule
         return null;
     }
 
-    private static function getMatricule($mat)
-    {
-        $year = intval(substr($mat, 0, 3));
-        $rang = intval(substr($mat, 3, 3));
-        if ($year > 200) { $year /= 10; };
-        if ($year < 96) {
-            return null;
-        } else {
-            return sprintf('%04u%04u', 1900+$year, $rang);
-        }
-    }
-
     private static function formatNewUser($infosLine, $separator, $promo, $size)
     {
         $infos = explode($separator, $infosLine);
@@ -753,7 +741,7 @@ class AdminModule extends PLModule
                         && ($sex = self::formatSex($page, $infos[3], $line))) {
                         $name = $infos[1] . ' ' . $infos[0];
                         $birthDate = self::formatBirthDate($infos[2]);
-                        $xorgId = self::getMatricule($infos[4]);
+                        $xorgId = Profile::getXorgId($infos[4]);
 
                         XDB::execute('INSERT INTO  profiles (hrpid, xorg_id, ax_id, birthdate_ref, sex)
                                            VALUES  ({?}, {?}, {?}, {?})',
index 3313bea..cce4dd2 100644 (file)
@@ -579,9 +579,9 @@ class ListsModule extends PLModule
 
     static public function no_login_callback($login)
     {
-        require_once 'user.func.inc.php';
         global $list_unregistered, $globals;
 
+        /* TODO: fixes this call to a removed function. */
         $users = get_not_registered_user($login, true);
         if ($users && $users->total()) {
             if (!isset($list_unregistered)) {
index eecab75..fc4a95f 100644 (file)
@@ -64,8 +64,7 @@ class MarketingModule extends PLModule
         }
         $matricule = $user->profile()->xorg_id;
 
-        require_once('user.func.inc.php');
-        $matricule_X = get_X_mat($matricule);
+        $matricule_X = Profile::getSchoolId($matricule);
 
         $page->assign('full_name', $user->fullName());
         $page->assign('promo', $user->promo());
index 62e44d8..da3b414 100644 (file)
@@ -228,7 +228,6 @@ class ProfileModule extends PLModule
         // Now that we know this is the profile of an existing user, we can
         // switch to the appropriate template.
         $page->changeTpl('profile/profile.tpl', SIMPLE);
-        require_once 'user.func.inc.php';
 
         // Determines the access level at which the profile will be displayed.
         if (!S::logged() || Env::v('view') == 'public') {
@@ -586,7 +585,6 @@ class ProfileModule extends PLModule
 
     function handler_referent(&$page, $user)
     {
-        require_once 'user.func.inc.php';
         $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
 
         $user = Profile::get($user);
index c669cb4..de108fc 100644 (file)
@@ -794,7 +794,6 @@ class XnetGrpModule extends PLModule
 
     private function changeLogin(PlPage &$page, PlUser &$user, MMList &$mmlist, $login)
     {
-        require_once 'user.func.inc.php';
         // Search the uid of the user...
         $res = XDB::query("SELECT  f.id, f.alias
                              FROM  aliases AS a
@@ -802,6 +801,7 @@ class XnetGrpModule extends PLModule
                             WHERE  a.alias = {?}",
                           $login);
         if ($res->numRows() == 0) {
+            // TODO: replace this call to a removed function.
             $x = get_not_registered_user($login);
             if (!$x) {
                 $page->trigError("Le login $login ne correspond à aucun X.");