Fix inverted test.
[platal.git] / classes / profile.php
index 7828ceb..b856508 100644 (file)
@@ -35,14 +35,15 @@ class Profile
     const ADDRESS_POSTAL     = 0x000008;
 
     const EDUCATION_MAIN     = 0x000010;
-    const EDUCATION_ALL      = 0x000020;
-    const EDUCATION_FINISHED = 0x000040;
-    const EDUCATION_CURRENT  = 0x000080;
+    const EDUCATION_EXTRA    = 0x000020;
+    const EDUCATION_ALL      = 0x000040;
+    const EDUCATION_FINISHED = 0x000080;
+    const EDUCATION_CURRENT  = 0x000100;
 
-    const JOBS_MAIN          = 0x000100;
-    const JOBS_ALL           = 0x000200;
-    const JOBS_FINISHED      = 0x000400;
-    const JOBS_CURRENT       = 0x000800;
+    const JOBS_MAIN          = 0x001000;
+    const JOBS_ALL           = 0x002000;
+    const JOBS_FINISHED      = 0x004000;
+    const JOBS_CURRENT       = 0x008000;
 
     private $pid;
     private $hrpid;
@@ -154,7 +155,10 @@ class Profile
         $this->visibility = self::$v_values[$visibility];
     }
 
-    public function getAddresses($flags)
+
+    /* Addresses
+     */
+    public function getAddresses($flags, $limit = null)
     {
         $where = XDB::format('pa.pid = {?}', $this->id());
         if ($flags & self::ADDRESS_MAIN) {
@@ -176,6 +180,7 @@ class Profile
         if (count($type) > 0) {
             $where .= ' AND pa.type IN ' . XDB::formatArray($type);
         }
+        $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
         return XDB::iterator('SELECT  pa.text, pa.postalCode, pa.type, pa.latitude, pa.longitude,
                                       gl.name AS locality, gas.name AS subAdministrativeArea,
                                       ga.name AS administrativeArea, gc.countryFR AS country,
@@ -188,7 +193,9 @@ class Profile
                            LEFT JOIN  geoloc_administrativeareas AS ga ON (ga.id = pa.administrativeAreaId)
                            LEFT JOIN  geoloc_administrativeareas AS gas ON (gas.id = pa.subAdministrativeAreaId)
                            LEFT JOIN  geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pa.countryId)
-                               WHERE  ' . $where);
+                               WHERE  ' . $where . '
+                            ORDER BY  pa.id
+                                      ' . $limit);
     }
 
     public function getMainAddress()
@@ -201,6 +208,42 @@ class Profile
         }
     }
 
+
+    /* Educations
+     */
+    public function getEducations($flags, $limit = null)
+    {
+        $where = XDB::format('pe.uid = {?}', $this->id());
+        if ($flags & self::EDUCATION_MAIN) {
+            $where .= ' AND FIND_IN_SET(\'primary\', pe.flags)';
+        } else if ($flags & self::EDUCATION_EXTRA) {
+            $where .= ' AND NOT FIND_IN_SET(\'primary\', pe.flags)';
+        } else if ($flags & self::EDUCATION_FINISHED) {
+            $where .= ' AND pe.grad_year <= YEAR(CURDATE())';
+        } else if ($flags & self::EDUCATION_CURRENT) {
+            $where .= ' AND pe.grad_year > YEAR(CURDATE())';
+        }
+        $limit = is_null($limit) ? '' : XDB::format('LIMIT {?}', (int)$limit);
+        return XDB::iterator('SELECT  pe.entry_year, pe.grad_year, pe.program,
+                                      pee.name AS school, pee.abbreviation AS school_short, pee.url AS school_url, gc.countryFR AS country,
+                                      pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level, pefe.field,
+                                      FIND_IN_SET(\'primary\', pe.flags) AS prim
+                                FROM  profile_education AS pe
+                          INNER JOIN  profile_education_enum AS pee ON (pe.eduid = pee.id)
+                           LEFT JOIN  geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
+                          INNER JOIN  profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
+                           LEFT JOIN  profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
+                               WHERE  ' . $where . '
+                            ORDER BY  NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id
+                                      ' . $limit);
+    }
+
+    public function getExtraEducations($limit = null)
+    {
+        return $this->getEducations(self::EDUCATION_EXTRA, $limit);
+    }
+
+
     public function owner()
     {
         return User::getSilent($this);