Carnet RSS is back.
[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(PlUser &$owner)
30 {
31 $notifs = Watch::getEvents($owner);
32 $infos = array();
33 foreach ($notifs as $n) {
34 foreach ($n['users'] as $user) {
35 $op = $n['operation'];
36 $date = $op->getDate($user);
37 $infos[] = array('operation' => $op,
38 'title' => '[' . $op->getTitle(1) . '] - ' . $user->fullName(),
39 'author' => $user->fullName(),
40 'publication' => strtotime($op->publicationDate($user)),
41 'date' => strtotime($date),
42 'id' => $op->flag . strtotime($date),
43 'data' => $op->getData($user),
44 'hruid' => $user->login(),
45 'dead' => $user->deathdate,
46 'profile' => $user->profile()->hrid(),
47 'user' => $user,
48 'contact' => $owner->isContact($user));
49 }
50 }
51 $this->it = PlIteratorUtils::fromArray($infos);
52 }
53
54 public function next()
55 {
56 $data = $this->it->next();
57 return $data['value'];
58 }
59
60 public function total()
61 {
62 return $this->it->total();
63 }
64
65 public function first()
66 {
67 return $this->it->first();
68 }
69
70 public function last()
71 {
72 return $this->it->last();
73 }
74 }
75
76 class CarnetFeed extends PlFeed
77 {
78 public function __construct()
79 {
80 global $globals;
81 parent::__construct($globals->core->sitename . ' :: Carnet',
82 $globals->baseurl . '/carnet/panel',
83 'Ton carnet polytechnicien',
84 $globals->baseurl . '/images/logo.png',
85 'carnet/rss.tpl');
86 }
87
88 protected function fetch(PlUser &$user)
89 {
90 return new CarnetFeedIterator($user);
91 }
92 }
93
94 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
95 ?>