Commit | Line | Data |
---|---|---|
4f18bb11 FB |
1 | <?php |
2 | /*************************************************************************** | |
9f5bd98e | 3 | * Copyright (C) 2003-2010 Polytechnique.org * |
4f18bb11 FB |
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 | ||
aa21c568 FB |
22 | class UserFilterIterator implements PlIterator |
23 | { | |
24 | private $it; | |
25 | private $user; | |
26 | public function __construct(PlIterator &$it, PlUser &$user) | |
27 | { | |
28 | $this->it =& $it; | |
29 | $this->user =& $user; | |
30 | } | |
31 | ||
32 | public function total() | |
33 | { | |
34 | return $this->it->total(); | |
35 | } | |
36 | ||
37 | public function first() | |
38 | { | |
39 | return $this->it->first(); | |
40 | } | |
41 | ||
42 | public function last() | |
43 | { | |
44 | return $this->it->last(); | |
45 | } | |
46 | ||
47 | public function next() | |
48 | { | |
49 | while ($n = $this->it->next()) { | |
50 | $uf = UserFilter::getLegacy($n['promo_min'], $n['promo_max']); | |
51 | if ($uf->checkUser($this->user)) { | |
52 | return $n; | |
53 | } | |
54 | } | |
55 | return null; | |
56 | } | |
57 | } | |
58 | ||
4f18bb11 FB |
59 | class XnetGrpEventFeed extends PlFeed |
60 | { | |
61 | public function __construct() | |
62 | { | |
63 | global $globals; | |
64 | $name = $globals->asso('nom'); | |
65 | $url = $globals->baseurl . '/' . $globals->asso('diminutif'); | |
66 | parent::__construct('Polytechnique.net :: ' . $name . ' :: News', | |
67 | $url, | |
68 | 'L\'actualité du groupe ' . $name, | |
69 | $url . '/logo', | |
22c8c0c3 | 70 | 'xnetgrp/announce-rss.tpl'); |
4f18bb11 FB |
71 | } |
72 | ||
3f63a693 | 73 | protected function fetch(PlUser &$user) |
4f18bb11 FB |
74 | { |
75 | global $globals; | |
76 | if (!is_null($user)) { | |
aa21c568 | 77 | return new UserFilterIterator( |
14bc135e SJ |
78 | XDB::iterator("SELECT id, titre AS title, texte, contacts, |
79 | create_date AS publication, | |
80 | FIND_IN_SET('photo', flags) AS photo, | |
81 | CONCAT({?}, '/#art', id) AS link | |
82 | FROM group_announces | |
b58e5ac2 | 83 | WHERE expiration >= NOW() AND asso_id = {?}", |
aa21c568 | 84 | $this->link, $globals->asso('id'), $user)); |
4f18bb11 | 85 | } else { |
14bc135e SJ |
86 | return XDB::iterator("SELECT id, titre AS title, texte, create_date AS publication, |
87 | CONCAT({?}, '/#art', id) AS link, | |
aa21c568 | 88 | NULL AS photo, NULL AS contacts |
14bc135e | 89 | FROM group_announces |
b58e5ac2 | 90 | WHERE FIND_IN_SET('public', flags) AND expiration >= NOW() AND asso_id = {?}", |
4f18bb11 FB |
91 | $this->link, $globals->asso('id')); |
92 | } | |
93 | } | |
94 | } | |
95 | ||
96 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
97 | ||
98 | ?> |