Adds jobs to vcards (Closes #1324, #1352).
authorStéphane Jacob <sj@m4x.org>
Tue, 1 Mar 2011 09:57:53 +0000 (10:57 +0100)
committerStéphane Jacob <sj@m4x.org>
Tue, 1 Mar 2011 09:57:53 +0000 (10:57 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
include/vcard.inc.php
modules/carnet.php
modules/profile.php
modules/xnetgrp.php

index f48b63c..16f815d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -25,6 +25,7 @@ Bug/Wish:
 
     * Profile:
         - #1270: Adapts default picture to main education                  -JAC
+        - #1324,1352: Adds jobs to vcards                                  -JAC
         - #1340: Allows secretaries and admin to fully edit profiles' name -JAC
         - #1354: Do not notify death to a deceased user                    -JAC
         - #1356: Indicates delivery issues on addresses                    -JAC
index 22ab927..ddaa420 100644 (file)
@@ -35,7 +35,7 @@ class VCard extends PlVCard
 
     public function addProfile($profile)
     {
-        $profile = Profile::get($profile);
+        $profile = Profile::get($profile, Profile::FETCH_ALL);
         if ($profile) {
             $this->profile_list[] = $profile;
             $this->count++;
@@ -105,23 +105,39 @@ class VCard extends PlVCard
         }
 
         // Pro
-        $adrs = $pf->iterAddresses(Profile::ADDRESS_PRO);
-        while ($adr = $adrs->next()) {
-            if (!$adr->postalCode || !$adr->locality || !$adr->country) {
-                $group = $entry->addWork(null, null, null, null,
-                                         $adr->text, null, null, null,
-                                         null, $adr->administrativeArea, null);
+        $jobs = $pf->getJobs();
+        foreach ($jobs as $job) {
+            $terms_array = array();
+            foreach ($job->terms as $term) {
+               $terms_array[] = $term->full_name;
+            }
+            $terms = implode(', ', $terms_array);
+            if ($job->address) {
+                if (!$job->address->postalCode || !$job->address->locality || !$job->address->country) {
+                    $group = $entry->addWork($job->company->name, null, $job->description, $terms,
+                                             $job->address->text, null, null, null,
+                                             null, $job->address->administrativeArea, null);
+                } else {
+                    $group = $entry->addWork($job->company->name, null, $job->description, $terms,
+                                             trim(Geocoder::getFirstLines($job->address->text, $job->address->postalCode, 4)),
+                                             null, null, $job->address->postalCode,
+                                             $job->address->locality, $job->address->administrativeArea, $job->address->country);
+                }
             } else {
-                // TODO : link address to company
-                $group = $entry->addWork(null, null, null, null,
-                                         trim(Geocoder::getFirstLines($adr->text, $adr->postalCode, 4)), null, null, $adr->postalCode,
-                                         $adr->locality, $adr->administrativeArea, $adr->country);
+                $group = $entry->addWork($job->company->name, null, $job->description, $terms,
+                                         null, null, null, null,
+                                         null, null, null);
             }
-            foreach ($adr->phones() as $phone) {
-                if ($phone->link_type == Phone::TYPE_FIXED) {
-                    $entry->addTel($group, $phone->display);
-                } else if ($phone->link_type == Phone::TYPE_FAX) {
+            if ($job->user_email) {
+                $entry->addMail($group, $job->user_email);
+            }
+            foreach ($job->phones as $phone) {
+                if ($phone->type == Phone::TYPE_MOBILE) {
+                    $entry->addTel($group, $phone->display, false, true, true, false, true);
+                } else if ($phone->type == Phone::TYPE_FAX) {
                     $entry->addTel($group, $phone->display, true);
+                } else {
+                    $entry->addTel($group, $phone->display, false, true, true);
                 }
             }
         }
index 4f80b49..06b3a2e 100644 (file)
@@ -419,7 +419,7 @@ class CarnetModule extends PLModule
     {
         $pf = new ProfileFilter(new UFC_Contact(S::user()));
         $vcard = new VCard($photos == 'photos');
-        $vcard->addProfiles($pf->getProfiles());
+        $vcard->addProfiles($pf->getProfiles(null, Profile::FETCH_ALL));
         $vcard->show();
     }
 
index d76b821..e93a86f 100644 (file)
@@ -667,7 +667,7 @@ class ProfileModule extends PLModule
         }
 
         $vcard = new VCard();
-        $vcard->addProfile(Profile::get($x));
+        $vcard->addProfile(Profile::get($x, Profile::FETCH_ALL));
         $vcard->show();
     }
 
index b38b9e4..05319f0 100644 (file)
@@ -384,7 +384,7 @@ class XnetGrpModule extends PLModule
     {
         global $globals;
         $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom'));
-        $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles());
+        $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null, Profile::FETCH_ALL));
         $vcard->show();
     }