Merge commit 'origin/platal-0.10.0'
[platal.git] / modules / carnet / feed.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 require_once 'notifs.inc.php';
23
24 class CarnetFeedIterator implements PlIterator
25 {
26 private $notifs;
27 private $it;
28
29 public function __construct(Notifs& $notifs)
30 {
31 $this->notifs =& $notifs;
32 $this->it = PlIteratorUtils::fromArray($notifs->_data, 3);
33 }
34
35 public function next()
36 {
37 $data = $this->it->next();
38 if (is_null($data)) {
39 return null;
40 }
41 $cid = $data['keys'][0];
42 $x = $data['value'];
43
44 global $globals;
45 @require_once 'Date.php';
46 @$date = new Date($x['date']);
47 @$date = $date->format('%e %B %Y');
48 $author = $x['prenom'] . ' ' . $x['nom'] . ' (X' . $x['promo'] . ')';
49 return array_merge($x,
50 array('author' => $author,
51 'publication' => $x['known'],
52 'id' => 'carnet' . $x['known'] . $cid . $x['bestalias'],
53 'link' => $globals->baseurl . '/profile/private/'
54 . $x['bestalias'],
55 'title' => '[' . $this->notifs->_cats[$cid]['short'] . '] '
56 . $author . ' - le ' . $date));
57 }
58
59 public function total()
60 {
61 return $this->it->total();
62 }
63
64 public function first()
65 {
66 return $this->it->first();
67 }
68
69 public function last()
70 {
71 return $this->it->last();
72 }
73 }
74
75 class CarnetFeed extends PlFeed
76 {
77 public function __construct()
78 {
79 global $globals;
80 parent::__construct($globals->core->sitename . ' :: Carnet',
81 $globals->baseurl . '/carnet/panel',
82 'Ton carnet polytechnicien',
83 $globals->baseurl . '/images/logo.png',
84 'carnet/rss.tpl');
85 }
86
87 protected function fetch(PlUser &$user)
88 {
89 return new CarnetFeedIterator(new Notifs($user->id(), false));
90 }
91 }
92
93 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
94 ?>