2 /***************************************************************************
3 * Copyright (C) 2003-2008 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once 'notifs.inc.php';
24 class CarnetFeedIterator
implements PlIterator
36 public function __construct(Notifs
& $notifs)
38 $this->notifs
=& $notifs;
39 foreach ($notifs->_data
as $c) {
40 foreach ($c as $promo) {
41 $this->count +
= count($promo);
45 reset($notifs->_data
);
46 if ($this->count
> 0) {
47 $this->p1
= current($notifs->_data
);
49 $this->p2
= current($this->p1
);
54 public function next()
57 $this->first
= ($this->count
> 0 && $this->pos
== 1);
58 $this->last
= ($this->count
> 0 && $this->pos
== $this->count
);
59 if ($this->count
== 0) {
63 $x = current($this->p2
);
65 $this->p2
= next($this->p1
);
66 if ($this->p2
=== false
) {
67 $this->p1
= next($this->notifs
->_data
);
68 if ($this->p1
=== false
) {
72 $this->p2
= current($this->p1
);
75 $x = current($this->p2
);
77 $cid = key($this->notifs
->_data
);
81 $author = $x['prenom'] . ' ' . $x['nom'] . ' (X' . $x['promo'] . ')';
83 @require_once
'Date.php';
84 @$date = new Date($x['date']);
85 @$date = $date->format('%e %B %Y');
86 return array_merge($x,
87 array('author' => $author,
88 'publication' => $x['known'],
89 'id' => 'carnet' . $x['known'] . $cid . $x['bestalias'],
90 'link' => $globals->baseurl
. '/profile/private/'
92 'title' => '[' . $this->notifs
->_cats
[$cid]['short'] . '] '
93 . $author . ' - le ' . $date));
96 public function total()
101 public function first()
106 public function last()
112 class CarnetFeed
extends PlFeed
114 public function __construct()
117 parent
::__construct($globals->core
->sitename
. ' :: Carnet',
118 $globals->baseurl
. '/carnet/panel',
119 'Ton carnet polytechnicien',
120 $globals->baseurl
. '/images/logo.png',
124 protected function fetch($user)
126 return new CarnetFeedIterator(new Notifs($user, false
));
130 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: