X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fcarnet.php;h=afd1a315d3641d6198adf7f9e0aed5ba40dc7a74;hb=206cb50c8bb9924ebb4335af7e9cb951ef3a23aa;hp=5dbf71a5dab119ed85655efabf2620c3f36dc1b6;hpb=d6ccc6055edaf8aa9d33c5d27c96b6e1c8ef9aa1;p=platal.git diff --git a/modules/carnet.php b/modules/carnet.php index 5dbf71a..afd1a31 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -1,6 +1,6 @@ date('Y')) { + if (!(is_int($promo) || ctype_digit($promo)) || $promo < 1920 || $promo > date('Y')) { $page->trigError('Promotion invalide : ' . $promo . '.'); return null; } @@ -255,7 +255,7 @@ class CarnetModule extends PLModule $this->_add_rss_link($page); $uid = S::i('uid'); - $user = Env::v('user'); + $user = S::user(); // For XSRF protection, checks both the normal xsrf token, and the special RSS token. // It allows direct linking to contact adding in the RSS feed. @@ -285,7 +285,6 @@ class CarnetModule extends PLModule } $search = false; - $user = S::user(); require_once 'userset.inc.php'; @@ -296,8 +295,6 @@ class CarnetModule extends PLModule } if ($search && trim(Env::v('quick'))) { $base = 'carnet/contacts/search'; - - Platal::load('search', 'classes.inc.php'); $view = new SearchSet(true, false, new UFC_Contact($user)); } else { $base = 'carnet/contacts'; @@ -321,7 +318,7 @@ class CarnetModule extends PLModule Platal::session()->close(); - $order = array(new UFO_Name(UserFilter::LASTNAME), new UFO_Name(UserFilter::FIRSTNAME)); + $order = array(new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); if ($arg0 == 'promo') { $order = array_unshift($order, new UFO_Promo()); } else { @@ -331,8 +328,8 @@ class CarnetModule extends PLModule $pdf = new ContactsPDF(); - $profiles = $filter->getProfiles(); - foreach ($profiles as $p) { + $it = $filter->iterProfiles(); + while ($p = $it->next()) { $pdf = ContactsPDF::addContact($pdf, $p, $arg0 == 'photos' || $arg1 == 'photos'); } $pdf->Output(); @@ -347,6 +344,20 @@ class CarnetModule extends PLModule return $feed->run($page, $user, $hash); } + function buildBirthRef(Profile $profile) + { + $date = strtotime($profile->birthdate); + $tomorrow = $date + 86400; + return array( + 'timestamp' => $date, + 'date' => date('Ymd', $date), + 'tomorrow' => date('Ymd', $tomorrow), + 'hruid' => $profile->hrid(), + 'summary' => 'Anniversaire de ' . $profile->fullName(true) + ); + } + + function handler_ical(&$page, $alias = null, $hash = null) { $user = Platal::session()->tokenAuth($alias, $hash); @@ -363,31 +374,17 @@ class CarnetModule extends PLModule $page->register_function('display_ical', 'display_ical'); $filter = new UserFilter(new UFC_Contact($user)); - $annivs = Array(); - foreach ($filter->getUsers() as $u) { - $profile = $u->profile(); - $date = strtotime($profile->birthdate); - $tomorrow = $date + 86400; - $annivs[] = array( - 'timestamp' => strtotime($user->registration_date), - 'date' => date('Ymd', $date), - 'tomorrow' => date('Ymd', $tomorrow), - 'hruid' => $profile->hrid(), - 'summary' => 'Anniversaire de ' . $profile->fullName(true) - ); - } - $page->assign('events', $annivs); + $profiles = $filter->iterProfiles(); + $page->assign('events', PlIteratorUtils::map($profiles, array($this, 'buildBirthRef'))); pl_content_headers("text/calendar"); } function handler_vcard(&$page, $photos = null) { - $res = XDB::query('SELECT contact - FROM contacts - WHERE uid = {?}', S::v('uid')); + $pf = new ProfileFilter(new UFC_Contact(S::user())); $vcard = new VCard($photos == 'photos'); - $vcard->addUsers($res->fetchColumn()); + $vcard->addProfiles($pf->getProfiles()); $vcard->show(); } }