3 * StatusNet, the distributed open-source microblogging tool
5 * List/add/remove list 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 Shashi Gowda <connect2shashi@gmail.com>
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26 * @link http://status.net/
29 if (!defined('STATUSNET')) {
33 require_once INSTALLDIR . '/lib/apilistusers.php';
35 class ApiListMembersAction extends ApiListUsersAction
38 * Add a user to a list (tag someone)
40 * @return boolean success
44 if($this->auth_user->id != $this->list->tagger) {
45 // TRANS: Client error displayed when trying to add members to a list without having the right to do so.
46 $this->clientError(_('You are not allowed to add members to this list.'), 401);
49 if (!($this->target instanceof Profile)) {
50 // TRANS: Client error displayed when trying to modify list members without specifying them.
51 $this->clientError(_('You must specify a member.'));
54 $result = Profile_tag::setTag($this->auth_user->id,
55 $this->target->id, $this->list->tag);
58 // TRANS: Client error displayed when an unknown error occurs viewing list members.
59 $this->clientError(_('An error occured.'), 500);
62 switch($this->format) {
64 $this->showSingleXmlList($this->list);
67 $this->showSingleJsonList($this->list);
70 // TRANS: Client error displayed when coming across a non-supported API method.
71 $this->clientError(_('API method not found.'), 404);
76 * Remove a user from a list (untag someone)
78 * @return boolean success
80 function handleDelete()
82 if($this->auth_user->id != $this->list->tagger) {
83 // TRANS: Client error displayed when trying to remove members from a list without having the right to do so.
84 $this->clientError(_('You are not allowed to remove members from this list.'), 401);
87 if (!($this->target instanceof Profile)) {
88 // TRANS: Client error displayed when trying to modify list members without specifying them.
89 $this->clientError(_('You must specify a member.'));
92 $args = array('tagger' => $this->auth_user->id,
93 'tagged' => $this->target->id,
94 'tag' => $this->list->tag);
95 $ptag = Profile_tag::pkeyGet($args);
98 // TRANS: Client error displayed when trying to remove a list member that is not part of a list.
99 $this->clientError(_('The user you are trying to remove from the list is not a member.'));
102 if (!$ptag->delete()) {
103 // TRANS: Client error displayed when an unknown error occurs viewing list members.
104 $this->clientError(_('An error occured.'), 500);
107 switch($this->format) {
109 $this->showSingleXmlList($this->list);
112 $this->showSingleJsonList($this->list);
115 // TRANS: Client error displayed when coming across a non-supported API method.
116 $this->clientError(_('API method not found.'), 404);
123 * List the members of a list (people tagged)
127 $fn = array($this->list, 'getTagged');
128 list($this->users, $this->next_cursor, $this->prev_cursor) =
129 Profile_list::getAtCursor($fn, array(), $this->cursor, 20);