Fixes medal grades (table was missing).
[platal.git] / include / profilefields.inc.php
index 79a3b88..4f83389 100644 (file)
 abstract class ProfileField
 {
     public static $fields = array(
-        Profile::FETCH_ADDRESSES  => 'ProfileAddresses',
-        Profile::FETCH_CORPS      => 'ProfileCorps',
-        Profile::FETCH_EDU        => 'ProfileEducation',
-        Profile::FETCH_JOBS       => 'ProfileJobs',
-        Profile::FETCH_MEDALS     => 'ProfileMedals',
-        Profile::FETCH_NETWORKING => 'ProfileNetworking',
-        Profile::FETCH_PHONES     => 'ProfilePhones',
+        Profile::FETCH_ADDRESSES      => 'ProfileAddresses',
+        Profile::FETCH_CORPS          => 'ProfileCorps',
+        Profile::FETCH_EDU            => 'ProfileEducation',
+        Profile::FETCH_JOBS           => 'ProfileJobs',
+        Profile::FETCH_MEDALS         => 'ProfileMedals',
+        Profile::FETCH_NETWORKING     => 'ProfileNetworking',
+        Profile::FETCH_PHONES         => 'ProfilePhones',
+        Profile::FETCH_MENTOR_SECTOR  => 'ProfileMentoringSectors',
+        Profile::FETCH_MENTOR_COUNTRY => 'ProfileMentoringCountries',
     );
 
     /** The profile to which this field belongs
@@ -293,6 +295,9 @@ class Address
 
     public function hasFlag($flag)
     {
+        if (!$this->flags instanceof PlFlagSet) {
+            $this->flags = new PlFlagSet($this->flags);
+        }
         return $this->flags->hasFlag($flag);
     }
 }
@@ -407,10 +412,11 @@ class ProfileMedals extends ProfileField
 
     public static function fetchData(array $pids, ProfileVisibility $visibility)
     {
-        $data = XDB::iterator('SELECT  pm.pid, pm.mid, pm.gid, pme.text, pme.img
+        $data = XDB::iterator('SELECT  pm.pid, pm.mid, pm.gid, pme.text, pme.img, pmge.text AS grade
                                  FROM  profile_medals AS pm
                             LEFT JOIN  profiles AS p ON (pm.pid = p.pid)
                             LEFT JOIN  profile_medal_enum AS pme ON (pme.id = pm.mid)
+                            LEFT JOIN  profile_medal_grade_enum AS pmge ON (pmge.mid = pm.mid AND pmge.gid = pm.gid)
                                 WHERE  pm.pid IN {?} AND p.medals_pub IN {?}
                              ORDER BY  ' . XDB::formatCustomOrder('pm.pid', $pids),
                                 $pids, $visibility->levels());
@@ -450,9 +456,9 @@ class ProfileNetworking extends ProfileField
         foreach ($this->networks as $id => $nw) {
             // XXX hardcoded reference to web site index
             if (
-                (($flags & self::NETWORKING_WEB) && $nw['network_type'] == 0)
+                (($flags & Profile::NETWORKING_WEB) && $nw['network_type'] == 0)
                 ||
-                (! ($flags & self::NETWORKING_WEB))
+                (! ($flags & Profile::NETWORKING_WEB))
             ) {
                 $nws[$id] = $nw;
                 ++$nb;
@@ -509,6 +515,59 @@ class ProfileCorps extends ProfileField
     }
 }
 // }}}
+// {{{ class ProfileMentoringSectors                  [ Field ]
+class ProfileMentoringSectors extends ProfileField
+{
+    public $sectors = array();
+
+    public function __construct(PlInnerSubIterator $it)
+    {
+        $this->pid = $it->value();
+        while ($sector = $it->next()) {
+            $this->sectors[] = $sector;
+        }
+    }
+
+    public static function fetchData(array $pids, ProfileVisibility $visibility)
+    {
+        $data = XDB::iterator('SELECT  pms.pid, pjse.name AS sector, pjsse.name AS subsector
+                                 FROM  profile_mentor_sector AS pms
+                            LEFT JOIN  profile_job_sector_enum AS pjse ON (pjse.id = pms.sectorid)
+                            LEFT JOIN  profile_job_subsector_enum AS pjsse ON (pjsse.id = pms.subsectorid)
+                                WHERE  pms.pid IN {?}
+                             ORDER BY  ' . XDB::formatCustomOrder('pms.pid', $pids),
+                                $pids);
+
+        return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));
+    }
+}
+// }}}
+// {{{ class ProfileMentoringCountries                [ Field ]
+class ProfileMentoringCountries extends ProfileField
+{
+    public $countries = array();
+
+    public function __construct(PlInnerSubIterator $it)
+    {
+        $this->pid = $it->value();
+        while ($country = $it->next()) {
+            $this->countries[$country['id']] = $country['name'];
+        }
+    }
+
+    public static function fetchData(array $pids, ProfileVisibility $visibility)
+    {
+        $data = XDB::iterator('SELECT  pmc.pid, pmc.country AS id, gc.countryFR AS name
+                                 FROM  profile_mentor_country AS pmc
+                            LEFT JOIN  geoloc_countries AS gc ON (gc.iso_3166_1_a2 = pmc.country)
+                                WHERE  pmc.pid IN {?}
+                             ORDER BY  ' . XDB::formatCustomOrder('pmc.pid', $pids),
+                                $pids);
+
+        return PlIteratorUtils::subIterator($data, PlIteratorUtils::arrayValueCallback('pid'));
+    }
+}
+// }}}
 
 /** Loading of data for a Profile :
  * 1) load jobs, addresses, phones
@@ -617,7 +676,7 @@ class ProfilePhones extends ProfileField
 
     public static function fetchData(array $pids, ProfileVisibility $visibility)
     {
-        $data = XDB::iterator('SELECT  tel_type AS type, search_tel AS search, display_tel AS display, link_type, comment
+        $data = XDB::iterator('SELECT  tel_type AS type, search_tel AS search, display_tel AS display, link_type, comment, pid
                                  FROM  profile_phones
                                 WHERE  pid IN {?} AND pub IN {?}
                              ORDER BY  ' . XDB::formatCustomOrder('pid', $pids),
@@ -681,7 +740,7 @@ class ProfileJobs extends ProfileField
         }
     }
 
-    public static function addAddresses(ProfileAddresses $addresses)
+    public function addAddresses(ProfileAddresses $addresses)
     {
         $a = $addresses->get(Profile::ADDRESS_PRO);
         foreach ($a as $address) {
@@ -691,11 +750,10 @@ class ProfileJobs extends ProfileField
         }
     }
 
-    public static function addCompanies(array $companies)
+    public function addCompanies(array $companies)
     {
-        foreach ($this->jobs as $job)
-        {
-            $job->company = $companies[$job->jobid];
+        foreach ($this->jobs as $job) {
+            $this->company = $companies[$job->jobid];
         }
     }
 }