Add ProfileMentoringSectors / ProfileMentoringCountries
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 21:36:52 +0000 (22:36 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 21:44:34 +0000 (22:44 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php
include/profilefields.inc.php

index 7cac571..da54907 100644 (file)
@@ -133,17 +133,19 @@ class Profile
     const NETWORKING_IM      = 0x020000;
     const NETWORKING_SOCIAL  = 0x040000;
 
-    const FETCH_ADDRESSES    = 0x000001;
-    const FETCH_CORPS        = 0x000002;
-    const FETCH_EDU          = 0x000004;
-    const FETCH_JOBS         = 0x000008;
-    const FETCH_MEDALS       = 0x000010;
-    const FETCH_NETWORKING   = 0x000020;
-    const FETCH_PHONES       = 0x000040;
+    const FETCH_ADDRESSES      = 0x000001;
+    const FETCH_CORPS          = 0x000002;
+    const FETCH_EDU            = 0x000004;
+    const FETCH_JOBS           = 0x000008;
+    const FETCH_MEDALS         = 0x000010;
+    const FETCH_NETWORKING     = 0x000020;
+    const FETCH_MENTOR_SECTOR  = 0x000040;
+    const FETCH_MENTOR_COUNTRY = 0x000080;
+    const FETCH_PHONES         = 0x000100;
 
-    const FETCH_MINIFICHES   = 0x00006D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES
+    const FETCH_MINIFICHES   = 0x00012D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_NETWORKING | FETCH_PHONES
 
-    const FETCH_ALL          = 0x0000FF; // OR of FETCH_*
+    const FETCH_ALL          = 0x0001FF; // OR of FETCH_*
 
     private $fetched_fields  = 0x000000;
 
@@ -551,6 +553,46 @@ class Profile
         return array_pop($job);
     }
 
+    /* Mentoring
+     */
+    private $mentor_sectors = null;
+    public function setMentoringSectors(ProfileMentoringSectors $sectors)
+    {
+        $this->mentor_sectors = $sectors;
+    }
+
+    public function getMentoringSectors()
+    {
+        if ($this->mentor_sectors == null && !$this->fetched(self::FETCH_MENTOR_SECTOR)) {
+            $this->setMentoringSectors($this->getProfileField(self::FETCH_MENTOR_SECTOR));
+        }
+
+        if ($this->mentor_sectors == null) {
+            return array();
+        } else {
+            return $this->mentor_sectors->sectors;
+        }
+    }
+
+    private $mentor_countries = null;
+    public function setMentoringCountries(ProfileMentoringCountries $countries)
+    {
+        $this->mentor_countries = $countries;
+    }
+
+    public function getMentoringCountries()
+    {
+        if ($this->mentor_countries == null && !$this->fetched(self::FETCH_MENTOR_COUNTRY)) {
+            $this->setMentoringCountries($this->getProfileField(self::FETCH_MENTOR_COUNTRY));
+        }
+
+        if ($this->mentor_countries == null) {
+            return array();
+        } else {
+            return $this->mentor_countries->countries;
+        }
+    }
+
     /* Binets
      */
     public function getBinets()
index 79a3b88..9af88ff 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
@@ -509,6 +511,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