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
52 * Take arguments for running
54 * @param array $args $_REQUEST args
56 * @return boolean success flag
60 function prepare($args)
62 parent::prepare($args);
64 $this->group = $this->getTargetGroup($this->arg('id'));
65 $this->profiles = $this->getProfiles();
73 * Show the members of the group
75 * @param array $args $_REQUEST data (unused)
80 function handle($args)
82 parent::handle($args);
86 switch($this->format) {
88 $this->showTwitterXmlUsers($this->profiles);
91 $this->showJsonUsers($this->profiles);
95 _('API method not found!'),
104 * Fetch the members of a group
106 * @return array $profiles list of profiles
109 function getProfiles()
113 $profile = $this->group->getMembers(
114 ($this->page - 1) * $this->count,
121 while ($profile->fetch()) {
122 $profiles[] = clone($profile);
129 * Is this action read only?
131 * @param array $args other arguments
133 * @return boolean true
136 function isReadOnly($args)
142 * When was this list of profiles last modified?
144 * @return string datestamp of the lastest profile in the group
147 function lastModified()
149 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
150 return strtotime($this->profiles[0]->created);
157 * An entity tag for this list of groups
159 * Returns an Etag based on the action name, language
160 * the group id, and timestamps of the first and last
161 * user who has joined the group
163 * @return string etag
168 if (!empty($this->profiles) && (count($this->profiles) > 0)) {
170 $last = count($this->profiles) - 1;
172 return '"' . implode(
174 array($this->arg('action'),
177 strtotime($this->profiles[0]->created),
178 strtotime($this->profiles[$last]->created))