Ejemplo n.º 1
0
 /**
  * Fields config for backend.
  *
  * @access     public
  * @return     MConfig
  * @since      1.0.0
  * @version    2.1.0-dev
  */
 protected static function generateConfig()
 {
     # get all permissions list
     $aRoles = [];
     $aResult = DB::queryList('\\Model\\User\\Role')->execute();
     foreach ($aResult as $oRole) {
         /* @var $oRole User\Role */
         $aRoles[] = ['value' => $oRole->getId(), 'label' => $oRole->getName()];
     }
     # get config from parent
     $config = parent::generateConfig();
     # create fields
     $config->addField(FormField\Hidden::singleton('id')->setLabel(__('ID'))->setDisabled());
     $config->addField(FormFieldPassword::singleton('password')->setLabel(__('Password'))->addRulesSet(RulesSetBuilder\String::factory()->containNumbers(':value')->containText(':value')->containUppercase(':value')->containCustomCharacters(':value')));
     $config->addField(FormField\Text::singleton('login')->setLabel('Login')->addTipParagraph(__('This value can contain only letters, numbers and "-" or "_" characters.'))->setDisabled()->addRulesSet(RulesSetBuilder\String::factory()->onlyLettersNumsAndChars(':value', '\\-_', __('This value can contain only letters, numbers and "-" or "_" characters.')))->addRulesSet(RulesSetBuilder\Database::factory()->unique(':value', ':valuefrom:id', '\\Model\\User', 'login')));
     $config->addField(FormField\Text::singleton('email')->setLabel('E-mail')->setDisabled()->addRulesSet(RulesSetBuilder\String::factory()->email(':value'))->addRulesSet(RulesSetBuilder\Database::factory()->unique(':value', ':valuefrom:id', '\\Model\\User', 'email')));
     $config->addField(FormField\Text::singleton('firstname')->setLabel(__('Firstname'))->addRulesSet(RulesSetBuilder\String::factory()->onlyLetters(':value')));
     $config->addField(FormField\Text::singleton('lastname')->setLabel(__('Lastname'))->addRulesSet(RulesSetBuilder\String::factory()->onlyLetters(':value')));
     $config->addField(FormField\Text::singleton('nickname')->setLabel(__('Nickname')));
     $config->addField(FormField\ImageModel::singleton('image')->setBrokerModel('\\Model\\User\\Image')->setUploadPath('uploads/users/image')->setLabel(__('Image'))->addRulesSet(RulesSetBuilder\FileModel::factory()->allowedExt(':value', ['jpg', 'png', 'gif'])->maxSize(':value', 1024)));
     $config->addField(FormField\Text::singleton('city')->setLabel(__('City'))->addRulesSet(RulesSetBuilder\String::factory()->onlyLetters(':value')));
     $config->addField(FormField\Textarea::singleton('description')->setLabel(__('Description')));
     if (\UserPermissions::hasPerm('users_edit')) {
         $config->addField(CheckboxRelationFormField::singleton('roles')->setRelatedModelName('\\Model\\User\\Role')->setOptions($aRoles)->setLabel(__('Roles')));
     }
     $config->addFieldFormatter('registration_date', FieldFormatterDate::factory());
     $config->addFieldFormatter('login_date', FieldFormatterDate::factory());
     # return config
     return $config;
 }
Ejemplo n.º 2
0
 /**
  * Set field as required (can't be empty).
  *
  * @access   public
  * @return   $this
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function setRequired()
 {
     $oRulesSet = Validator\RulesSetBuilder\FileModel::factory();
     /* @var $oRulesSet Validator\RulesSetBuilder\FileModel */
     $this->addRulesSet($oRulesSet->notEmpty(':value'));
     $this->bRequired = TRUE;
     if ($this->iQuantityMin === 0) {
         $this->setQuantityMin(1);
     }
     return $this;
 }