Wiki selection is done by the Platal class.
[platal.git] / modules / carnet.php
index 51d2fdc..6f1b9a8 100644 (file)
@@ -79,7 +79,7 @@ class CarnetModule extends PLModule
 
     private function getSinglePromotion(PlPage &$page, $promo)
     {
-        if (!ctype_digit($promo) || $promo < 1920 || $promo > date('Y')) {
+        if (!(is_int($promo) || ctype_digit($promo)) || $promo < 1920 || $promo > date('Y')) {
             $page->trigError('Promotion invalide&nbsp;: ' . $promo . '.');
             return null;
         }
@@ -296,8 +296,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';
@@ -347,6 +345,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 +376,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");
     }