User ProfileIterator for contacts (pdf and calendar).
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 16 Feb 2010 20:45:22 +0000 (21:45 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 16 Feb 2010 20:45:22 +0000 (21:45 +0100)
Also fix the code of ProfileIterator: Profile constructor is private, so
use Profile::get() factory with the current row.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/profile.php
core
modules/carnet.php

index 3e9ea2d..d6694ba 100644 (file)
@@ -495,6 +495,9 @@ class Profile
      */
     public static function get($login)
     {
+        if (is_array($login)) {
+            return new Profile($login);
+        }
         $pid = self::getPID($login);
         if (!is_null($pid)) {
             $it = self::iterOverPIDs(array($pid), false);
@@ -590,7 +593,7 @@ class ProfileIterator implements PlIterator
         if ($data == null) {
             return null;
         } else {
-            return new Profile($data);
+            return Profile::get($data);
         }
     }
 
diff --git a/core b/core
index 47595f9..29bd16d 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 47595f9a4a4f4ee903e6ac02d64b9b5b5b6bf191
+Subproject commit 29bd16dff22ad53c92c51e799a1e68dadf9aeff5
index 0c8f790..51d2fdc 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();
@@ -363,13 +363,13 @@ class CarnetModule extends PLModule
         $page->register_function('display_ical', 'display_ical');
 
         $filter = new UserFilter(new UFC_Contact($user));
+        $profiles = $filter->iterProfiles();
         $annivs = Array();
-        foreach ($filter->getUsers() as $u) {
-            $profile = $u->profile();
+        while ($profile = $profiles->next()) {
             $date = strtotime($profile->birthdate);
             $tomorrow = $date + 86400;
             $annivs[] = array(
-                'timestamp' => strtotime($user->registration_date),
+                'timestamp' => $date,
                 'date' => date('Ymd', $date),
                 'tomorrow' => date('Ymd', $tomorrow),
                 'hruid' => $profile->hrid(),