Carnet RSS is back.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 12 Feb 2009 21:27:02 +0000 (22:27 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 12 Feb 2009 21:27:02 +0000 (22:27 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/user.php
include/notifs.inc.php
modules/carnet/feed.inc.php
templates/carnet/rss.tpl

index 6d1987f..ba271dd 100644 (file)
@@ -446,6 +446,20 @@ class User extends PlUser
         return $this->watch_last;
     }
 
+
+    // Contacts
+    private $contacts = null;
+    public function isContact(PlUser &$user)
+    {
+        if ($this->contacts) {
+            $this->contacts = XDB::fetchAllAssoc('contact', 'SELECT  *
+                                                               FROM  contacts
+                                                              WHERE  uid = {?}',
+                                                 $this->id());
+        }
+        return isset($this->contacts[$user->id()]);
+    }
+
     // Return permission flags for a given permission level.
     public static function makePerms($perms, $is_admin)
     {
index 0f313fc..5e8d8ae 100644 (file)
@@ -43,10 +43,20 @@ abstract class WatchOperation
     abstract public function getOrder();
     abstract public function getDate(PlUser &$user);
 
+    public function publicationDate(PlUser &$user)
+    {
+        return $this->getDate($user);
+    }
+
     public function seen(PlUser &$user, $last)
     {
         return strtotime($this->getDate($user)) > $last;
     }
+
+    public function getData(PlUser &$user)
+    {
+        return null;
+    }
 }
 
 class WatchProfileUpdate extends WatchOperation
@@ -123,6 +133,11 @@ class WatchDeath extends WatchOperation
         return $user->profile()->deathdate;
     }
 
+    public function publicationDate(PlUser &$user)
+    {
+        return $user->profile()->deathdate_rec;
+    }
+
     public function seen(PlUser &$user, $last)
     {
         return strtotime($user->profile()->deathdate_rec) > $last;
@@ -155,6 +170,11 @@ class WatchBirthday extends WatchOperation
         return $user->profile()->next_birthday;
     }
 
+    public function publicationDate(PlUser &$user)
+    {
+        return date('Y-m-d', strtotime($user->profile()->next_birthday) - self::WATCH_LIMIT);
+    }
+
     public function seen(PlUser &$user, $last)
     {
         $birthday = strtotime($user->profile()->next_birthday);
index 3172b4a..8f5a8e1 100644 (file)
@@ -26,34 +26,35 @@ 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);
+                $infos[] = array('operation'   => $op,
+                                 'title'       => '[' . $op->getTitle(1) . ']  - ' . $user->fullName(),
+                                 'author'      => $user->fullName(),
+                                 'publication' => strtotime($op->publicationDate($user)),
+                                 'date'        => strtotime($date),
+                                 'id'          => $op->flag . strtotime($date),
+                                 'data'        => $op->getData($user),
+                                 'hruid'       => $user->login(),
+                                 'dead'        => $user->deathdate,
+                                 'profile'     => $user->profile()->hrid(),
+                                 'user'        => $user,
+                                 'contact'     => $owner->isContact($user));
+            }
+        }
+        $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()
@@ -86,7 +87,7 @@ class CarnetFeed extends PlFeed
 
     protected function fetch(PlUser &$user)
     {
-        return new CarnetFeedIterator(new Notifs($user->id(), false));
+        return new CarnetFeedIterator($user);
     }
 }
 
index 9b97c1d..6e3984a 100644 (file)
 {*                                                                        *}
 {**************************************************************************}
 
-{if $article->data}{$article->prenom} {$article->nom} a mis à jours les données suivantes&nbsp;:<br />{$article->data}<br />{/if}
-{if !$article->contact and !$article->dcd}
-<a href="{#globals.baseurl#}/carnet/contacts?action=ajouter&amp;user={$article->bestalias}&amp;token={$rss_hash}">
+{if $article->data}{profile user=$article->user promo=false link=false} a mis à jours les données suivantes&nbsp;:<br />{$article->data}<br />{/if}
+{if !$article->contact and !$article->dead}
+<a href="{#globals.baseurl#}/carnet/contacts?action=ajouter&amp;user={$article->hruid}&amp;token={$rss_hash}">
   {icon name=add title="Ajouter" full=true} Ajouter &agrave; mes contacts
 </a><br />
 {/if}
-{if !$article->dcd}
-<a href="{#globals.baseurl#}/vcard/{$article->bestalias}.vcf">
+{if !$article->dead}
+<a href="{#globals.baseurl#}/vcard/{$article->profile}.vcf">
   {icon name=vcard title="Carte de visite" full=true} T&eacute;l&eacute;charger la carte de visite &eacute;lectronique
 </a>
 {/if}