]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/apigroupmembership.php
These same params are used in most API actions; moved to base API class
[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 ApiAction
47 {
48     var $group    = null;
49     var $profiles = null;
50
51     /**
52      * Take arguments for running
53      *
54      * @param array $args $_REQUEST args
55      *
56      * @return boolean success flag
57      *
58      */
59
60     function prepare($args)
61     {
62         parent::prepare($args);
63
64         $this->group    = $this->getTargetGroup($this->arg('id'));
65         $this->profiles = $this->getProfiles();
66
67         return true;
68     }
69
70     /**
71      * Handle the request
72      *
73      * Show the members of the group
74      *
75      * @param array $args $_REQUEST data (unused)
76      *
77      * @return void
78      */
79
80     function handle($args)
81     {
82         parent::handle($args);
83
84         // XXX: RSS and Atom
85
86         switch($this->format) {
87         case 'xml':
88             $this->show_twitter_xml_users($this->profiles);
89             break;
90         case 'json':
91             $this->show_json_users($this->profiles);
92             break;
93         default:
94             $this->clientError(
95                 _('API method not found!'),
96                 404,
97                 $this->format
98             );
99             break;
100         }
101     }
102
103     /**
104      * Fetch the members of a group
105      *
106      * @return array $profiles list of profiles 
107      */
108
109     function getProfiles()
110     {
111         $profiles = array();
112
113         $profile = $this->group->getMembers(
114             ($this->page - 1) * $this->count,
115             $this->count, 
116             $this->since_id, 
117             $this->max_id, 
118             $this->since
119         );
120
121         while ($profile->fetch()) {
122             $profiles[] = clone($profile);
123         }
124
125         return $profiles;
126     }
127
128     /**
129      * Is this action read only?
130      *
131      * @param array $args other arguments
132      *
133      * @return boolean true
134      */
135
136     function isReadOnly($args)
137     {
138         return true;
139     }
140
141     /**
142      * When was this list of profiles last modified?
143      *
144      * @return string datestamp of the lastest profile in the group
145      */
146
147     function lastModified()
148     {
149         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
150             return strtotime($this->profiles[0]->created);
151         }
152
153         return null;
154     }
155
156     /**
157      * An entity tag for this list of groups
158      *
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
162      *
163      * @return string etag
164      */
165
166     function etag()
167     {
168         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
169
170             $last = count($this->profiles) - 1;
171
172             return '"' . implode(
173                 ':',
174                 array($this->arg('action'),
175                       common_language(),
176                       $this->group->id,
177                       strtotime($this->profiles[0]->created),
178                       strtotime($this->profiles[$last]->created))
179             )
180             . '"';
181         }
182
183         return null;
184     }
185
186 }