Merge branch 'platal-1.0.0'
[platal.git] / modules / carnet / feed.inc.php
index fad227c..ea4f52c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2008 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
  ***************************************************************************/
 
 require_once 'notifs.inc.php';
+@require_once 'Date.php';
 
 class CarnetFeedIterator implements PlIterator
 {
     private $notifs;
     private $it;
 
-    public function __construct(Notifs& $notifs)
+    public function __construct(PlUser &$owner)
     {
-        $this->notifs =& $notifs;
-        $this->it = PlIteratorUtils::fromArray($notifs->_data, 3);
+        $notifs = Watch::getEvents($owner);
+        $infos  = array();
+        foreach ($notifs as $n) {
+            foreach ($n['users'] as $user) {
+                $op   = $n['operation'];
+                $date = $op->getDate($user);
+                @$datetext = new Date($date);
+                @$datetext = $datetext->format('%e %B %Y');
+                $profile = $user->profile();
+                $infos[] = array('operation'   => $op,
+                                 'title'       => '[' . $op->getTitle(1) . ']  - ' . $user->fullName() . ' le ' . $datetext,
+                                 'author'      => $user->fullName(),
+                                 'publication' => $op->publicationDate($user),
+                                 'date'        => strtotime($date),
+                                 'id'          => $op->flag . '-' . $user->id() . '-' . strtotime($date),
+                                 'data'        => $op->getData($user),
+                                 'hruid'       => $user->login(),
+                                 'dead'        => $user->deathdate,
+                                 'profile'     => $user->profile()->hrid(),
+                                 'link'        => Platal::globals()->baseurl . '/profile/' . $profile->hrid(),
+                                 'user'        => $user,
+                                 'contact'     => $owner->isContact($profile));
+            }
+        }
+        $this->it = PlIteratorUtils::fromArray($infos);
     }
 
     public function next()
     {
         $data = $this->it->next();
-        if (is_null($data)) {
-            return null;
-        }
-        $cid  = $data['keys'][0];
-        $x    = $data['value'];
-
-        global $globals;
-        @require_once 'Date.php';
-        @$date = new Date($x['date']);
-        @$date = $date->format('%e %B %Y');
-        $author = $x['prenom'] . ' ' . $x['nom'] . ' (X' . $x['promo'] . ')';
-        return array_merge($x, 
-                    array('author' => $author,
-                          'publication' => $x['known'],
-                          'id' => 'carnet' . $x['known'] . $cid . $x['bestalias'],
-                          'link' => $globals->baseurl . '/profile/private/'
-                                    . $x['bestalias'],
-                          'title' => '[' . $this->notifs->_cats[$cid]['short'] . '] '
-                                     . $author . ' - le ' . $date));
+        return $data['value'];
     }
 
     public function total()
@@ -84,9 +90,9 @@ class CarnetFeed extends PlFeed
                             'carnet/rss.tpl');
     }
 
-    protected function fetch($user)
+    protected function fetch(PlUser &$user)
     {
-        return new CarnetFeedIterator(new Notifs($user, false));
+        return new CarnetFeedIterator($user);
     }
 }