Backend\Modules\Users\Actions\Edit::loadForm PHP Метод

loadForm() приватный Метод

Load the form
private loadForm ( )
    private function loadForm()
    {
        // create user objects
        $this->user = new BackendUser($this->id);
        $this->allowUserRights = BackendAuthentication::isAllowedAction('Add') || $this->authenticatedUser->getUserId() != $this->id || $this->authenticatedUser->isGod();
        // redirect to error page when not allowed to edit other profiles
        if (!$this->authenticatedUser->isGod() && ($this->authenticatedUser->getUserId() != $this->id && !BackendAuthentication::isAllowedAction('Add'))) {
            $this->redirect(BackendModel::createURLForAction('Error') . '&type=not-allowed');
        }
        // create form
        $this->frm = new BackendForm('edit');
        // get active groups
        $groups = BackendGroupsModel::getGroupsByUser($this->id);
        // loop through groups and set checked
        foreach ($groups as $group) {
            $checkedGroups[] = $group['id'];
        }
        // create elements
        // profile
        $this->frm->addText('email', $this->record['email'], 255)->setAttribute('type', 'email');
        if ($this->user->isGod()) {
            $this->frm->getField('email')->setAttributes(array('disabled' => 'disabled'));
        }
        $this->frm->addText('name', $this->record['settings']['name'], 255);
        $this->frm->addText('surname', $this->record['settings']['surname'], 255);
        $this->frm->addText('nickname', $this->record['settings']['nickname'], 24);
        $this->frm->addImage('avatar');
        // password
        // check if we're god or same user
        if ($this->authenticatedUser->getUserId() == $this->id || $this->authenticatedUser->isGod()) {
            // allow to set new password
            $this->frm->addPassword('new_password', null, 75);
            $this->frm->addPassword('confirm_password', null, 75);
            // disable autocomplete
            $this->frm->getField('new_password')->setAttributes(array('autocomplete' => 'off'));
            $this->frm->getField('confirm_password')->setAttributes(array('autocomplete' => 'off'));
        }
        // settings
        $this->frm->addDropdown('interface_language', BL::getInterfaceLanguages(), $this->record['settings']['interface_language']);
        $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), $this->user->getSetting('date_format'));
        $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), $this->user->getSetting('time_format'));
        $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), $this->user->getSetting('number_format', 'dot_nothing'));
        $this->frm->addDropdown('csv_split_character', BackendUsersModel::getCSVSplitCharacters(), $this->user->getSetting('csv_split_character'));
        $this->frm->addDropdown('csv_line_ending', BackendUsersModel::getCSVLineEndings(), $this->user->getSetting('csv_line_ending'));
        // permissions
        $this->frm->addCheckbox('active', $this->record['active'] == 'Y');
        // only when GOD or when you can edit other users
        if ($this->allowUserRights) {
            // disable active field for current users
            if ($this->authenticatedUser->getUserId() == $this->record['id']) {
                $this->frm->getField('active')->setAttribute('disabled', 'disabled');
            }
            // @TODO remove this when the api is kicked out
            $this->frm->addCheckbox('api_access', isset($this->record['settings']['api_access']) && $this->record['settings']['api_access'] == 'Y');
            $this->frm->addMultiCheckbox('groups', BackendGroupsModel::getAll(), $checkedGroups);
        }
    }