Merge remote branch 'origin/platal-1.0.1'
[platal.git] / include / profilefields.inc.php
index e841c16..559686d 100644 (file)
@@ -226,7 +226,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;
         }
     }
@@ -539,8 +539,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 +641,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);
             }
         }
     }