UserModel::ban PHP Méthode

ban() public méthode

Manually ban a user.
public ban ( integer $UserID, array $Options )
$UserID integer The ID of the user to ban.
$Options array Additional options for the ban.
    public function ban($UserID, $Options)
    {
        $User = $this->getID($UserID);
        $Banned = val('Banned', $User, 0);
        $this->setField($UserID, 'Banned', BanModel::setBanned($Banned, true, BanModel::BAN_MANUAL));
        $LogID = false;
        if (val('DeleteContent', $Options)) {
            $Options['Log'] = 'Ban';
            $LogID = $this->deleteContent($UserID, $Options);
        }
        if ($LogID) {
            $this->saveAttribute($UserID, 'BanLogID', $LogID);
        }
        $this->EventArguments['UserID'] = $UserID;
        $this->EventArguments['Options'] = $Options;
        $this->fireEvent('Ban');
        if (val('AddActivity', $Options, true)) {
            switch (val('Reason', $Options, '')) {
                case '':
                    $Story = null;
                    break;
                case 'Spam':
                    $Story = t('Banned for spamming.');
                    break;
                case 'Abuse':
                    $Story = t('Banned for being abusive.');
                    break;
                default:
                    $Story = $Options['Reason'];
                    break;
            }
            $Activity = ['ActivityType' => 'Ban', 'NotifyUserID' => ActivityModel::NOTIFY_MODS, 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::session()->UserID, 'HeadlineFormat' => t('HeadlineFormat.Ban', '{RegardingUserID,You} banned {ActivityUserID,you}.'), 'Story' => $Story, 'Data' => ['LogID' => $LogID]];
            $ActivityModel = new ActivityModel();
            $ActivityModel->save($Activity);
        }
    }

Usage Example

Exemple #1
0
 function ban($user_id, $action_by, $warning_id, $banned_till)
 {
     $this->clear();
     $this->user_id = (int) $user_id;
     $this->action_by = (int) $action_by;
     $this->warning_id = (int) $warning_id;
     $this->banned_till = $banned_till;
     $this->action_date = date("Y-m-d H:i:s");
     $this->type = self::BANNED;
     $this->save();
     $user_model = new UserModel();
     $user_model->ban($user_id);
 }
UserModel