From c350577bb79078fabcb4818f4ffa31022d34ccb7 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Thu, 12 Feb 2009 22:27:02 +0100 Subject: [PATCH] Carnet RSS is back. Signed-off-by: Florent Bruneau --- classes/user.php | 14 ++++++++++++++ include/notifs.inc.php | 20 +++++++++++++++++++ modules/carnet/feed.inc.php | 47 +++++++++++++++++++++++---------------------- templates/carnet/rss.tpl | 10 +++++----- 4 files changed, 63 insertions(+), 28 deletions(-) diff --git a/classes/user.php b/classes/user.php index 6d1987f..ba271dd 100644 --- a/classes/user.php +++ b/classes/user.php @@ -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) { diff --git a/include/notifs.inc.php b/include/notifs.inc.php index 0f313fc..5e8d8ae 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -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); diff --git a/modules/carnet/feed.inc.php b/modules/carnet/feed.inc.php index 3172b4a..8f5a8e1 100644 --- a/modules/carnet/feed.inc.php +++ b/modules/carnet/feed.inc.php @@ -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); } } diff --git a/templates/carnet/rss.tpl b/templates/carnet/rss.tpl index 9b97c1d..6e3984a 100644 --- a/templates/carnet/rss.tpl +++ b/templates/carnet/rss.tpl @@ -20,14 +20,14 @@ {* *} {**************************************************************************} -{if $article->data}{$article->prenom} {$article->nom} a mis à jours les données suivantes :
{$article->data}
{/if} -{if !$article->contact and !$article->dcd} - +{if $article->data}{profile user=$article->user promo=false link=false} a mis à jours les données suivantes :
{$article->data}
{/if} +{if !$article->contact and !$article->dead} +
{icon name=add title="Ajouter" full=true} Ajouter à mes contacts
{/if} -{if !$article->dcd} - +{if !$article->dead} + {icon name=vcard title="Carte de visite" full=true} Télécharger la carte de visite électronique {/if} -- 2.1.4