Esempio n. 1
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $config = $this->getOption('config');
     $mergeCustomFields = new Element\Checkbox('mergeCustomFields');
     $mergeCustomFields->setLabel('Merge user supplied information');
     $mergeCustomFields->setChecked($config->defaultMergeCustomFields);
     $this->add($mergeCustomFields);
     $mergeGroups = new Element\Checkbox('mergeGroups');
     $mergeGroups->setLabel('Merge manual group assignments');
     $mergeGroups->setChecked($config->defaultMergeGroups);
     $this->add($mergeGroups);
     $mergePackages = new Element\Checkbox('mergePackages');
     $mergePackages->setLabel('Merge missing package assignments');
     $mergePackages->setChecked($config->defaultMergePackages);
     $this->add($mergePackages);
     $submit = new \Library\Form\Element\Submit('submit');
     $submit->setLabel('Merge selected clients');
     $this->add($submit);
     // Checkboxes for "clients[]" are generated manually, without
     // \Zend\Form\Element. Define an input filter to have them processed.
     $arrayCount = new \Zend\Validator\Callback();
     $arrayCount->setCallback(array($this, 'validateArrayCount'))->setMessage('At least 2 different clients have to be selected', \Zend\Validator\Callback::INVALID_VALUE);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'clients', 'required' => true, 'continue_if_empty' => true, 'filters' => array(array($this, 'clientsFilter')), 'validators' => array($arrayCount, new \Zend\Validator\Explode(array('validator' => new \Zend\Validator\Digits()))), 'error_message' => $arrayCount->getDefaultTranslator()->translate($arrayCount->getMessageTemplates()[\Zend\Validator\Callback::INVALID_VALUE])));
     $this->setInputFilter($inputFilter);
 }
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $types = new \Zend\Form\Fieldset('Types');
     $this->add($types);
     $inputFilterTypes = new \Zend\InputFilter\InputFilter();
     $this->_definedTypes = $this->getOption('DeviceManager')->getTypeCounts();
     foreach ($this->_definedTypes as $name => $count) {
         $element = new \Zend\Form\Element\Text($name);
         $element->setValue($name);
         $types->add($element);
         $callback = new \Zend\Validator\Callback();
         $callback->setCallback(array($this, 'validateName'))->setCallbackOptions($name)->setTranslatorTextDomain('default')->setMessage('The name already exists');
         $filter = array('name' => $name, 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 1, 'max' => 255)), $callback));
         $inputFilterTypes->add($filter);
     }
     $add = new \Zend\Form\Element\Text('Add');
     $add->setLabel('Add');
     $this->add($add);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('Change');
     $this->add($submit);
     $callback = new \Zend\Validator\Callback();
     $callback->setCallback(array($this, 'validateName'))->setTranslatorTextDomain('default')->setMessage('The name already exists');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add($inputFilterTypes, 'Types');
     $inputFilter->add(array('name' => 'Add', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), $callback)));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 3
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $what = new \Zend\Form\Element\Radio('What');
     $what->setValueOptions(array(\Model\Client\Client::MEMBERSHIP_AUTOMATIC => $this->_('Store search parameters. Group memberships will be updated automatically.'), \Model\Client\Client::MEMBERSHIP_ALWAYS => $this->_('Add current search results. Group memberships will be set only this time.'), \Model\Client\Client::MEMBERSHIP_NEVER => $this->_('Exclude search results from a group.')));
     $what->setValue(\Model\Client\Client::MEMBERSHIP_AUTOMATIC);
     $this->add($what);
     $where = new \Zend\Form\Element\Radio('Where');
     $where->setValueOptions(array('new' => $this->_('Store in new group'), 'existing' => $this->_('Store in existing group')));
     $where->setValue('new')->setAttribute('onchange', 'selectElements()');
     $this->add($where);
     $newGroup = new \Zend\Form\Element\Text('NewGroup');
     $newGroup->setLabel('Name');
     $this->add($newGroup);
     $description = new \Zend\Form\Element\Text('Description');
     $description->setLabel('Description');
     $this->add($description);
     $existingGroup = new \Library\Form\Element\SelectSimple('ExistingGroup');
     $existingGroup->setLabel('Group');
     $groups = array();
     foreach ($this->getOption('GroupManager')->getGroups(null, null, 'Name') as $group) {
         $groups[] = $group['Name'];
     }
     $existingGroup->setValueOptions($groups);
     $this->add($existingGroup);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $lengthValidator = new \Zend\Validator\Callback();
     $lengthValidator->setCallback(array($this, 'validateLength'))->setCallbackOptions(array(0, 255))->setTranslatorTextDomain('default')->setMessage('The input is more than 255 characters long');
     $requiredValidator = new \Zend\Validator\Callback();
     $requiredValidator->setCallback(array($this, 'validateLength'))->setCallbackOptions(array(1, 255))->setTranslatorTextDomain('default')->setMessage("Value is required and can't be empty");
     $existsValidator = new \Zend\Validator\Callback();
     $existsValidator->setCallback(array($this, 'validateGroupExists'))->setTranslatorTextDomain('default')->setMessage('The name already exists');
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attach($lengthValidator, true)->attach($requiredValidator, true)->attach($existsValidator, true);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'NewGroup', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array($validatorChain)));
     $lengthValidator = new \Zend\Validator\Callback();
     $lengthValidator->setCallback(array($this, 'validateLength'))->setCallbackOptions(array(0, 255))->setTranslatorTextDomain('default')->setMessage('The input is more than 255 characters long');
     $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null', 'options' => array('type' => 'string'))), 'validators' => array($lengthValidator)));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 4
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $translatedTypes = array('text' => $this->_('Text'), 'clob' => $this->_('Long text'), 'integer' => $this->_('Integer'), 'float' => $this->_('Float'), 'date' => $this->_('Date'));
     $fields = new \Zend\Form\Fieldset('Fields');
     $this->add($fields);
     $inputFilterFields = new \Zend\InputFilter\InputFilter();
     foreach ($this->getOption('CustomFieldManager')->getFields() as $name => $type) {
         if ($name == 'TAG') {
             // Static field, can not be edited
             continue;
         }
         $this->_definedFields[$name] = $translatedTypes[$type];
         $element = new \Zend\Form\Element\Text($name);
         $element->setValue($name);
         $fields->add($element);
         $callback = new \Zend\Validator\Callback();
         $callback->setCallback(array($this, 'validateName'))->setCallbackOptions($name)->setTranslatorTextDomain('default')->setMessage('The name already exists');
         $filter = array('name' => $name, 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 1, 'max' => 255)), $callback));
         $inputFilterFields->add($filter);
     }
     // Empty text field to create new field.
     $newName = new \Zend\Form\Element\Text('NewName');
     $newName->setLabel('Add');
     $this->add($newName);
     // Datatype of new field
     $newType = new \Zend\Form\Element\Select('NewType');
     $newType->setValueOptions($translatedTypes);
     $this->add($newType);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('Change');
     $this->add($submit);
     $callback = new \Zend\Validator\Callback();
     $callback->setCallback(array($this, 'validateName'))->setTranslatorTextDomain('default')->setMessage('The name already exists');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add($inputFilterFields, 'Fields');
     $inputFilter->add(array('name' => 'NewName', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), $callback)));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 5
