Only uses autoload to require validation classes.
[platal.git] / classes / direnum.php
index a8b9a8e..567f4de 100644 (file)
@@ -40,6 +40,9 @@ class DirEnum
     const EDUDEGREES     = 'educationdegrees';
     const EDUFIELDS      = 'educationfields';
 
+    const CORPS          = 'corps';
+    const CORPSRANKS     = 'corpsranks';
+
     const NATIONALITIES  = 'nationalities';
     const COUNTRIES      = 'countries';
     const ADMINAREAS     = 'adminareas';
@@ -48,20 +51,24 @@ class DirEnum
     const COMPANIES      = 'companies';
     const SECTORS        = 'sectors';
     const JOBDESCRIPTION = 'jobdescription';
+    const JOBTERMS       = 'jobterms';
 
     const NETWORKS       = 'networking';
 
+    const MEDALS         = 'medals';
+
     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);
             }
         }
@@ -94,8 +101,10 @@ class DirEnum
             self::init($type);
         }
         $obj = self::$enumerations[$type];
+        $args = func_get_args();
+        array_shift($args);
         if ($obj->capabilities & DirEnumeration::HAS_OPTIONS) {
-            return call_user_func(array($obj, 'getOptionsIter'));
+            return call_user_func_array(array($obj, 'getOptionsIter'), $args);
         } else {
             return PlIteratorUtils::fromArray(array());
         }
@@ -236,6 +245,9 @@ abstract class DirEnumeration
     }
     // }}}
 
+    /** Builds a list of query parts for searching @$text in @$field :
+     * field LIKE 'text%', field LIKE '% text%', field LIKE '%-text%'
+     */
     private function mkTests($field, $text)
     {
         $tests = array();
@@ -344,7 +356,7 @@ abstract class DE_WithSuboption extends DirEnumeration
         } else if (array_key_exists($subid, $this->suboptions)) {
             return $this->suboptions[$subid];
         } else {
-            return false;
+            return array();
         }
     }
 
@@ -518,6 +530,32 @@ class DE_EducationFields extends DirEnumeration
 }
 // }}}
 
+// {{{ class DE_Corps
+class DE_Corps 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.current_corpsid = profile_corps_enum.id)';
+}
+// }}}
+
+// {{{ class DE_CorpsRanks
+class DE_CorpsRanks extends DirEnumeration
+{
+    protected $idfield   = 'profile_corps_rank_enum.id';
+    protected $valfield  = 'profile_corps_rank_enum.name';
+    protected $valfield2 = 'profile_corps_rank_enum.abbrev';
+    protected $from      = 'profile_corps_rank_enum';
+
+    protected $ac_unique = 'profile_corps.pid';
+    protected $ac_join   = 'INNER JOIN profile_corps ON (profile_corps.rankid = profile_corps_rank_enum.id)';
+}
+// }}}
+
 /** GEOLOC
  */
 // {{{ class DE_Nationalities
@@ -610,20 +648,56 @@ 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
 class DE_Networking extends DirEnumeration
 {
-    protected $idfield  = 'profile_networking_enum.network_type';
+    protected $idfield  = 'profile_networking_enum.nwid';
     protected $valfield = 'profile_networking_enum.name';
     protected $from     = 'profile_networking_enum';
 
 
-    protected $ac_join   = 'INNER JOIN profile_networking ON (profile_networking.network_type = profile_networking_enum.network_type)';
+    protected $ac_join   = 'INNER JOIN profile_networking ON (profile_networking.nwid = profile_networking_enum.nwid)';
     protected $ac_unique = 'profile_networking.pid';
 }
 // }}}
 
+/** MEDALS
+ */
+// {{{ class DE_Medals
+class DE_Medals extends DirEnumeration
+{
+    protected $from = 'profile_medal_enum';
+
+    protected $ac_join = 'INNER JOIN profile_medals ON (profile_medals.mid = profile_medal_enum.id)';
+    protected $ac_unique = 'profile_medals.pid';
+}
+// }}}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>