<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2009 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;
- private $start;
- private $stop;
- private $pos;
- private $count;
-
- private $p1;
- private $p2;
-
- public function __construct(Notifs& $notifs)
+ public function __construct(PlUser &$owner)
{
- $this->notifs =& $notifs;
- foreach ($notifs->_data as $c) {
- foreach ($c as $promo) {
- $this->count += count($promo);
+ $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');
+ $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(),
+ 'user' => $user,
+ 'contact' => $owner->isContact($user));
}
}
- $this->pos = 0;
- reset($notifs->_data);
- if ($this->count > 0) {
- $this->p1 = current($notifs->_data);
- reset($this->p1);
- $this->p2 = current($this->p1);
- reset($this->p2);
- }
+ $this->it = PlIteratorUtils::fromArray($infos);
}
public function next()
{
- $this->pos++;
- $this->start = ($this->count > 0 && $this->pos == 1);
- $this->stop = ($this->count > 0 && $this->pos == $this->count);
- if ($this->count == 0) {
- return null;
- }
-
- $x = current($this->p2);
- if ($x === false) {
- $this->p2 = next($this->p1);
- if ($this->p2 === false) {
- $this->p1 = next($this->notifs->_data);
- if ($this->p1 === false) {
- return null;
- }
- reset($this->p1);
- $this->p2 = current($this->p1);
- }
- reset($this->p2);
- $x = current($this->p2);
- }
- $cid = key($this->notifs->_data);
- next($this->p2);
-
- global $globals;
- $author = $x['prenom'] . ' ' . $x['nom'] . ' (X' . $x['promo'] . ')';
-
- @require_once 'Date.php';
- @$date = new Date($x['date']);
- @$date = $date->format('%e %B %Y');
- 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));
+ $data = $this->it->next();
+ return $data['value'];
}
public function total()
{
- return $this->count;
+ return $this->it->total();
}
public function first()
{
- return $this->start;
+ return $this->it->first();
}
public function last()
{
- return $this->stop;
+ return $this->it->last();
}
}
'carnet/rss.tpl');
}
- protected function fetch($user)
+ protected function fetch(PlUser &$user)
{
- return new CarnetFeedIterator(new Notifs($user, false));
+ return new CarnetFeedIterator($user);
}
}