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 Craig Andrews <candrews@integralblue.com>
25 * @author Evan Prodromou <evan@status.net>
26 * @author Jeffery To <jeffery.to@gmail.com>
27 * @author Zach Copley <zach@status.net>
28 * @copyright 2009 StatusNet, Inc.
29 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
30 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
31 * @link http://status.net/
34 if (!defined('STATUSNET')) {
39 * List 20 newest members of the group specified by name or ID.
43 * @author Craig Andrews <candrews@integralblue.com>
44 * @author Evan Prodromou <evan@status.net>
45 * @author Jeffery To <jeffery.to@gmail.com>
46 * @author Zach Copley <zach@status.net>
47 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
48 * @link http://status.net/
50 class ApiGroupMembershipAction extends ApiPrivateAuthAction
56 * Take arguments for running
58 * @param array $args $_REQUEST args
60 * @return boolean success flag
62 protected function prepare(array $args=array())
64 parent::prepare($args);
66 $this->group = $this->getTargetGroup($this->arg('id'));
67 if (empty($this->group)) {
68 // TRANS: Client error displayed trying to show group membership on a non-existing group.
69 $this->clientError(_('Group not found.'), 404);
72 $this->profiles = $this->getProfiles();
80 * Show the members of the group
84 protected function handle()
90 switch($this->format) {
92 $this->showTwitterXmlUsers($this->profiles);
95 $this->showJsonUsers($this->profiles);
98 // TRANS: Client error displayed when coming across a non-supported API method.
99 $this->clientError(_('API method not found.'), 404);
104 * Fetch the members of a group
106 * @return array $profiles list of profiles
108 function getProfiles()
112 $profile = $this->group->getMembers(
113 ($this->page - 1) * $this->count,
119 while ($profile->fetch()) {
120 $profiles[] = clone($profile);
127 * Is this action read only?
129 * @param array $args other arguments
131 * @return boolean true
133 function isReadOnly($args)
139 * When was this list of profiles last modified?
141 * @return string datestamp of the lastest profile in the group
143 function lastModified()
145 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
146 return strtotime($this->profiles[0]->created);
153 * An entity tag for this list of groups
155 * Returns an Etag based on the action name, language
156 * the group id, and timestamps of the first and last
157 * user who has joined the group
159 * @return string etag
163 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
165 $last = count($this->profiles) - 1;
167 return '"' . implode(
169 array($this->arg('action'),
170 common_user_cache_hash($this->auth_user),
173 strtotime($this->profiles[0]->created),
174 strtotime($this->profiles[$last]->created))