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)
60 $entry = new PlVCardEntry($pf->firstNames(), $pf->lastNames
, null
, null
, $pf->nickname
);
65 $freetext = '(' . $pf->promo
. ')';
66 if ($this->freetext
) {
67 $freetext .= "\n" . $this->freetext
;
69 $entry->set('NOTE', $freetext);
71 if (!empty($pf->mobile
)) {
72 $entry->addTel(null
, $pf->mobile
, false
, true
, true
, false
, true
, true
);
76 if (!is_null($user)) {
77 $entry->addMail(null
, $user->bestalias
, true
);
78 $entry->addMail(null
, $user->bestalias_alternate
);
79 if ($user->forlife
!= $user->bestalias
) {
80 $entry->addMail(null
, $user->forlife
);
81 $entry->addMail(null
, $user->forlife_alternate
);
86 $adrs = $pf->iterAddresses(Profile
::ADDRESS_PERSO
);
87 while ($adr = $adrs->next()) {
88 // TODO : find a way to fetch only the "street" part of the address
89 $group = $entry->addHome($adr['text'], null
, null
, $adr['postalCode'],
90 $adr['locality'], $adr['administrativeArea'], $adr['country'],
91 $adr['current'], $adr['mail'], $adr['mail']);
92 if (!empty($adr['fixed_tel'])) {
93 $entry->addTel($group, $adr['fixed_tel'], false
, true
, true
, false
, false
, $adr['current'] && empty($pf->mobile
));
95 if (!empty($adr['fax_tel'])) {
96 $entry->addTel($group, $adr['fax_tel'], true
, false
, false
, false
, false
, false
);
101 $adrs = $pf->iterAddresses(Profile
::ADDRESS_PRO
);
102 while ($adr = $adrs->next()) {
103 // TODO : link address to company
104 $group = $entry->addWork(null
, null
, null
, null
,
105 $adr['text'], null
, null
, $adr['postalCode'],
106 $adr['locality'], $adr['administrativeArea'], $adr['country']);
107 if (!empty($adr['fixed_tel'])) {
108 $entry->addTel($group, $adr['fixed_tel']);
110 if (!empty($adr['fax_tel'])) {
111 $entry->addTel($group, $adr['display_tel'], true
);
113 /* TODO : fetch email for jobs, too
114 if (!empty($pro['email'])) {
115 $entry->addMail($group, $pro['email']);
121 if (!is_null($user)) {
122 $alias = $user->emailAlias();
123 if (!is_null($alias)) {
124 $entry->addMail(null
, $alias);
129 if (!is_null($user)) {
130 $groups = $user->groups();
131 if (count($groups)) {
132 $gn = DirEnum
::getOptions(DirEnum
::GROUPESX
);
134 foreach (array_keys($groups) as $gid) {
135 $gns[$gid] = $gn[$gid];
137 $entry->set('X-GROUPS', join(', ', $gns));
141 $binets = $pf->getBinets();
143 if (count($binets)) {
144 $bn = DirEnum
::getOptions(DirEnum
::BINETS
);
146 foreach ($binets as $bid) {
147 $bns[$bid] = $bn[$bid];
149 $entry->set('X-BINETS', join(', ', $bid));
151 if (!empty($pf->section
)) {
152 $sections = DirEnum
::getOptions(DirEnum
::SECTIONS
);
153 $entry->set('X-SECTION', $sections[$pf->section
]);
159 "SELECT attach, attachmime
161 WHERE p.uid = {?}", $pf->id());
162 if ($res->numRows()) {
163 list($data, $type) = $res->fetchOneRow();
164 $entry->setPhoto($data, strtoupper($type));
171 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: