/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } $user = common_current_user(); assert(!empty($user)); // checked above assert(!empty($this->profile)); // checked above if (User_flag_profile::exists($this->profile->id, $user->id)) { $this->clientError(_('Flag already exists.')); return false; } return true; }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } $user = common_current_user(); assert(!empty($user)); // checked above assert(!empty($this->profile)); // checked above if (User_flag_profile::exists($this->profile->id, $user->id)) { // TRANS: Client error when setting flag that has already been set for a profile. $this->clientError(_m('Flag already exists.')); return false; } return true; }
/** * Handle POST * * @return void */ function handlePost() { $user = common_current_user(); assert(!empty($user)); assert(!empty($this->profile)); // throws an exception on error if (User_flag_profile::exists($this->profile->id, $user->id)) { // We'll return to the profile page (or return the updated AJAX form) // showing the current state, so no harm done. } else { User_flag_profile::create($user->id, $this->profile->id); } if ($this->boolean('ajax')) { $this->ajaxResults(); } }
/** * Optionally flag profile when a block happens * * We optionally add a flag when a profile has been blocked * * @param User $user User doing the block * @param Profile $profile Profile being blocked * * @return boolean hook result */ function onEndBlockProfile($user, $profile) { if ($this->flagOnBlock && !User_flag_profile::exists($profile->id, $user->id)) { User_flag_profile::create($user->id, $profile->id); } return true; }