Makes use of PlIteratorUtils::map() to build contact calendar.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 16 Feb 2010 21:14:01 +0000 (22:14 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 16 Feb 2010 21:14:01 +0000 (22:14 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
core
modules/carnet.php
templates/carnet/calendar.tpl

diff --git a/core b/core
index 29bd16d..8d37a36 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 29bd16dff22ad53c92c51e799a1e68dadf9aeff5
+Subproject commit 8d37a362f0def3c6cd94f31adab8f2d47a75a28e
index 51d2fdc..fc0d8f9 100644 (file)
@@ -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");
     }
index e6284fc..52df5e2 100644 (file)
@@ -26,7 +26,7 @@ CALSCALE:GREGORIAN
 METHOD:PUBLISH\r
 {display_ical name="x-wr-calname" value="Anniversaires des X"}\r
 X-WR-TIMEZONE:Europe/Paris\r
-{foreach from=$events item=e}\r
+{iterate from=$events item=e}\r
 BEGIN:VEVENT\r
 DTSTAMP:{$e.timestamp|date_format:"%Y%m%dT%H%M%SZ"}\r
 DTSTART;VALUE=DATE:{$e.date}\r
@@ -36,5 +36,5 @@ RRULE:FREQ=YEARLY;INTERVAL=1
 CLASS:PUBLIC\r
 {display_ical name="summary" value=$e.summary}\r
 END:VEVENT\r
-{/foreach}\r
+{/iterate}\r
 END:VCALENDAR{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}