|
Perforce Chronicle 2012.2/486814
API Documentation
|
This is the add user form. More...
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 | |
This is the add user form.
| 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.
| array | $data | the field values to validate. |
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;
}
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." |