From ddaa62b8da770c403dddc57a5fda6e175762a2ee Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Tue, 16 Feb 2010 22:14:01 +0100 Subject: [PATCH] Makes use of PlIteratorUtils::map() to build contact calendar. Signed-off-by: Florent Bruneau --- core | 2 +- modules/carnet.php | 28 +++++++++++++++------------- templates/carnet/calendar.tpl | 4 ++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/core b/core index 29bd16d..8d37a36 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 29bd16dff22ad53c92c51e799a1e68dadf9aeff5 +Subproject commit 8d37a362f0def3c6cd94f31adab8f2d47a75a28e diff --git a/modules/carnet.php b/modules/carnet.php index 51d2fdc..fc0d8f9 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -347,6 +347,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); @@ -364,19 +378,7 @@ class CarnetModule extends PLModule $filter = new UserFilter(new UFC_Contact($user)); $profiles = $filter->iterProfiles(); - $annivs = Array(); - while ($profile = $profiles->next()) { - $date = strtotime($profile->birthdate); - $tomorrow = $date + 86400; - $annivs[] = array( - 'timestamp' => $date, - 'date' => date('Ymd', $date), - 'tomorrow' => date('Ymd', $tomorrow), - 'hruid' => $profile->hrid(), - 'summary' => 'Anniversaire de ' . $profile->fullName(true) - ); - } - $page->assign('events', $annivs); + $page->assign('events', PlIteratorUtils::map($profiles, array($this, 'buildBirthRef'))); pl_content_headers("text/calendar"); } diff --git a/templates/carnet/calendar.tpl b/templates/carnet/calendar.tpl index e6284fc..52df5e2 100644 --- a/templates/carnet/calendar.tpl +++ b/templates/carnet/calendar.tpl @@ -26,7 +26,7 @@ CALSCALE:GREGORIAN METHOD:PUBLISH {display_ical name="x-wr-calname" value="Anniversaires des X"} X-WR-TIMEZONE:Europe/Paris -{foreach from=$events item=e} +{iterate from=$events item=e} BEGIN:VEVENT DTSTAMP:{$e.timestamp|date_format:"%Y%m%dT%H%M%SZ"} DTSTART;VALUE=DATE:{$e.date} @@ -36,5 +36,5 @@ RRULE:FREQ=YEARLY;INTERVAL=1 CLASS:PUBLIC {display_ical name="summary" value=$e.summary} END:VEVENT -{/foreach} +{/iterate} END:VCALENDAR{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4