2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class VCard
extends PlVCard
24 private $profile_list = array();
26 private $freetext = null
;
27 private $photos = true
;
29 public function __construct($photos = true
, $freetext = null
)
31 PlVCard
::$folding = false
;
32 $this->freetext
= $freetext;
33 $this->photos
= $photos;
36 public function addProfile($profile)
38 $profile = Profile
::get($profile);
40 $this->profile_list
[] = $profile;
45 public function addProfiles(array $profiles) {
46 foreach ($profiles as $profile) {
47 $this->addProfile($profile);
51 protected function fetch()
53 return PlIteratorUtils
::fromArray($this->profile_list
);
56 protected function buildEntry($pf)
61 $entry = new PlVCardEntry($pf->firstNames(), $pf->lastNames(), null
, null
, $pf->nickname
);
66 $freetext = '(' . $pf->promo
. ')';
67 if ($this->freetext
) {
68 $freetext .= "\n" . $this->freetext
;
70 $entry->set('NOTE', $freetext);
72 if (!empty($pf->mobile
)) {
73 $entry->addTel(null
, $pf->mobile
, false
, true
, true
, false
, true
, true
);
77 if (!is_null($user)) {
78 $entry->addMail(null
, $user->bestalias
, true
);
79 $entry->addMail(null
, $user->bestalias_alternate
);
80 if ($user->forlife
!= $user->bestalias
) {
81 $entry->addMail(null
, $user->forlife
);
82 $entry->addMail(null
, $user->forlife_alternate
);
87 $adrs = $pf->iterAddresses(Profile
::ADDRESS_PERSO
);
88 while ($adr = $adrs->next()) {
89 // TODO : find a way to fetch only the "street" part of the address
90 $group = $entry->addHome($adr->text
, null
, null
, $adr->postalCode
,
91 $adr->locality
, $adr->administrativeArea
, $adr->country
,
92 $adr->hasFlag('current'), $adr->hasFlag('mail'), $adr->hasFlag('mail'));
93 foreach ($adr->phones() as $phone) {
94 if ($phone->type
== Phone
::TYPE_FIXED
) {
95 $entry->addTel($group, $phone->display
, false
, true
, true
, false
, false
,
96 $adr->hasFlag('current') && empty($pf->mobile
));
97 } else if ($phone->type
== Phone
::TYPE_FAX
) {
98 $entry->addTel($group, $phone->display
, true
, false
, false
, false
, false
, false
);
104 $adrs = $pf->iterAddresses(Profile
::ADDRESS_PRO
);
105 while ($adr = $adrs->next()) {
106 // TODO : link address to company
107 $group = $entry->addWork(null
, null
, null
, null
,
108 $adr->text
, null
, null
, $adr->postalCode
,
109 $adr->locality
, $adr->administrativeArea
, $adr->country
);
110 foreach ($adr->phones() as $phone) {
111 if ($phone->type
== Phone
::TYPE_FIXED
) {
112 $entry->addTel($group, $phone->display
);
113 } else if ($phone->type
== Phone
::TYPE_FAX
) {
114 $entry->addTel($group, $phone->display
, true
);
120 if (!is_null($user)) {
121 $alias = $user->emailAlias();
122 if (!is_null($alias)) {
123 $entry->addMail(null
, $alias);
128 if (!is_null($user)) {
129 $groups = $user->groups();
130 if (count($groups)) {
131 $gn = DirEnum
::getOptions(DirEnum
::GROUPESX
);
133 foreach (array_keys($groups) as $gid) {
134 $gns[$gid] = $gn[$gid];
136 $entry->set('X-GROUPS', join(', ', $gns));
140 $binets = $pf->getBinets();
142 if (count($binets)) {
143 $bn = DirEnum
::getOptions(DirEnum
::BINETS
);
145 foreach ($binets as $bid) {
146 $bns[$bid] = $bn[$bid];
148 $entry->set('X-BINETS', join(', ', $bns));
150 if (!empty($pf->section
)) {
151 $sections = DirEnum
::getOptions(DirEnum
::SECTIONS
);
152 $entry->set('X-SECTION', $sections[$pf->section
]);
158 "SELECT attach, attachmime
159 FROM profile_photos AS p
160 WHERE p.pid = {?}", $pf->id());
161 if ($res->numRows()) {
162 list($data, $type) = $res->fetchOneRow();
163 $entry->setPhoto($data, strtoupper($type));
170 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: