Simplifies profile names handling.
[platal.git] / classes / direnum.php
index 8415ee3..16cdb25 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -29,9 +29,6 @@ class DirEnum
      * Each of these consts contains the basename of the class (its full name
      * being DE_$basename).
      */
-    const NAMETYPES      = 'nametypes';
-    const NAMES          = 'names';
-
     const BINETS         = 'binets';
     const GROUPESX       = 'groupesx';
     const SECTIONS       = 'sections';
@@ -40,33 +37,39 @@ class DirEnum
     const EDUDEGREES     = 'educationdegrees';
     const EDUFIELDS      = 'educationfields';
 
-    const CORPS          = 'corps';
+    const CURRENTCORPS   = 'currentcorps';
+    const ORIGINCORPS    = 'origincorps';
     const CORPSRANKS     = 'corpsranks';
 
     const NATIONALITIES  = 'nationalities';
     const COUNTRIES      = 'countries';
     const ADMINAREAS     = 'adminareas';
+    const SUBADMINAREAS  = 'subadminareas';
     const LOCALITIES     = 'localities';
 
     const COMPANIES      = 'companies';
-    const SECTORS        = 'sectors';
     const JOBDESCRIPTION = 'jobdescription';
+    const JOBTERMS       = 'jobterms';
 
     const NETWORKS       = 'networking';
 
     const MEDALS         = 'medals';
 
