3 * StatusNet, the distributed open-source microblogging tool
5 * List a group's members
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.
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.
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/>.
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/
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/lib/api.php';
37 * List 20 newest members of the group specified by name or ID.
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/
46 class ApiGroupMembershipAction extends ApiAction
57 * Take arguments for running
59 * @param array $args $_REQUEST args
61 * @return boolean success flag
65 function prepare($args)
67 parent::prepare($args);
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');
75 $this->group = $this->getTargetGroup($this->arg('id'));
77 $this->profiles = $this->getProfiles();
85 * Show the members of the group
87 * @param array $args $_REQUEST data (unused)
92 function handle($args)
94 parent::handle($args);
98 switch($this->format) {
100 $this->show_twitter_xml_users($this->profiles);
103 $this->show_json_users($this->profiles);
107 _('API method not found!'),
116 * Fetch the members of a group
118 * @return array $profiles list of profiles
121 function getProfiles()
125 $profile = $this->group->getMembers(
126 ($this->page - 1) * $this->count,
133 while ($profile->fetch()) {
134 $profiles[] = clone($profile);
141 * Is this action read only?
143 * @param array $args other arguments
145 * @return boolean true
148 function isReadOnly($args)
154 * When was this list of profiles last modified?
156 * @return string datestamp of the lastest profile in the group
159 function lastModified()
161 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
162 return strtotime($this->profiles[0]->created);
169 * An entity tag for this list of groups
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
175 * @return string etag
180 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
182 $last = count($this->profiles) - 1;
184 return '"' . implode(
186 array($this->arg('action'),
189 strtotime($this->profiles[0]->created),
190 strtotime($this->profiles[$last]->created))