]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apigroupmembership.php
Remove more redundant $formats
[quix0rs-gnu-social.git] / actions / apigroupmembership.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List a group's members
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  API
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2009 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/api.php';
35
36 /**
37  * List 20 newest members of the group specified by name or ID. 
38  *
39  * @category API
40  * @package  StatusNet
41  * @author   Zach Copley <zach@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45
46 class ApiGroupMembershipAction extends TwitterApiAction
47 {
48     var $page     = null;
49     var $count    = null;
50     var $max_id   = null;
51     var $since_id = null;
52     var $since    = null;
53     var $group    = null;
54     var $profiles = null;
55
56     /**
57      * Take arguments for running
58      *
59      * @param array $args $_REQUEST args
60      *
61      * @return boolean success flag
62      *
63      */
64
65     function prepare($args)
66     {
67         parent::prepare($args);
68
69         $this->page     = (int)$this->arg('page', 1);
70         $this->count    = (int)$this->arg('count', 20);
71         $this->max_id   = (int)$this->arg('max_id', 0);
72         $this->since_id = (int)$this->arg('since_id', 0);
73         $this->since    = $this->arg('since');
74
75         $this->group  = $this->getTargetGroup($this->arg('id'));
76
77         $this->profiles = $this->getProfiles();
78
79         return true;
80     }
81
82     /**
83      * Handle the request
84      *
85      * Show the members of the group
86      *
87      * @param array $args $_REQUEST data (unused)
88      *
89      * @return void
90      */
91
92     function handle($args)
93     {
94         parent::handle($args);
95
96         // XXX: RSS and Atom
97
98         switch($this->format) {
99         case 'xml':
100             $this->show_twitter_xml_users($this->profiles);
101             break;
102         case 'json':
103             $this->show_json_users($this->profiles);
104             break;
105         default:
106             $this->clientError(
107                 _('API method not found!'),
108                 404,
109                 $this->format
110             );
111             break;
112         }
113     }
114
115     /**
116      * Fetch the members of a group
117      *
118      * @return array $profiles list of profiles 
119      */
120
121     function getProfiles()
122     {
123         $profiles = array();
124
125         $profile = $this->group->getMembers(
126             ($this->page - 1) * $this->count,
127             $this->count, 
128             $this->since_id, 
129             $this->max_id, 
130             $this->since
131         );
132
133         while ($profile->fetch()) {
134             $profiles[] = clone($profile);
135         }
136
137         return $profiles;
138     }
139
140     /**
141      * Is this action read only?
142      *
143      * @param array $args other arguments
144      *
145      * @return boolean true
146      */
147
148     function isReadOnly($args)
149     {
150         return true;
151     }
152
153     /**
154      * When was this list of profiles last modified?
155      *
156      * @return string datestamp of the lastest profile in the group
157      */
158
159     function lastModified()
160     {
161         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
162             return strtotime($this->profiles[0]->created);
163         }
164
165         return null;
166     }
167
168     /**
169      * An entity tag for this list of groups
170      *
171      * Returns an Etag based on the action name, language
172      * the group id, and timestamps of the first and last 
173      * user who has joined the group
174      *
175      * @return string etag
176      */
177
178     function etag()
179     {
180         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
181
182             $last = count($this->profiles) - 1;
183
184             return '"' . implode(
185                 ':',
186                 array($this->arg('action'),
187                       common_language(),
188                       $this->group->id,
189                       strtotime($this->profiles[0]->created),
190                       strtotime($this->profiles[$last]->created))
191             )
192             . '"';
193         }
194
195         return null;
196     }
197
198 }