Perforce Chronicle 2012.2/486814
API Documentation

User_Form_AddRole Class Reference

This is the add user form. More...

Inheritance diagram for User_Form_AddRole:
P4Cms_Form User_Form_EditRole

List of all members.

Public Member Functions

 init ()
 Defines the elements that make up the role form.
 isValid ($data)
 Override isValid to ensure given role does not already exist.

Public Attributes

const E_ROLE_ADMINISTRATOR_EMPTY = "The administrator role must have at least one user."
const E_ROLE_EXISTS = "Role '%s' already exists."

Protected Attributes

 $_uniqueIdRequired = true

Detailed Description

This is the add user form.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

User_Form_AddRole::init ( )

Defines the elements that make up the role form.

Called automatically when the form object is created.

Reimplemented in User_Form_EditRole.

    {
        // form should use p4cms-ui styles.
        $this->setAttrib('class', 'p4cms-ui role-form role-add-form');

        // set the method for the form to POST
        $this->setMethod('post');

        // add a field to collect the role name.
        $this->addElement(
            'text',
            'id',
            array(
                'label'         => 'Name',
                'required'      => true,
                'filters'       => array('StringTrim'),
                'validators'    => array('GroupName'),
                'size'          => 30,
                'order'         => 10
            )
        );

        // add a field to collect users to assign this role to (doesn't include system user).
        $users = P4Cms_User::fetchAll()->invoke('getId');

        $options = count($users) ? array_combine($users, $users) : array();
        $this->addElement(
            'MultiCheckbox',
            'users',
            array(
                'multiOptions'  => $options,
                'label'         => 'Users',
                'order'         => 20
            )
        );

        // add the submit button
        $this->addElement(
            'SubmitButton',
            'save',
            array(
                'label'     => 'Save',
                'class'     => 'preferred',
                'required'  => false,
                'ignore'    => true
            )
        );

        // put the button in a fieldset.
        $this->addDisplayGroup(
            array('save'),
            'buttons',
            array(
                'class' => 'buttons',
                'order' => 100
            )
        );

    }
User_Form_AddRole::isValid ( data)

Override isValid to ensure given role does not already exist.

Parameters:
array$datathe field values to validate.
Returns:
boolean true if the form values are valid.

Reimplemented from P4Cms_Form.

    {
        $valid = parent::isValid($data);

        if ($this->_uniqueIdRequired && isset($data['id'])) {
            if (P4Cms_Acl_Role::exists(($data['id']))) {
                $this->getElement('id')->addError(
                    sprintf(self::E_ROLE_EXISTS, $data['id'])
                );
                $valid = false;
            }
        }

        // administrator role must have at least one user
        if (isset($data['id'])
             && $data['id'] === P4Cms_Acl_Role::ROLE_ADMINISTRATOR
             && (!isset($data['users']) || empty($data['users']))
        ) {
            $this->getElement('users')->addError(self::E_ROLE_ADMINISTRATOR_EMPTY);
            $valid = false;
        }

        return $valid;
    }

Member Data Documentation

User_Form_AddRole::$_uniqueIdRequired = true [protected]

Reimplemented in User_Form_EditRole.

const User_Form_AddRole::E_ROLE_ADMINISTRATOR_EMPTY = "The administrator role must have at least one user."
const User_Form_AddRole::E_ROLE_EXISTS = "Role '%s' already exists."

The documentation for this class was generated from the following file: