X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=include%2Fvcard.inc.php;h=6e29640483d97a84a1604b490a94b59739e556b8;hb=ce0d7be772306674fadaf020511871aba1683816;hp=d16dae6e8762f5bdc32b10d742ce381204e9e59d;hpb=805f3d1679a53bb04fff34619c171a1381068612;p=platal.git diff --git a/include/vcard.inc.php b/include/vcard.inc.php index d16dae6..6e29640 100644 --- a/include/vcard.inc.php +++ b/include/vcard.inc.php @@ -1,6 +1,6 @@ photos = $photos; } - public function addUser($user) + public function addProfile($profile) { - $user = User::getSilent($user); - if ($user) { - $this->user_list[] = $user; + $profile = Profile::get($profile); + if ($profile) { + $this->profile_list[] = $profile; $this->count++; } } - public function addUsers(array $users) { - foreach ($users as $user) { - $this->addUser($user); + public function addProfiles(array $profiles) { + foreach ($profiles as $profile) { + $this->addProfile($profile); } } protected function fetch() { - return PlIteratorUtils::fromArray($this->user_list); + return PlIteratorUtils::fromArray($this->profile_list); } - protected function buildEntry($entry) + protected function buildEntry($pf) { global $globals; - $login = $entry['value']; - $user = get_user_details($login->login()); + $pf = $pf['value']; - if (empty($user['nom_usage'])) { - $entry = new PlVCardEntry($user['prenom'], $user['nom'], null, null, @$user['nickname']); - } else { - $entry = new PlVCardEntry($user['prenom'], array($user['nom'], $user['nom_usage']), null, null, @$user['nickname']); - } + $entry = new PlVCardEntry($pf->firstNames(), $pf->lastNames(), null, null, $pf->nickname); + + $user = $pf->owner(); // Free text - $freetext = '(' . $user['promo'] . ')'; + $freetext = '(' . $pf->promo . ')'; if ($this->freetext) { $freetext .= "\n" . $this->freetext; } - if (strlen(trim($user['freetext']))) { - $freetext .= "\n" . MiniWiki::WikiToText($user['freetext']); - } $entry->set('NOTE', $freetext); - - // Mobile - if (!empty($user['mobile'])) { - $entry->addTel(null, $user['mobile'], false, true, true, false, true, true); + if ($pf->mobile) { + $entry->addTel(null, $pf->mobile, false, true, true, false, true, true); } // Emails - $entry->addMail(null, $user['bestalias'] . '@' . $globals->mail->domain, true); - $entry->addMail(null, $user['bestalias'] . '@' . $globals->mail->domain2); - if ($user['bestalias'] != $user['forlife']) { - $entry->addMail(null, $user['forlife'] . '@' . $globals->mail->domain); - $entry->addMail(null, $user['forlife'] . '@' . $globals->mail->domain2); + if (!is_null($user)) { + $entry->addMail(null, $user->bestalias, true); + $entry->addMail(null, $user->bestalias_alternate); + if ($user->forlife != $user->bestalias) { + $entry->addMail(null, $user->forlife); + $entry->addMail(null, $user->forlife_alternate); + } } // Homes - foreach ($user['adr'] as $adr) { - $street = array($adr['adr1']); - if (!empty($adr['adr2'])) { - $street[] = $adr['adr2']; - } - if (!empty($adr['adr3'])) { - $street[] = $adr['adr3']; + $adrs = $pf->iterAddresses(Profile::ADDRESS_PERSO); + while ($adr = $adrs->next()) { + if (!$adr->postalCode || !$adr->locality || !$adr->country) { + $group = $entry->addHome($adr->text, null, null, null, + null, $adr->administrativeArea, null, + $adr->hasFlag('current'), $adr->hasFlag('mail'), $adr->hasFlag('mail')); + } else { + // TODO : find a way to fetch only the "street" part of the address + $group = $entry->addHome($adr->text, null, null, $adr->postalCode, + $adr->locality, $adr->administrativeArea, $adr->country, + $adr->hasFlag('current'), $adr->hasFlag('mail'), $adr->hasFlag('mail')); } - $group = $entry->addHome($street, null, null, $adr['postcode'], $adr['city'], $adr['region'], @$adr['country'], - $adr['active'], $adr['courier'], $adr['courier']); - if (!empty($adr['tels'])) { - foreach ($adr['tels'] as $tel) { - $fax = $tel['tel_type'] == 'Fax'; - $entry->addTel($group, $tel['tel'], $fax, !$fax, !$fax, false, false, !$fax && $adr['active'] && empty($user['mobile'])); + foreach ($adr->phones() as $phone) { + if ($phone->link_type == Phone::TYPE_FIXED) { + $entry->addTel($group, $phone->display, false, true, true, false, false, + $adr->hasFlag('current') && empty($pf->mobile)); + } else if ($phone->link_type == Phone::TYPE_FAX) { + $entry->addTel($group, $phone->display, true, false, false, false, false, false); } } } // Pro - foreach ($user['adr_pro'] as $pro) { - $street = array($adr['adr1']); - if (!empty($pro['adr2'])) { - $street[] = $pro['adr2']; - } - if (!empty($pro['adr3'])) { - $street[] = $pro['adr3']; - } - $group = $entry->addWork($pro['entreprise'], null, $pro['poste'], $pro['fonction'], - $street, null, null, $pro['postcode'], $pro['city'], $pro['region'], @$pro['country']); - if (!empty($pro['tel'])) { - $entry->addTel($group, $pro['tel']); + $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); + } else { + // TODO : link address to company + $group = $entry->addWork(null, null, null, null, + $adr->text, null, null, $adr->postalCode, + $adr->locality, $adr->administrativeArea, $adr->country); } - if (!empty($pro['fax'])) { - $entry->addTel($group, $pro['fax'], true); - } - if (!empty($pro['email'])) { - $entry->addMail($group, $pro['email']); + 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) { + $entry->addTel($group, $phone->display, true); + } } } // Melix - $res = XDB::query( - "SELECT alias - FROM virtual - INNER JOIN virtual_redirect USING(vid) - INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) - WHERE ( redirect={?} OR redirect={?} ) - AND alias LIKE '%@{$globals->mail->alias_dom}'", - $user['user_id'], - $user['forlife'].'@'.$globals->mail->domain, - $user['forlife'].'@'.$globals->mail->domain2); - if ($res->numRows()) { - $entry->addMail(null, $res->fetchOneCell()); + if (!is_null($user)) { + $alias = $user->emailAlias(); + if (!is_null($alias) && $pf->alias_pub == 'pub') { + $entry->addMail(null, $alias); + } } // Custom fields - if (count($user['gpxs_name'])) { - $entry->set('X-GROUPS', join(', ', $user['gpxs_name'])); + if (!is_null($user)) { + $groups = $user->groups(true, true); + if (count($groups)) { + $gn = DirEnum::getOptions(DirEnum::GROUPESX); + $gns = array(); + foreach (array_keys($groups) as $gid) { + $gns[$gid] = $gn[$gid]; + } + $entry->set('X-GROUPS', join(', ', $gns)); + } } - if (count($user['binets'])) { - $entry->set('X-BINETS', join(', ', $user['binets'])); + + $binets = $pf->getBinets(); + + if (count($binets)) { + $bn = DirEnum::getOptions(DirEnum::BINETS); + $bns = array(); + foreach ($binets as $bid) { + $bns[$bid] = $bn[$bid]; + } + $entry->set('X-BINETS', join(', ', $bns)); } - if (!empty($user['section'])) { - $entry->set('X-SECTION', $user['section']); + if (!empty($pf->section)) { + $entry->set('X-SECTION', $pf->section); } // Photo if ($this->photos) { $res = XDB::query( "SELECT attach, attachmime - FROM photo AS p - WHERE u.user_id = {?}", $login->id()); + FROM profile_photos AS p + WHERE p.pid = {?}", $pf->id()); if ($res->numRows()) { list($data, $type) = $res->fetchOneRow(); $entry->setPhoto($data, strtoupper($type));