0
 /**
  * Get input filter specification for an integer field
  *
  * @param string $name Field name
  * @param integer $min Allowed minimum value
  * @return array
  */
 protected function _getIntegerFilter($name, $min)
 {
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attachByName('Callback', array('callback' => array($this, 'validateInteger')), true);
     // Callback validators do not support message variables. For
     // translatable messages with a parameter, do translation and
     // substitution here and disable further translation.
     $message = "The input is not greater or equal than '%min%'";
     // Prevent extraction by xgettext
     $minValueValidator = new \Zend\Validator\Callback();
     $minValueValidator->setCallback(array($this, 'validateMinValue'))->setCallbackOptions($min)->setMessage(str_replace('%min%', $min, $minValueValidator->getTranslator()->translate($message)))->setTranslatorEnabled(false);
     $validatorChain->attach($minValueValidator);
     return array('name' => $name, 'required' => false, 'filters' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'filterInteger')))), 'validators' => $validatorChain);
 }
Esempio n. 6
0
 /**
  * Get input filter specification for an integer field
  *
  * @param string $name Field name
  * @param integer $min Allowed minimum value
  * @return array
  */
 protected function _getIntegerFilter($name, $min)
 {
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attachByName('Callback', array('callback' => array($this, 'validateInteger')), true);
     $minValueValidator = new \Zend\Validator\Callback();
     $minValueValidator->setCallback(array($this, 'validateMinValue'))->setCallbackOptions($min)->setMessage("The input is not greater or equal than '{$min}'");
     $validatorChain->attach($minValueValidator);
     return array('name' => $name, 'required' => false, 'filters' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'filterInteger')))), 'validators' => $validatorChain);
 }