static function blockProfile($group, $profile, $blocker) { // Insert the block $block = new Group_block(); $block->query('BEGIN'); $block->group_id = $group->id; $block->blocked = $profile->id; $block->blocker = $blocker->id; $result = $block->insert(); if (!$result) { common_log_db_error($block, 'INSERT', __FILE__); return null; } // Delete membership if any $member = new Group_member(); $member->group_id = $group->id; $member->profile_id = $profile->id; if ($member->find(true)) { $result = $member->delete(); if (!$result) { common_log_db_error($member, 'DELETE', __FILE__); return null; } } // Commit, since both have been done $block->query('COMMIT'); return $block; }
/** * Handle the request * * Save the new message * * @param array $args $_REQUEST data (unused) * * @return void */ function handle($args) { parent::handle($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_('This method requires a POST.'), 400, $this->format); return; } if (empty($this->user)) { $this->clientError(_('No such user.'), 404, $this->format); return; } if (empty($this->group)) { $this->clientError(_('Group not found.'), 404, $this->format); return false; } $member = new Group_member(); $member->group_id = $this->group->id; $member->profile_id = $this->auth_user->id; if (!$member->find(true)) { $this->serverError(_('You are not a member of this group.')); return; } $result = $member->delete(); if (!$result) { common_log_db_error($member, 'DELETE', __FILE__); $this->serverError(sprintf(_('Could not remove user %1$s from group %2$s.'), $this->user->nickname, $this->group->nickname)); return; } 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, $this->format); break; } }
/** * Handle the request * * On POST, add the current user to the group * * @param array $args unused * * @return void */ function handle($args) { parent::handle($args); $cur = common_current_user(); $member = new Group_member(); $member->group_id = $this->group->id; $member->profile_id = $cur->id; if (!$member->find(true)) { $this->serverError(_('Could not find membership record.')); return; } $result = $member->delete(); if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); $this->serverError(sprintf(_('Could not remove user %s to group %s'), $cur->nickname, $this->group->nickname)); } if ($this->boolean('ajax')) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); $this->element('title', null, sprintf(_('%s left group %s'), $cur->nickname, $this->group->nickname)); $this->elementEnd('head'); $this->elementStart('body'); $jf = new JoinForm($this, $this->group); $jf->show(); $this->elementEnd('body'); $this->elementEnd('html'); } else { common_redirect(common_local_url('groupmembers', array('nickname' => $this->group->nickname))); } }