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 require_once('user.func.inc.php');
24 class VCard
extends PlVCard
26 private $profile_list = array();
28 private $freetext = null
;
29 private $photos = true
;
31 public function __construct($photos = true
, $freetext = null
)
33 PlVCard
::$folding = false
;
34 $this->freetext
= $freetext;
35 $this->photos
= $photos;
38 public function addProfile($profile)
40 $profile = Profile
::get($profile);
42 $this->profile_list
[] = $profile;
47 public function addProfiles(array $profiles) {
48 foreach ($profiles as $profile) {
49 $this->addProfile($profile);
53 protected function fetch()
55 return PlIteratorUtils
::fromArray($this->profile_list
);
58 protected function buildEntry($pf)
62 $entry = new PlVCardEntry($pf->firstNames(), $pf->lastNames
, null
, null
, $pf->nickname
);
67 $freetext = '(' . $pf->promo
. ')';
68 if ($this->freetext
) {
69 $freetext .= "\n" . $this->freetext
;
71 $entry->set('NOTE', $freetext);
73 if (!empty($pf->mobile
)) {
74 $entry->addTel(null
, $pf->mobile
, false
, true
, true
, false
, true
, true
);
78 if (!is_null($user)) {
79 $entry->addMail(null
, $user->bestalias
, true
);
80 $entry->addMail(null
, $user->bestalias_alternate
);
81 if ($user->forlife
!= $user->bestalias
) {
82 $entry->addMail(null
, $user->forlife
);
83 $entry->addMail(null
, $user->forlife_alternate
);
88 $adrs = $pf->getAddresses(Profile
::ADDRESS_PERSO
);
89 while ($adr = $adrs->next()) {
90 // TODO : find a way to fetch only the "street" part of the address
91 $group = $entry->addHome($adr['text'], null
, null
, $adr['postalCode'],
92 $adr['locality'], $adr['administrativeArea'], $adr['country'],
93 $adr['current'], $adr['mail'], $adr['mail']);
94 if (!empty($adr['fixed_tel'])) {
95 $entry->addTel($group, $adr['fixed_tel'], false
, true
, true
, false
, false
, $adr['current'] && empty($pf->mobile
));
97 if (!empty($adr['fax_tel'])) {
98 $entry->addTel($group, $adr['fax_tel'], true
, false
, false
, false
, false
, false
);
103 $adrs = $pf->getAddresses(Profile
::ADDRESS_PRO
);
104 while ($adr = $adrs->next()) {
105 // TODO : link address to company
106 $group = $entry->addWork(null
, null
, null
, null
,
107 $adr['text'], null
, null
, $adr['postalCode'],
108 $adr['locality'], $adr['administrativeArea'], $adr['country']);
109 if (!empty($adr['fixed_tel'])) {
110 $entry->addTel($group, $adr['fixed_tel']);
112 if (!empty($adr['fax_tel'])) {
113 $entry->addTel($group, $adr['display_tel'], true
);
115 /* TODO : fetch email for jobs, too
116 if (!empty($pro['email'])) {
117 $entry->addMail($group, $pro['email']);
123 if (!is_null($user)) {
124 $alias = $user->emailAlias();
125 if (!is_null($alias)) {
126 $entry->addMail(null
, $alias);
131 if (!is_null($user)) {
132 $groups = $user->groups();
133 if (count($groups)) {
134 require_once "directory.enums.inc.php";
135 $gn = DirEnum
::getOptions(DirEnum
::GROUPESX
);
137 foreach (array_keys($groups) as $gid) {
138 $gns[$gid] = $gn[$gid];
140 $entry->set('X-GROUPS', join(', ', $gns));
144 $binets = $pf->getBinets();
146 if (count($binets)) {
147 require_once "directory.enums.inc.php";
148 $bn = DirEnum
::getOptions(DirEnum
::BINETS
);
150 foreach ($binets as $bid) {
151 $bns[$bid] = $bn[$bid];
153 $entry->set('X-BINETS', join(', ', $bid));
155 if (!empty($pf->section
)) {
156 require_once "directory.enums.inc.php";
157 $sections = DirEnum
::getOptions(DirEnum
::SECTIONS
);
158 $entry->set('X-SECTION', $sections[$pf->section
]);
164 "SELECT attach, attachmime
166 WHERE p.uid = {?}", $pf->id());
167 if ($res->numRows()) {
168 list($data, $type) = $res->fetchOneRow();
169 $entry->setPhoto($data, strtoupper($type));
176 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: