123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiGroupLeaveAction extends ApiAuthAction
- {
- protected $needPost = true;
- var $group = null;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->group = $this->getTargetGroup($this->arg('id'));
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if (!$this->scoped instanceof Profile) {
-
- $this->clientError(_('No such user.'), 404);
- }
- if (!$this->group instanceof User_group) {
-
- $this->clientError(_('Group not found.'), 404);
- }
- $member = new Group_member();
- $member->group_id = $this->group->id;
- $member->profile_id = $this->scoped->id;
- if (!$member->find(true)) {
-
- $this->serverError(_('You are not a member of this group.'));
- }
- try {
- $this->user->leaveGroup($this->group);
- } catch (Exception $e) {
-
-
- $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'),
- $this->scoped->getNickname(), $this->group->nickname));
- }
- switch($this->format) {
- case 'xml':
- $this->showSingleXmlGroup($this->group);
- break;
- case 'json':
- $this->showSingleJsonGroup($this->group);
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
- }
|