SettingsController::bans PHP 메소드

bans() 공개 메소드

Manage user bans (add, edit, delete, list).
부터: 2.0.18
public bans ( string $Action = '', string $Search = '', integer $Page = '', integer $ID = '' )
$Action string Add, edit, delete, or none.
$Search string Term to filter ban list by.
$Page integer Page number.
$ID integer Ban ID we're editing or deleting.
    public function bans($Action = '', $Search = '', $Page = '', $ID = '')
    {
        $this->permission('Garden.Settings.Manage');
        // Page setup
        $this->title(t('Banning Options'));
        list($Offset, $Limit) = offsetLimit($Page, 20);
        $BanModel = $this->getBanModel();
        switch (strtolower($Action)) {
            case 'add':
            case 'edit':
                $this->Form->setModel($BanModel);
                if ($this->Form->authenticatedPostBack()) {
                    if ($ID) {
                        $this->Form->setFormValue('BanID', $ID);
                    }
                    // Trim the ban value to avoid obvious mismatches.
                    $banValue = trim($this->Form->getFormValue('BanValue'));
                    $this->Form->setFormValue('BanValue', $banValue);
                    // We won't let you HAL 9000 the entire crew.
                    $crazyBans = ['*', '*@*', '*.*', '*.*.*', '*.*.*.*'];
                    if (in_array($banValue, $crazyBans)) {
                        $this->Form->addError("I'm sorry Dave, I'm afraid I can't do that.");
                    }
                    try {
                        // Save the ban.
                        $NewID = $this->Form->save();
                    } catch (Exception $Ex) {
                        $this->Form->addError($Ex);
                    }
                } else {
                    if ($ID) {
                        $this->Form->setData($BanModel->getID($ID));
                    }
                }
                $this->setData('_BanTypes', array('IPAddress' => t('IP Address'), 'Email' => t('Email'), 'Name' => t('Name')));
                $this->View = 'Ban';
                break;
            case 'delete':
                if ($this->Form->authenticatedPostBack()) {
                    $BanModel->delete(array('BanID' => $ID));
                    $this->View = 'BanDelete';
                }
                break;
            default:
                $Bans = $BanModel->getWhere(array(), 'BanType, BanValue', 'asc', $Limit, $Offset)->resultArray();
                $this->setData('Bans', $Bans);
                break;
        }
        Gdn_Theme::section('Moderation');
        $this->render();
    }