Fix ProfileEducation fetching and display
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Fri, 19 Mar 2010 17:23:32 +0000 (18:23 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 12:49:29 +0000 (13:49 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
include/education.func.inc.php
include/profilefields.inc.php

index 3e036a9..4da4acd 100644 (file)
@@ -164,8 +164,8 @@ function _education_fmt($params, &$smarty)
     } else {
         $sex = $params->b('sex');
     }
-    return education_fmt($edu['school_short'], $edu['school_url'], $edu['degree_short'], $edu['grad_year'],
-                         $edu['field'], $edu['program'], $sex, $params->b('long'));
+    return education_fmt($edu->school_short, $edu->school_url, $edu->degree_short, $edu->grad_year,
+                         $edu->field, $edu->program, $sex, $params->b('long'));
 }
 Platal::page()->register_function('education_fmt', '_education_fmt');
 
index 5b53a0e..8293d21 100644 (file)
@@ -282,25 +282,29 @@ class Address
 // {{{ class Education
 class Education
 {
-    public $eduid;
-    public $degreeid;
-    public $fieldid;
+    public $id;
+    public $pid;
 
     public $entry_year;
     public $grad_year;
     public $program;
     public $flags;
 
+    public $school;
+    public $school_short;
+    public $school_url;
+    public $country;
+
+    public $degree;
+    public $degree_short;
+    public $degree_level;
+
     public function __construct(array $data)
     {
-        $this->eduid    = $data['eduid'];
-        $this->degreeid = $data['degreeid'];
-        $this->fieldid  = $data['fieldid'];
-
-        $this->entry_year = $data['entry_year'];
-        $this->grad_year  = $data['grad_year'];
-        $this->program    = $data['program'];
-        $this->flags      = new PlFlagSet($data['flags']);
+        foreach ($data as $key => $val) {
+            $this->$key = $val;
+        }
+        $this->flags      = new PlFlagSet($this->flags);
     }
 }
 // }}}
@@ -310,7 +314,7 @@ class ProfileEducation extends ProfileField
 {
     private $educations = array();
 
-    public function __construct(PlIterator $it)
+    public function __construct(PlInnerSubIterator $it)
     {
         $this->pid = $it->value();
         $this->visibility = Profile::VISIBILITY_PUBLIC;
@@ -342,17 +346,25 @@ class ProfileEducation extends ProfileField
                 break;
             }
         }
-        return PlIteratorUtils::fromArray($educations);
+        return PlIteratorUtils::fromArray($educations, 1, true);
     }
 
     public static function fetchData(array $pids, $visibility)
     {
-        $data = XDB::iterator('SELECT  id, pid, eduid, degreeid, fieldid,
-                                       entry_year, grad_year, program, flags
-                                 FROM  profile_education
-                                WHERE  pid IN {?}
+        $data = XDB::iterator('SELECT  pe.id, pe.pid,
+                                       pe.entry_year, pe.grad_year, pe.program, pe.flags,
+                                       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
+                                 FROM  profile_education AS pe
+                            LEFT JOIN  profile_education_enum AS pee ON (pee.id = pe.eduid)
+                            LEFT JOIN  geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pee.country)
+                            LEFT JOIN  profile_education_degree_enum AS pede ON (pede.id = pe.degreeid)
+                            LEFT JOIN  profile_education_field_enum AS pefe ON (pefe.id = pe.fieldid)
+                                WHERE  pe.pid IN {?}
                              ORDER BY  ' . XDB::formatCustomOrder('pid', $pids) . ',
-                                       NOT FIND_IN_SET(\'primary\', flags), entry_year, id',
+                                       NOT FIND_IN_SET(\'primary\', pe.flags), pe.entry_year, pe.id',
                                 $pids);
 
         return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));