Implements the first API handler (/api/1/user/<user>/isRegistered). It
[platal.git] / include / profilefields.inc.php
index e841c16..b39b8f9 100644 (file)
@@ -202,8 +202,12 @@ class Job
         }
         $this->company = CompanyList::get($this->jobid);
         if (is_null($this->company)) {
-            $entreprise = ProfileValidate::get_typed_requests($this->pid, 'entreprise');
-            $this->company = new Company(array('name' =>  $entreprise[$this->id]->name));
+            $entreprises = ProfileValidate::get_typed_requests($this->pid, 'entreprise');
+            foreach ($entreprises as $entreprise) {
+                if ($entreprise->id == $this->id) {
+                    $this->company = new Company(array('name' => $entreprise->name));
+                }
+            }
         }
     }
 
@@ -226,7 +230,7 @@ class Job
 
     public function setAddress(Address $address)
     {
-        if ($address->type == Address::LINK_JOB && $address->jobid == $this->id && $address->pid == $this->pid) {
+        if ($address->type == Address::LINK_JOB && $address->id == $this->id && $address->pid == $this->pid) {
             $this->address = $address;
         }
     }
@@ -334,7 +338,7 @@ class ProfileEducation extends ProfileField
         $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,
+                                       pee.url AS school_url, gc.country,
                                        pede.degree, pede.abbreviation AS degree_short, pede.level AS degree_level,
                                        pefe.field
                                  FROM  profile_education AS pe
@@ -485,7 +489,7 @@ class ProfileMentoringCountries extends ProfileField
 
     public static function fetchData(array $pids, ProfileVisibility $visibility)
     {
-        $data = XDB::iterator('SELECT  pmc.pid, pmc.country AS id, gc.countryFR AS name
+        $data = XDB::iterator('SELECT  pmc.pid, pmc.country AS id, gc.country 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 {?}
@@ -539,8 +543,13 @@ class ProfileAddresses extends ProfileField
     {
         $p = $phones->get(Profile::PHONE_LINK_ADDRESS | Profile::PHONE_TYPE_ANY);
         foreach ($p as $phone) {
-            if ($phone->linkType() == Phone::LINK_ADDRESS && array_key_exists($phone->linkId(), $this->addresses)) {
-                $this->addresses[$phone->linkId()]->addPhone($phone);
+            /* We must iterate on the addresses because id is not uniq thus,
+             * $this->addresse[$phone->linkId()] is invalid.
+             */
+            foreach ($this->addresses as $address) {
+                if ($address->type == Address::LINK_PROFILE && $address->id == $phone->linkId()) {
+                    $address->addPhone($phone);
+                }
             }
         }
     }
@@ -636,7 +645,7 @@ class ProfileJobs extends ProfileField
         $a = $addresses->get(Profile::ADDRESS_PRO);
         foreach ($a as $address) {
             if ($address->type == Address::LINK_JOB && array_key_exists($address->jobid, $this->jobs)) {
-                $this->jobs[$address->jobid]->setAddress($address);
+                $this->jobs[$address->id]->setAddress($address);
             }
         }
     }
@@ -761,7 +770,10 @@ class CompanyList
         if (!array_key_exists($id, self::$companies)) {
             self::preload();
         }
-        return self::$companies[$id];
+        if (isset(self::$companies[$id])) {
+            return self::$companies[$id];
+        }
+        return null;
     }
 }