Try to define an exhaustive list of tables to copy.
[platal.git] / modules / carnet.php
index 0c8f790..fc0d8f9 100644 (file)
@@ -321,7 +321,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 +331,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 +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);
@@ -363,20 +377,8 @@ 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");
     }