+    const ACCOUNTTYPES   = 'accounttypes';
+    const SKINS          = 'skins';
+
     static private $enumerations = array();
 
     static private function init($type)
     {
-        if (S::has('__DE_' . $type)) {
+        if (Platal::globals()->cacheEnabled() && S::has('__DE_' . $type)) {
             self::$enumerations[$type] = S::v('__DE_' . $type);
         } else {
             $cls = "DE_" . ucfirst($type);
             $obj = new $cls();
             self::$enumerations[$type] = $obj;
-            if ($obj->capabilities & DirEnumeration::SAVE_IN_SESSION) {
+            if (Platal::globals()->cacheEnabled()
+                 && $obj->capabilities & DirEnumeration::SAVE_IN_SESSION) {
                 S::set('__DE_' . $type, $obj);
             }
         }
@@ -427,29 +430,6 @@ abstract class DE_WithSuboption extends DirEnumeration
 }
 // }}}
 
-// {{{ class DE_NameTypes
-// returns 'system' names ('lastname', 'lastname_marital', ...)
-class DE_NameTypes extends DirEnumeration
-{
-    public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
-
-    protected $from     = 'profile_name_enum';
-    protected $valfield = 'type';
-}
-// }}}
-
-// {{{ class DE_Names
-// returns 'system' names ('lastname', 'lastname_marital', ...)
-class DE_Names extends DirEnumeration
-{
-    public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
-
-    protected $from     = 'profile_name_enum';
-    protected $idfield  = 'type';
-    protected $valfield = 'name';
-}
-// }}}
-
 /** GROUPS
  */
 // {{{ class DE_Binets
@@ -493,6 +473,7 @@ class DE_GroupesX extends DirEnumeration
 // {{{ class DE_EducationSchools
 class DE_EducationSchools extends DirEnumeration
 {
+    protected $ac_beginwith = false;
     protected $idfield   = 'profile_education_enum.id';
     protected $valfield  = 'profile_education_enum.name';
     protected $valfield2 = 'profile_education_enum.abbreviation';
@@ -528,18 +509,32 @@ class DE_EducationFields extends DirEnumeration
 }
 // }}}
 
-// {{{ class DE_Corps
-class DE_Corps extends DirEnumeration
+// {{{ class DE_CurrentCorps
+class DE_CurrentCorps extends DirEnumeration
 {
     protected $idfield   = 'profile_corps_enum.id';
     protected $valfield  = 'profile_corps_enum.name';
     protected $valfield2 = 'profile_corps_enum.abbrev';
     protected $from      = 'profile_corps_enum';
+    protected $where     = 'WHERE profile_corps_enum.still_exists = 1';
 
     protected $ac_unique = 'profile_corps.pid';
     protected $ac_join   = 'INNER JOIN profile_corps ON (profile_corps.current_corpsid = profile_corps_enum.id)';
 }
 // }}}
+//
+// {{{ class DE_OriginCorps
+class DE_OriginCorps extends DirEnumeration
+{
+    protected $idfield   = 'profile_corps_enum.id';
+    protected $valfield  = 'profile_corps_enum.name';
+    protected $valfield2 = 'profile_corps_enum.abbrev';
+    protected $from      = 'profile_corps_enum';
+
+    protected $ac_unique = 'profile_corps.pid';
+    protected $ac_join   = 'INNER JOIN profile_corps ON (profile_corps.original_corpsid = profile_corps_enum.id)';
+}
+// }}}
 
 // {{{ class DE_CorpsRanks
 class DE_CorpsRanks extends DirEnumeration
@@ -560,8 +555,8 @@ class DE_CorpsRanks extends DirEnumeration
 class DE_Nationalities extends DirEnumeration
 {
     protected $idfield   = 'geoloc_countries.iso_3166_1_a2';
-    protected $valfield  = 'geoloc_countries.nationalityFR';
-    protected $valfield2 = 'geoloc_countries.nationality';
+    protected $valfield  = 'geoloc_countries.nationality';
+    protected $valfield2 = 'geoloc_countries.nationalityEn';
     protected $from      = 'geoloc_countries';
     protected $join      = 'INNER JOIN profiles ON (geoloc_countries.iso_3166_1_a2 IN (profiles.nationality1, profiles.nationality2, profiles.nationality3))';
 
@@ -574,12 +569,13 @@ class DE_Nationalities extends DirEnumeration
 class DE_Countries extends DirEnumeration
 {
     protected $idfield   = 'geoloc_countries.iso_3166_1_a2';
-    protected $valfield  = 'geoloc_countries.countryFR';
-    protected $valfield2 = 'geoloc_countries.country';
+    protected $valfield  = 'geoloc_countries.country';
+    protected $valfield2 = 'geoloc_countries.countryEn';
     protected $from      = 'geoloc_countries';
 
     protected $ac_join   = 'INNER JOIN profile_addresses ON (geoloc_countries.iso_3166_1_a2 = profile_addresses.countryId)';
     protected $ac_unique = 'profile_addresses.pid';
+    protected $ac_where  = 'profile_addresses.type = \'home\'';
 }
 // }}}
 
@@ -596,6 +592,19 @@ class DE_AdminAreas extends DE_WithSuboption
 }
 // }}}
 
+// {{{ class DE_SubAdminAreas
+class DE_SubAdminAreas extends DE_WithSuboption
+{
+    protected $idfield   = 'geoloc_subadministrativeareas.id';
+    protected $optfield  = 'geoloc_subadministrativeareas.administrativearea';
+    protected $valfield  = 'geoloc_subadministrativeareas.name';
+    protected $from      = 'geoloc_subadministrativeareas';
+
+    protected $ac_join   = 'INNER JOIN profile_addresses ON (profile_addresses.subadministrativeAreaId = geoloc_subadministrativeareas.id)';
+    protected $ac_unique = 'profile_addresses.pid';
+}
+// }}}
+
 // {{{ class DE_Localities
 class DE_Localities extends DirEnumeration
 {
@@ -623,18 +632,6 @@ class DE_Companies extends DirEnumeration
 }
 // }}}
 
-// {{{ class DE_Sectors
-class DE_Sectors extends DirEnumeration
-{
-    protected $idfield   = 'profile_job_sector_enum.id';
-    protected $valfield  = 'profile_job_sector_enum.name';
-    protected $from      = 'profile_job_sector_enum';
-
-    protected $ac_join   = 'INNER JOIN profile_job ON (profile_job_sector_enum.id = profile_job.sectorid)';
-    protected $ac_unique = 'profile_job.pid';
-}
-// }}}
-
 // {{{ class DE_JobDescription
 class DE_JobDescription extends DirEnumeration
 {
@@ -646,6 +643,30 @@ class DE_JobDescription extends DirEnumeration
 }
 // }}}
 
+// {{{ class DE_JobTerms
+class DE_JobTerms extends DirEnumeration
+{
+    // {{{ function getAutoComplete
+    public function getAutoComplete($text)
+    {
+        $tokens = JobTerms::tokenize($text.'%');
+        if (count($tokens) == 0) {
+            return PlIteratorUtils::fromArray(array());
+        }
+        $token_join = JobTerms::token_join_query($tokens, 'e');
+        return XDB::iterator('SELECT  e.jtid AS id, e.full_name AS field, COUNT(DISTINCT p.pid) AS nb
+                                 FROM  profile_job_term_enum AS e
+                           INNER JOIN  profile_job_term_relation AS r ON (r.jtid_1 = e.jtid)
+                           INNER JOIN  profile_job_term AS p ON (r.jtid_2 = p.jtid)
+                           '.$token_join.'
+                             GROUP BY  e.jtid
+                             ORDER BY  nb DESC, field
+                                LIMIT ' . self::AUTOCOMPLETE_LIMIT);
+    }
+    // }}}
+}
+// }}}
+
 /** NETWORKING
  */
 // {{{ class DE_Networking
@@ -673,5 +694,29 @@ class DE_Medals extends DirEnumeration
 }
 // }}}
 
+/** ACCOUNTS
+ */
+// {{{ class DE_AccountTypes
+class DE_AccountTypes extends DirEnumeration
+{
+    public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
+
+    protected $from     = 'account_types';
+    protected $valfield = 'perms';
+    protected $idfield  = 'type';
+}
+// }}}
+
+// {{{ class DE_Skins
+class DE_Skins extends DirEnumeration
+{
+    public $capabilities = 0x005; // self::HAS_OPTIONS | self::SAVE_IN_SESSION;
+
+    protected $from      = 'skins';
+    protected $valfield  = 'name';
+    protected $idfield   = 'skin_tpl';
+}
+// }}}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>