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 TwitterApiAction
58 * Take arguments for running
60 * @param array $args $_REQUEST args
62 * @return boolean success flag
66 function prepare($args)
68 parent::prepare($args);
70 $this->page = (int)$this->arg('page', 1);
71 $this->count = (int)$this->arg('count', 20);
72 $this->max_id = (int)$this->arg('max_id', 0);
73 $this->since_id = (int)$this->arg('since_id', 0);
74 $this->since = $this->arg('since');
76 $this->format = $this->arg('format');
77 $this->group = $this->getTargetGroup($this->arg('id'));
79 $this->profiles = $this->getProfiles();
87 * Show the members of the group
89 * @param array $args $_REQUEST data (unused)
94 function handle($args)
96 parent::handle($args);
100 switch($this->format) {
102 $this->show_twitter_xml_users($this->profiles);
105 $this->show_json_users($this->profiles);
109 _('API method not found!'),
118 * Fetch the members of a group
120 * @return array $profiles list of profiles
123 function getProfiles()
127 $profile = $this->group->getMembers(
128 ($this->page - 1) * $this->count,
135 while ($profile->fetch()) {
136 $profiles[] = clone($profile);
143 * Is this action read only?
145 * @param array $args other arguments
147 * @return boolean true
150 function isReadOnly($args)
156 * When was this list of profiles last modified?
158 * @return string datestamp of the lastest profile in the group
161 function lastModified()
163 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
164 return strtotime($this->profiles[0]->created);
171 * An entity tag for this list of groups
173 * Returns an Etag based on the action name, language
174 * the group id, and timestamps of the first and last
175 * user who has joined the group
177 * @return string etag
182 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
184 $last = count($this->profiles) - 1;
186 return '"' . implode(
188 array($this->arg('action'),
191 strtotime($this->profiles[0]->created),
192 strtotime($this->profiles[$last]->created))