fa8290bf772e51fe8c6ec910aa4384a3678e9579
[platal.git] / modules / carnet / feed.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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
28 private $start;
29 private $stop;
30 private $pos;
31 private $count;
32
33 private $p1;
34 private $p2;
35
36 public function __construct(Notifs& $notifs)
37 {
38 $this->notifs =& $notifs;
39 foreach ($notifs->_data as $c) {
40 foreach ($c as $promo) {
41 $this->count += count($promo);
42 }
43 }
44 $this->pos = 0;
45 reset($notifs->_data);
46 if ($this->count > 0) {
47 $this->p1 = current($notifs->_data);
48 reset($this->p1);
49 $this->p2 = current($this->p1);
50 reset($this->p2);
51 }
52 }
53
54 public function next()
55 {
56 $this->pos++;
57 $this->start = ($this->count > 0 && $this->pos == 1);
58 $this->stop = ($this->count > 0 && $this->pos == $this->count);
59 if ($this->count == 0) {
60 return null;
61 }
62
63 $x = current($this->p2);
64 if ($x === false) {
65 $this->p2 = next($this->p1);
66 if ($this->p2 === false) {
67 $this->p1 = next($this->notifs->_data);
68 if ($this->p1 === false) {
69 return null;
70 }
71 reset($this->p1);
72 $this->p2 = current($this->p1);
73 }
74 reset($this->p2);
75 $x = current($this->p2);
76 }
77 $cid = key($this->notifs->_data);
78 next($this->p2);
79
80 global $globals;
81 $author = $x['prenom'] . ' ' . $x['nom'] . ' (X' . $x['promo'] . ')';
82
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/'
91 . $x['bestalias'],
92 'title' => '[' . $this->notifs->_cats[$cid]['short'] . '] '
93 . $author . ' - le ' . $date));
94 }
95
96 public function total()
97 {
98 return $this->count;
99 }
100
101 public function first()
102 {
103 return $this->start;
104 }
105
106 public function last()
107 {
108 return $this->stop;
109 }
110 }
111
112 class CarnetFeed extends PlFeed
113 {
114 public function __construct()
115 {
116 global $globals;
117 parent::__construct($globals->core->sitename . ' :: Carnet',
118 $globals->baseurl . '/carnet/panel',
119 'Ton carnet polytechnicien',
120 $globals->baseurl . '/images/logo.png',
121 'carnet/rss.tpl');
122 }
123
124 protected function fetch($user)
125 {
126 return new CarnetFeedIterator(new Notifs($user, false));
127 }
128 }
129
130 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
131 ?>