Esempio n. 1
0
 /** {@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);
         $filter = array('name' => $name, 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 1, 'max' => 255)), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateName'), 'callbackOptions' => $name, 'message' => $this->_('The name already exists')))));
         $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);
     $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)), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateName'), 'message' => $this->_('The name already exists'))))));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 2
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);
         $filter = array('name' => $name, 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 1, 'max' => 255)), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateName'), 'callbackOptions' => $name, 'message' => $this->_('The name already exists')))));
         $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);
     $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)), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateName'), 'message' => $this->_('The name already exists'))))));
     $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);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'NewGroup', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(1, 255), 'message' => "Value is required and can't be empty"), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateGroupExists'), 'message' => $this->_('The name already exists'))))));
     $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null', 'options' => array('type' => 'string'))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateLength'), 'callbackOptions' => array(0, 255), 'message' => $this->_('The input is more than 255 characters long'))))));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 4
0
 public static function getInputFilter()
 {
     //if(!$this->inputFilter){
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $factory = new \Zend\InputFilter\Factory();
     $inputFilter->add($factory->createInput(array('name' => 'title', 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim'), array('name' => 'HtmlEntities')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 5, 'max' => 100))))));
     $inputFilter->add($factory->createInput(array('name' => 'image', 'required' => true)));
     $inputFilter->add($factory->createInput(array('required' => false, 'name' => 'image-url', 'validators' => array(array('name' => 'Uri')))));
     return $inputFilter;
     //}
 }
Esempio n. 5
0
 public static function getInputFilter()
 {
     //if(!$this->inputFilter){
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $factory = new \Zend\InputFilter\Factory();
     $inputFilter->add($factory->createInput(array('name' => 'username', 'required' => true, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'HtmlEntities')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 3, 'max' => 70))))));
     $inputFilter->add($factory->createInput(array('name' => 'email', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'EmailAddress')))));
     $inputFilter->add($factory->createInput(array('required' => true, 'name' => 'password', 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 5, 'max' => 70))))));
     $inputFilter->add($factory->createInput(array('required' => true, 'name' => 'repassword', 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 5, 'max' => 70))))));
     return $inputFilter;
     //}
 }
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $scannersPerSubnet = new \Zend\Form\Element\Text('scannersPerSubnet');
     $scannersPerSubnet->setLabel('Number of scanning computers per subnet')->setAttribute('size', 5);
     $preferences->add($scannersPerSubnet);
     $inputFilter->add($this->_getIntegerFilter('scannersPerSubnet', -1));
     $scanSnmp = new \Zend\Form\Element\Checkbox('scanSnmp');
     $scanSnmp->setLabel('Use SNMP');
     $preferences->add($scanSnmp);
     $scannerMinDays = new \Zend\Form\Element\Text('scannerMinDays');
     $scannerMinDays->setLabel('Minimum days before a scanning computer is replaced')->setAttribute('size', 5);
     $preferences->add($scannerMinDays);
     $inputFilter->add($this->_getIntegerFilter('scannerMinDays', 0));
     $scannerMaxDays = new \Zend\Form\Element\Text('scannerMaxDays');
     $scannerMaxDays->setLabel('Maximum days before a scanning computer is replaced')->setAttribute('size', 5);
     $preferences->add($scannerMaxDays);
     $inputFilter->add($this->_getIntegerFilter('scannerMaxDays', 0));
     $scanArpDelay = new \Zend\Form\Element\Text('scanArpDelay');
     $scanArpDelay->setLabel('Delay (in milliseconds) between ARP requests')->setAttribute('size', 5);
     $preferences->add($scanArpDelay);
     $inputFilter->add($this->_getIntegerFilter('scanArpDelay', 9));
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Esempio n. 7
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);
 }
 public function getInputFilter()
 {
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $factory = new \Zend\InputFilter\Factory();
     $inputFilter->add($factory->createInput(array('name' => 'control_id', 'validators' => array('name' => '\\DoctrineModule\\Validator\\NoObjectExists', 'options' => array('object_repository' => this, 'fields' => array('control_id'))))));
     return $inputFilter;
 }
Esempio n. 9
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $this->_types = $this->getOption('customFieldManager')->getFields();
     $fields = new \Zend\Form\Fieldset('Fields');
     $inputFilterField = new \Zend\InputFilter\InputFilter();
     foreach ($this->_types as $name => $type) {
         if ($type == 'clob') {
             $element = new \Zend\Form\Element\Textarea($name);
         } else {
             $element = new \Zend\Form\Element\Text($name);
         }
         if ($name == 'TAG') {
             $element->setLabel('Category');
         } else {
             $element->setLabel($name);
         }
         $fields->add($element);
         $filter = array('name' => $name, 'required' => false, 'filters' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'filterField'), 'callback_params' => $type))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateField'), 'callbackOptions' => $type))));
         $inputFilterField->add($filter);
     }
     $this->add($fields);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('Change');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add($inputFilterField, 'Fields');
     $this->setInputFilter($inputFilter);
 }
Esempio n. 10
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $communicationServerUri = new \Zend\Form\Element\Text('communicationServerUri');
     $communicationServerUri->setLabel('Communication server URI');
     $preferences->add($communicationServerUri);
     $inputFilter->add(array('name' => 'communicationServerUri', 'validators' => array(array('name' => 'Uri', 'options' => array('uriHandler' => 'Zend\\Uri\\Http', 'allowRelative' => false)))));
     $lockValidity = new \Zend\Form\Element\Text('lockValidity');
     $lockValidity->setLabel('Maximum seconds to lock a computer')->setAttribute('size', 5);
     $preferences->add($lockValidity);
     $inputFilter->add($this->_getIntegerFilter('lockValidity'));
     $sessionValidity = new \Zend\Form\Element\Text('sessionValidity');
     $sessionValidity->setLabel('Maximum duration of an agent session in seconds')->setAttribute('size', 5);
     $preferences->add($sessionValidity);
     $inputFilter->add($this->_getIntegerFilter('sessionValidity'));
     $sessionCleanupInterval = new \Zend\Form\Element\Text('sessionCleanupInterval');
     $sessionCleanupInterval->setLabel('Interval in seconds to cleanup sessions')->setAttribute('size', 5);
     $preferences->add($sessionCleanupInterval);
     $inputFilter->add($this->_getIntegerFilter('sessionCleanupInterval'));
     $sessionRequired = new \Zend\Form\Element\Checkbox('sessionRequired');
     $sessionRequired->setLabel('Session required for inventory');
     $preferences->add($sessionRequired);
     $logLevel = new \Library\Form\Element\SelectSimple('logLevel');
     $logLevel->setLabel('Log level')->setValueOptions(array(0, 1, 2));
     $preferences->add($logLevel);
     $autoMergeDuplicates = new \Zend\Form\Element\Checkbox('autoMergeDuplicates');
     $autoMergeDuplicates->setLabel('Merge duplicates automatically (not recommended)');
     $preferences->add($autoMergeDuplicates);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Esempio n. 11
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $integerValidator = new \Zend\Validator\Callback(array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'));
     $contactInterval = new \Zend\Form\Element\Text('contactInterval');
     $contactInterval->setLabel('Agent contact interval (in hours)')->setAttribute('size', 5);
     $preferences->add($contactInterval);
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attach($integerValidator, true)->attachByName('GreaterThan', array('min' => 0));
     $inputFilter->add(array('name' => 'contactInterval', 'filters' => array($integerFilter), 'validators' => $validatorChain));
     $inventoryInterval = new \Zend\Form\Element\Text('inventoryInterval');
     $inventoryInterval->setLabel('Inventory interval (in days, 0 = always, -1 = never)')->setAttribute('size', 5);
     $preferences->add($inventoryInterval);
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attach($integerValidator, true)->attachByName('GreaterThan', array('min' => -2));
     $inputFilter->add(array('name' => 'inventoryInterval', 'filters' => array($integerFilter), 'validators' => $validatorChain));
     $agentWhitelistFile = new \Zend\Form\Element\Text('agentWhitelistFile');
     $agentWhitelistFile->setLabel('File with allowed non-OCS agents (FusionInventory etc.)');
     $preferences->add($agentWhitelistFile);
     $inputFilter->add(array('name' => 'agentWhitelistFile', 'required' => false, 'validators' => array(array('name' => 'Library\\Validator\\FileReadable'))));
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Esempio n. 12
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $inputFilter = new \Zend\InputFilter\InputFilter();
     // Create list of values as array because nested iteration does not work with ResultSet objects.
     $this->_definedValues = iterator_to_array($this->getOption('registryManager')->getValueDefinitions());
     // Subform for enabling/disabling registry inspection, in addition to
     // the same setting in preferences.
     $fieldsetInspect = new \Zend\Form\Fieldset('inspect');
     $inspect = new Element\Checkbox('inspect');
     $inspect->setLabel('Inspect registry')->setChecked($this->getOption('config')->inspectRegistry);
     $fieldsetInspect->add($inspect);
     $this->add($fieldsetInspect);
     // Subform for existing values
     $fieldsetExisting = new \Zend\Form\Fieldset('existing');
     $inputFilterExisting = new \Zend\InputFilter\InputFilter();
     // Create text elements for existing values to rename them
     foreach ($this->_definedValues as $value) {
         $name = $value['Name'];
         $elementName = "value_{$value['Id']}_name";
         $element = new Element\Text($elementName);
         $element->setValue($name)->setLabel($value['FullPath']);
         $inputFilterExisting->add(array('name' => $elementName, 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), $this->_createBlacklistValidator($name))));
         $fieldsetExisting->add($element);
     }
     $this->add($fieldsetExisting);
     $inputFilter->add($inputFilterExisting, 'existing');
     // Subform for new value
     $fieldsetNew = new \Zend\Form\Fieldset('new_value');
     $newName = new Element\Text('name');
     $newName->setLabel('Name');
     $fieldsetNew->add($newName);
     $newRootKey = new Element\Select('root_key');
     $newRootKey->setLabel('Root key')->setAttribute('type', 'select_untranslated')->setValueOptions(\Model\Registry\Value::rootKeys())->setValue(\Model\Registry\Value::HKEY_LOCAL_MACHINE);
     $fieldsetNew->add($newRootKey);
     // Additional validation in isValid()
     $newSubKeys = new Element\Text('subkeys');
     $newSubKeys->setLabel('Subkeys');
     $fieldsetNew->add($newSubKeys);
     $newValue = new Element\Text('value');
     $newValue->setLabel('Only this value (optional)');
     $fieldsetNew->add($newValue);
     $submit = new \Library\Form\Element\Submit('submit');
     $submit->setLabel('Change');
     $fieldsetNew->add($submit);
     $this->add($fieldsetNew);
     $inputFilterNew = new \Zend\InputFilter\InputFilter();
     $inputFilterNew->add(array('name' => 'name', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), $this->_createBlacklistValidator())));
     $inputFilterNew->add(array('name' => 'subkeys', 'continue_if_empty' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateEmptySubkeys'), 'message' => "Value is required and can't be empty")), array('name' => 'StringLength', 'options' => array('max' => 255)))));
     $inputFilterNew->add(array('name' => 'value', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)))));
     $inputFilter->add($inputFilterNew, 'new_value');
     $this->setInputFilter($inputFilter);
 }
Esempio n. 13
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $name = new \Zend\Form\Element\Text('Name');
     $name->setLabel('Name');
     $this->add($name);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'Name', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)))));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 14
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $key = new \Zend\Form\Element\Text('Key');
     $key->setLabel('Product key (if different)');
     $this->add($key);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'Key', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'StringToUpper')), 'validators' => array(array('name' => 'Library\\Validator\\ProductKey'))));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 15
0
 public function getFilter()
 {
     $filter = new \Zend\InputFilter\InputFilter();
     $filter->add(array('name' => 'firstname', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 2)))));
     $filter->add(array('name' => 'lastname', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 2)))));
     $filter->add(array('name' => 'street', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 2)))));
     $filter->add(array('name' => 'postal_code', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 4)))));
     $filter->add(array('name' => 'locality', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 2)))));
     $filter->add(array('name' => 'phone', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 2)))));
     $filter->add(array('name' => 'emailreal', 'required' => true, 'validators' => array(array('name' => 'email_address', 'options' => array('deep' => true, 'domain' => true, 'hostname' => '', 'mx' => true)))));
     return $filter;
 }
Esempio n. 16
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $file = new \Zend\Form\Element\File('File');
     $file->setLabel('File (*.ocs, *.xml)');
     $this->add($file);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('Import');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'File'));
     // Sufficient to force uploaded file
     $this->setInputFilter($inputFilter);
 }
Esempio n. 17
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $type = new \Library\Form\Element\SelectSimple('Type');
     $type->setLabel('Type')->setValueOptions($this->getOption('DeviceManager')->getTypes());
     $this->add($type);
     $description = new \Zend\Form\Element\Text('Description');
     $description->setLabel('Description');
     $this->add($description);
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'Description', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)))));
     $this->setInputFilter($inputFilter);
 }
Esempio n. 18
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $packageDeployment = new \Zend\Form\Element\Checkbox('packageDeployment');
     $packageDeployment->setLabel('Enable package download');
     $preferences->add($packageDeployment);
     $packagePath = new \Zend\Form\Element\Text('packagePath');
     $packagePath->setLabel('Package storage directory');
     $preferences->add($packagePath);
     $inputFilter->add(array('name' => 'packagePath', 'validators' => array(array('name' => 'Library\\Validator\\DirectoryWritable'))));
     $packageBaseUriHttp = new \Zend\Form\Element\Text('packageBaseUriHttp');
     $packageBaseUriHttp->setLabel('HTTP package base URL');
     $preferences->add($packageBaseUriHttp);
     $inputFilter->add(array('name' => 'packageBaseUriHttp', 'filters' => array(array('name' => 'StringTrim'), array('name' => 'PregReplace', 'options' => array('pattern' => '#(.*://|/$)#', 'replacement' => ''))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateUri'))))));
     $packageBaseUriHttps = new \Zend\Form\Element\Text('packageBaseUriHttps');
     $packageBaseUriHttps->setLabel('HTTPS package base URL');
     $preferences->add($packageBaseUriHttps);
     $inputFilter->add(array('name' => 'packageBaseUriHttps', 'filters' => array(array('name' => 'StringTrim'), array('name' => 'PregReplace', 'options' => array('pattern' => '#(.*://|/$)#', 'replacement' => ''))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateUri'))))));
     $downloadPeriodDelay = new \Zend\Form\Element\Text('downloadPeriodDelay');
     $downloadPeriodDelay->setLabel('Delay (in seconds) between periods')->setAttribute('size', 5);
     $preferences->add($downloadPeriodDelay);
     $inputFilter->add($this->_getIntegerFilter('downloadPeriodDelay'));
     $downloadCycleDelay = new \Zend\Form\Element\Text('downloadCycleDelay');
     $downloadCycleDelay->setLabel('Delay (in seconds) between cycles')->setAttribute('size', 5);
     $preferences->add($downloadCycleDelay);
     $inputFilter->add($this->_getIntegerFilter('downloadCycleDelay'));
     $downloadFragmentDelay = new \Zend\Form\Element\Text('downloadFragmentDelay');
     $downloadFragmentDelay->setLabel('Delay (in seconds) between fragments')->setAttribute('size', 5);
     $preferences->add($downloadFragmentDelay);
     $inputFilter->add($this->_getIntegerFilter('downloadFragmentDelay'));
     $downloadMaxPriority = new \Library\Form\Element\SelectSimple('downloadMaxPriority');
     $downloadMaxPriority->setLabel('Maximum package priority (packages with higher value will not be downloaded)')->setValueOptions(range(0, 10));
     $preferences->add($downloadMaxPriority);
     $downloadTimeout = new \Zend\Form\Element\Text('downloadTimeout');
     $downloadTimeout->setLabel('Timeout (in days)')->setAttribute('size', 5);
     $preferences->add($downloadTimeout);
     $inputFilter->add($this->_getIntegerFilter('downloadTimeout'));
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Esempio n. 19
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $trustedNetworksOnly = new \Zend\Form\Element\Checkbox('trustedNetworksOnly');
     $trustedNetworksOnly->setLabel('Limit agent connections to trusted networks');
     $preferences->add($trustedNetworksOnly);
     $inventoryFilter = new \Zend\Form\Element\Checkbox('inventoryFilter');
     $inventoryFilter->setLabel('Limit inventory frequency');
     $preferences->add($inventoryFilter);
     $limitInventoryInterval = new \Zend\Form\Element\Text('limitInventoryInterval');
     $limitInventoryInterval->setLabel('Seconds between inventory processing')->setAttribute('size', 5);
     $preferences->add($limitInventoryInterval);
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attachByName('Callback', array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'), true);
     $validatorChain->attachByName('GreaterThan', array('min' => 0));
     $inputFilter->add(array('name' => 'limitInventoryInterval', 'required' => false, 'filters' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'))), 'validators' => $validatorChain));
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Esempio n. 20
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $saveRawData = new \Zend\Form\Element\Checkbox('saveRawData');
     $saveRawData->setLabel('Save incoming raw inventory data');
     $preferences->add($saveRawData);
     $saveDir = new \Zend\Form\Element\Text('saveDir');
     $saveDir->setLabel('Target directory');
     $preferences->add($saveDir);
     $saveFormat = new \Zend\Form\Element\Select('saveFormat');
     $saveFormat->setLabel('File format')->setValueOptions(array('XML' => $this->_('uncompressed XML'), 'OCS' => $this->_('zlib compressed XML')));
     $preferences->add($saveFormat);
     $inputFilter->add(array('name' => 'saveDir', 'validators' => array(array('name' => 'Library\\Validator\\DirectoryWritable'))));
     $saveOverwrite = new \Zend\Form\Element\Checkbox('saveOverwrite');
     $saveOverwrite->setLabel('Overwrite existing files');
     $preferences->add($saveOverwrite);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Esempio n. 21
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $id = new Element\Text('Id');
     $id->setLabel('Login name');
     $this->add($id);
     $inputFilter->add(array('name' => 'Id', 'required' => true, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)))));
     $password = new Element\Password('Password');
     $password->setLabel('Password');
     $this->add($password);
     $inputFilter->add(array('name' => 'Password', 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 8)))));
     $password2 = new Element\Password('PasswordRepeat');
     $password2->setLabel('Repeat password');
     $this->add($password2);
     $identicalValidator = new \Zend\Validator\Identical();
     $identicalValidator->setToken('Password');
     $identicalValidator->setTranslatorTextDomain('default')->setMessage('The passwords do not match');
     $inputFilter->add(array('name' => 'PasswordRepeat', 'continue_if_empty' => 'true', 'validators' => array($identicalValidator)));
     $firstName = new Element\Text('FirstName');
     $firstName->setLabel('First name');
     $this->add($firstName);
     $inputFilter->add(array('name' => 'FirstName', 'required' => false, 'allow_empty' => true, 'continue_if_empty' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null')), 'validators' => array(array('name' => 'Library\\Validator\\StringLength', 'options' => array('max' => 255)))));
     $lastName = new Element\Text('LastName');
     $lastName->setLabel('Last name');
     $this->add($lastName);
     $inputFilter->add(array('name' => 'LastName', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null')), 'validators' => array(array('name' => 'Library\\Validator\\StringLength', 'options' => array('max' => 255)))));
     $mailAddress = new Element\Text('MailAddress');
     $mailAddress->setLabel('Mail address');
     $this->add($mailAddress);
     $inputFilter->add(array('name' => 'MailAddress', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null')), 'validators' => array(array('name' => 'Library\\Validator\\StringLength', 'options' => array('max' => 255)), array('name' => 'EmailAddress', 'options' => array('allow' => \Zend\Validator\Hostname::ALLOW_ALL)))));
     $comment = new Element\Textarea('Comment');
     $comment->setLabel('Comment');
     $this->add($comment);
     $inputFilter->add(array('name' => 'Comment', 'required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Null'))));
     // Submit button text is set in subclass
     $submit = new \Library\Form\Element\Submit('Submit');
     $this->add($submit);
     $this->setInputFilter($inputFilter);
 }
Esempio n. 22
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $validatorChain = new \Zend\Validator\ValidatorChain();
     $validatorChain->attachByName('Callback', array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'), true);
     $validatorChain->attachByName('GreaterThan', array('min' => 0));
     $groupCacheExpirationInterval = new \Zend\Form\Element\Text('groupCacheExpirationInterval');
     $groupCacheExpirationInterval->setLabel('Minimum seconds between group cache rebuilds')->setAttribute('size', 5);
     $preferences->add($groupCacheExpirationInterval);
     $inputFilter->add(array('name' => 'groupCacheExpirationInterval', 'filters' => array($integerFilter), 'validators' => $validatorChain));
     $groupCacheExpirationFuzz = new \Zend\Form\Element\Text('groupCacheExpirationFuzz');
     $groupCacheExpirationFuzz->setLabel('Maximum seconds added to above value')->setAttribute('size', 5);
     $preferences->add($groupCacheExpirationFuzz);
     $inputFilter->add(array('name' => 'groupCacheExpirationFuzz', 'filters' => array($integerFilter), 'validators' => $validatorChain));
     $setGroupPackageStatus = new \Zend\Form\Element\Checkbox('setGroupPackageStatus');
     $setGroupPackageStatus->setLabel('Set package status on clients for group-assigned packages');
     $preferences->add($setGroupPackageStatus);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
Esempio n. 23
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $translator = $this->getOption('translator');
     $this->_filters = array('Name' => $translator->translate('Name'), 'UserName' => $translator->translate('User name'), 'Windows.UserDomain' => $translator->translate('User domain'), 'Windows.Workgroup' => $translator->translate('Workgroup'), 'OsName' => $translator->translate('OS name'), 'OsVersionNumber' => $translator->translate('OS version number'), 'OsVersionString' => $translator->translate('OS version string'), 'Windows.CpuArchitecture' => $translator->translate('OS architecture'), 'OsComment' => $translator->translate('OS comment'), 'Windows.ProductKey' => $translator->translate('Windows product key'), 'Windows.ManualProductKey' => $translator->translate('Windows product key (manual)'), 'Software.Name' => $translator->translate('Software: Name'), 'Software.Version' => $translator->translate('Software: Version'), 'Software.Publisher' => $translator->translate('Software: Publisher'), 'Software.Comment' => $translator->translate('Software: Comment'), 'Software.InstallLocation' => $translator->translate('Software: Install location'), 'MsOfficeProduct.ProductKey' => $translator->translate('MS Office product key'), 'MsOfficeProduct.ProductId' => $translator->translate('MS Office product ID'), 'InventoryDate' => $translator->translate('Last inventory'), 'LastContactDate' => $translator->translate('Last contact'), 'CpuType' => $translator->translate('CPU type'), 'CpuClock' => $translator->translate('CPU clock (MHz)'), 'CpuCores' => $translator->translate('CPU cores'), 'PhysicalMemory' => $translator->translate('Physical memory'), 'SwapMemory' => $translator->translate('Swap memory'), 'Manufacturer' => $translator->translate('Manufacturer'), 'ProductName' => $translator->translate('Model'), 'Serial' => $translator->translate('Serial number'), 'AssetTag' => $translator->translate('Asset tag'), 'BiosVersion' => $translator->translate('BIOS version'), 'BiosDate' => $translator->translate('BIOS date'), 'Filesystem.Size' => $translator->translate('Filesystem size (MB)'), 'Filesystem.FreeSpace' => $translator->translate('Filesystem free space (MB)'), 'DnsServer' => $translator->translate('DNS server'), 'DefaultGateway' => $translator->translate('Default gateway'), 'NetworkInterface.IpAddress' => $translator->translate('IP address'), 'NetworkInterface.MacAddress' => $translator->translate('MAC address'), 'NetworkInterface.Subnet' => $translator->translate('Network address'), 'NetworkInterface.Netmask' => $translator->translate('Network Mask'), 'Printer.Name' => $translator->translate('Printer name'), 'Printer.Port' => $translator->translate('Printer port'), 'Printer.Driver' => $translator->translate('Printer driver'), 'UserAgent' => $translator->translate('User agent'), 'Display.Manufacturer' => $translator->translate('Monitor: manufacturer'), 'Display.Description' => $translator->translate('Monitor: description'), 'Display.Serial' => $translator->translate('Monitor: serial'), 'Display.Edid' => $translator->translate('Monitor: EDID'), 'DisplayController.Name' => $translator->translate('Display controller'), 'DisplayController.Memory' => $translator->translate('GPU memory'), 'Modem.Name' => $translator->translate('Modem'), 'AudioDevice.Name' => $translator->translate('Audio device'), 'Port.Name' => $translator->translate('Port name'));
     // Append filters and labels for registry values/data
     foreach ($this->getOption('registryManager')->getValueDefinitions() as $regValue) {
         $name = $regValue['Name'];
         $this->_filters["Registry.{$name}"] = "Registry: {$name}";
     }
     // Append filters and labels for user defined info
     $template = $translator->translate('User defined: %s');
     foreach ($this->getOption('customFieldManager')->getFields() as $name => $type) {
         $key = "CustomFields.{$name}";
         switch ($type) {
             case 'text':
             case 'clob':
                 break;
             case 'integer':
             case 'float':
             case 'date':
                 $this->_types[$key] = $type;
                 break;
             default:
                 throw new \UnexpectedValueException('Unsupported datatype: ' . $type);
         }
         if ($name == 'TAG') {
             $label = $translator->translate('Category');
         } else {
             $label = $name;
         }
         $this->_filters[$key] = sprintf($template, $label);
     }
     $filter = new Element\Select('filter');
     $filter->setLabel('Search for')->setAttribute('type', 'select_untranslated')->setAttribute('onchange', 'filterChanged();')->setValueOptions($this->_filters);
     $this->add($filter);
     $search = new Element\Text('search');
     $search->setLabel('Value');
     $this->add($search);
     // Operators dropdown. Options are set by JS depending on filter type.
     // Since valid options are known only after submission, the internal
     // InArray validator must be disabled and replaced by a callback.
     $operator = new Element\Select('operator');
     $operator->setDisableInArrayValidator(true)->setLabel('Operator');
     $this->add($operator);
     $invert = new Element\Checkbox('invert');
     $invert->setLabel('Invert results');
     $this->add($invert);
     $submit = new \Library\Form\Element\Submit('customSearch');
     $submit->setLabel('Search');
     $this->add($submit);
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $inputFilter->add(array('name' => 'search', 'continue_if_empty' => true, 'filters' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'filterSearch')))), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateSearch'))))));
     $inputFilter->add(array('name' => 'operator', 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateOperator'))))));
     $this->setInputFilter($inputFilter);
     $this->_operatorsText = array('like' => $translator->translate("Substring match, wildcards '?' and '*' allowed"), 'eq' => $translator->translate('Exact match'));
 }
Esempio n. 24
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $preferences = $this->get('Preferences');
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $integerValidator = array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'));
     $deploy = new \Zend\Form\Fieldset('Deploy');
     $deploy->setLabel('Defaults for deploying updated packages');
     $deployNonnotified = new \Zend\Form\Element\Checkbox('defaultDeployNonnotified');
     $deployNonnotified->setLabel('Not notified');
     $deploy->add($deployNonnotified);
     $deploySuccess = new \Zend\Form\Element\Checkbox('defaultDeploySuccess');
     $deploySuccess->setLabel('Success');
     $deploy->add($deploySuccess);
     $deployNotified = new \Zend\Form\Element\Checkbox('defaultDeployNotified');
     $deployNotified->setLabel('Running');
     $deploy->add($deployNotified);
     $deployError = new \Zend\Form\Element\Checkbox('defaultDeployError');
     $deployError->setLabel('Error');
     $deploy->add($deployError);
     $deployGroups = new \Zend\Form\Element\Checkbox('defaultDeployGroups');
     $deployGroups->setLabel('Groups');
     $deploy->add($deployGroups);
     $preferences->add($deploy);
     $defaultPlatform = new \Zend\Form\Element\Select('defaultPlatform');
     $defaultPlatform->setLabel('Default platform')->setAttribute('type', 'select_untranslated')->setValueOptions(array('windows' => 'Windows', 'linux' => 'Linux', 'mac' => 'MacOS'));
     $preferences->add($defaultPlatform);
     $defaultAction = new \Zend\Form\Element\Select('defaultAction');
     $defaultAction->setLabel('Default action')->setValueOptions(array('launch' => $this->_('Download package, execute command, retrieve result'), 'execute' => $this->_('Optionally download package, execute command'), 'store' => $this->_('Just download package to target path')));
     $preferences->add($defaultAction);
     $defaultActionParam = new \Zend\Form\Element\Text('defaultActionParam');
     $defaultActionParam->setLabel('Default action parameter');
     $preferences->add($defaultActionParam);
     $defaultPackagePriority = new \Library\Form\Element\SelectSimple('defaultPackagePriority');
     $defaultPackagePriority->setValueOptions(range(0, 10))->setLabel('Default priority (0: exclusive, 10: lowest)');
     $preferences->add($defaultPackagePriority);
     $defaultMaxFragmentSize = new \Zend\Form\Element\Text('defaultMaxFragmentSize');
     $defaultMaxFragmentSize->setAttribute('size', '8')->setLabel('Default maximum fragment size (kB)');
     $preferences->add($defaultMaxFragmentSize);
     $inputFilter->add(array('name' => 'defaultMaxFragmentSize', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     $defaultWarn = new \Zend\Form\Element\Checkbox('defaultWarn');
     $defaultWarn->setLabel('Warn user by default');
     $preferences->add($defaultWarn);
     $defaultWarnMessage = new \Zend\Form\Element\Textarea('defaultWarnMessage');
     $defaultWarnMessage->setLabel('Default warn message');
     $preferences->add($defaultWarnMessage);
     $defaultWarnCountdown = new \Zend\Form\Element\Text('defaultWarnCountdown');
     $defaultWarnCountdown->setAttribute('size', '5')->setLabel('Default warn countdown (seconds)');
     $preferences->add($defaultWarnCountdown);
     $inputFilter->add(array('name' => 'defaultWarnCountdown', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     $defaultWarnAllowAbort = new \Zend\Form\Element\Checkbox('defaultWarnAllowAbort');
     $defaultWarnAllowAbort->setLabel('Allow user abort by default');
     $preferences->add($defaultWarnAllowAbort);
     $defaultWarnAllowDelay = new \Zend\Form\Element\Checkbox('defaultWarnAllowDelay');
     $defaultWarnAllowDelay->setLabel('Allow user delay by default');
     $preferences->add($defaultWarnAllowDelay);
     $defaultPostInstMessage = new \Zend\Form\Element\Textarea('defaultPostInstMessage');
     $defaultPostInstMessage->setLabel('Default post-installation message');
     $preferences->add($defaultPostInstMessage);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $parentFilter->add($inputFilter, 'Preferences');
     $this->setInputFilter($parentFilter);
 }
 public function testConstructFormForUserProcessesAllRegisteredExtensionsOnSave()
 {
     $mockUser = \Mockery::mock('ZfcUser\\Entity\\UserInterface');
     // Extension A
     $mockUserDataOne = new \stdClass();
     $mockUserDataOne->testOne = 'hi1';
     $mockFieldsetOne = \Mockery::mock('Zend\\Form\\Fieldset[getName,setName]');
     $mockFieldsetOne->shouldReceive('getName')->andReturn('extone');
     $mockFieldsetOne->shouldReceive('setName')->withArgs(array('extone'));
     $mockFieldsetOne->add(new Text('testOne'));
     $mockFieldsetOne->setHydrator(new ObjectProperty());
     $mockFieldsetOne->setObject(new \stdClass());
     $mockInputFilterOne = new \Zend\InputFilter\InputFilter();
     $mockInputFilterOne->add(new \Zend\InputFilter\Input('testOne'));
     $extOne = \Mockery::mock('LdcUserProfile\\Extensions\\AbstractExtension');
     $extOne->shouldReceive('getName')->andReturn('extone');
     $extOne->shouldReceive('getFieldset')->andReturn($mockFieldsetOne);
     $extOne->shouldReceive('getInputFilter')->andReturn($mockInputFilterOne);
     $extOne->shouldReceive('getObjectForUser')->withArgs(array($mockUser))->andReturn($mockUserDataOne);
     $extOne->shouldReceive('getFieldsetValidationGroup')->andReturn(null);
     $extOne->shouldReceive('save')->once()->andReturn(false);
     $this->service->registerExtension($extOne);
     // Extension B
     $mockUserDataTwo = new \stdClass();
     $mockUserDataTwo->testTwo = 'hi2';
     $mockFieldsetTwo = \Mockery::mock('Zend\\Form\\Fieldset[getName,setName]');
     $mockFieldsetTwo->shouldReceive('getName')->andReturn('exttwo');
     $mockFieldsetTwo->shouldReceive('setName')->withArgs(array('exttwo'));
     $mockFieldsetTwo->add(new Text('testTwo'));
     $mockFieldsetTwo->setHydrator(new ObjectProperty());
     $mockFieldsetTwo->setObject(new \stdClass());
     $mockInputFilterTwo = new \Zend\InputFilter\InputFilter();
     $mockInputFilterTwo->add(new \Zend\InputFilter\Input('testTwo'));
     $extTwo = \Mockery::mock('LdcUserProfile\\Extensions\\AbstractExtension');
     $extTwo->shouldReceive('getName')->andReturn('exttwo');
     $extTwo->shouldReceive('getFieldset')->andReturn($mockFieldsetTwo);
     $extTwo->shouldReceive('getInputFilter')->andReturn($mockInputFilterTwo);
     $extTwo->shouldReceive('getObjectForUser')->withArgs(array($mockUser))->andReturn($mockUserDataTwo);
     $extTwo->shouldReceive('getFieldsetValidationGroup')->andReturn(null);
     $extTwo->shouldReceive('save')->once()->andReturn(true);
     $this->service->registerExtension($extTwo);
     $form = $this->service->constructFormForUser($mockUser);
     $this->assertInstanceOf('Zend\\Form\\FormInterface', $form);
     $this->assertTrue($form->has('extone'));
     $this->assertTrue($form->get('extone')->has('testOne'));
     $this->assertEquals('hi1', $form->get('extone')->get('testOne')->getValue());
     $this->assertTrue($form->getInputFilter()->has('extone'));
     $this->assertTrue($form->getInputFilter()->get('extone')->has('testOne'));
     $this->assertTrue($form->has('exttwo'));
     $this->assertTrue($form->get('exttwo')->has('testTwo'));
     $this->assertEquals('hi2', $form->get('exttwo')->get('testTwo')->getValue());
     $this->assertTrue($form->getInputFilter()->has('exttwo'));
     $this->assertTrue($form->getInputFilter()->get('exttwo')->has('testTwo'));
     $form->setData(array('extone' => array('testOne' => 'zzzz'), 'exttwo' => array('testTwo' => '42')));
     $this->assertTrue($form->isValid());
     $entity = $form->getData();
     $this->assertInstanceOf('stdClass', $entity);
     $this->assertObjectHasAttribute('extone', $entity);
     $this->assertObjectHasAttribute('testOne', $entity->extone);
     $this->assertEquals('zzzz', $entity->extone->testOne);
     $this->assertObjectHasAttribute('exttwo', $entity);
     $this->assertObjectHasAttribute('testTwo', $entity->exttwo);
     $this->assertEquals('42', $entity->exttwo->testTwo);
     $this->assertFalse($this->service->save($entity));
 }
Esempio n. 26
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $inputFilter = new \Zend\InputFilter\InputFilter();
     $integerFilter = array('name' => 'Callback', 'options' => array('callback' => array($this, 'normalize'), 'callback_params' => 'integer'));
     $integerValidator = array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateType'), 'callbackOptions' => 'integer'));
     // Package name
     $name = new Element\Text('Name');
     $name->setLabel('Name');
     $this->add($name);
     $inputFilter->add(array('name' => 'Name', 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('max' => 255)), array('name' => 'Library\\Validator\\NotInArray', 'options' => array('haystack' => $this->getOption('packageManager')->getAllNames(), 'caseSensitivity' => \Library\Validator\NotInArray::CASE_INSENSITIVE)))));
     // Comment
     $comment = new Element\Textarea('Comment');
     $comment->setLabel('Comment');
     $this->add($comment);
     $inputFilter->add(array('name' => 'Comment', 'required' => false, 'filters' => array(array('name' => 'StringTrim'))));
     // Platform combobox
     $platform = new Element\Select('Platform');
     $platform->setLabel('Platform')->setAttribute('type', 'select_untranslated')->setAttribute('id', 'form_package_build_platform')->setAttribute('onchange', 'changePlatform()')->setValueOptions(array('windows' => 'Windows', 'linux' => 'Linux', 'mac' => 'MacOS'));
     $this->add($platform);
     // Action combobox
     // Translate labels manually to let xgettext recognize them
     $action = new Element\Select('DeployAction');
     $action->setLabel('Action')->setAttribute('onchange', 'changeParam()')->setValueOptions(array('launch' => $this->_('Download package, execute command, retrieve result'), 'execute' => $this->_('Optionally download package, execute command'), 'store' => $this->_('Just download package to target path')));
     $this->add($action);
     // Command line or target path for action
     // Label is set by JavaScript code.
     $actionParam = new Element\Text('ActionParam');
     $this->add($actionParam);
     $inputFilter->add(array('name' => 'ActionParam', 'required' => true));
     // Upload file
     $file = new Element\File('File');
     $file->setLabel('File');
     $this->add($file);
     $inputFilter->add(array('name' => 'File'));
     // Requirement is set in isValid()
     // Priority combobox
     $priority = new \Library\Form\Element\SelectSimple('Priority');
     $priority->setValueOptions(range(0, 10))->setLabel('Priority (0: exclusive, 10: lowest)');
     $this->add($priority);
     // Maximum fragment size.
     $maxFragmentSize = new Element\Text('MaxFragmentSize');
     $maxFragmentSize->setAttribute('size', '8')->setLabel('Maximum fragment size (kB)');
     $this->add($maxFragmentSize);
     $inputFilter->add(array('name' => 'MaxFragmentSize', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     // Warn user before installation
     $warn = new Element\Checkbox('Warn');
     $warn->setLabel('Warn user')->setAttribute('id', 'form_package_build_warn')->setAttribute('onchange', 'toggleWarn()');
     $this->add($warn);
     // Message to display to user before installation
     $warnMessage = new Element\Textarea('WarnMessage');
     $warnMessage->setLabel('Message');
     $this->add($warnMessage);
     $inputFilter->add(array('name' => 'WarnMessage', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateNotificationMessage'), 'message' => $this->_('Message must not contain double quotes.'))))));
     // Countdown before installation starts automatically
     $warnCountdown = new Element\Text('WarnCountdown');
     $warnCountdown->setAttribute('size', '5')->setLabel('Countdown (seconds)');
     $this->add($warnCountdown);
     $inputFilter->add(array('name' => 'WarnCountdown', 'required' => false, 'filters' => array($integerFilter), 'validators' => array($integerValidator)));
     // Allow user abort
     $warnAllowAbort = new Element\Checkbox('WarnAllowAbort');
     $warnAllowAbort->setLabel('Allow abort by user');
     $this->add($warnAllowAbort);
     // Allow user delay
     $warnAllowDelay = new Element\Checkbox('WarnAllowDelay');
     $warnAllowDelay->setLabel('Allow delay by user');
     $this->add($warnAllowDelay);
     // Message to display to user after deployment
     $postInstMessage = new Element\Textarea('PostInstMessage');
     $postInstMessage->setLabel('Post-installation message');
     $this->add($postInstMessage);
     $inputFilter->add(array('name' => 'PostInstMessage', 'required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Callback', 'options' => array('callback' => array($this, 'validateNotificationMessage'), 'message' => $this->_('Message must not contain double quotes.'))))));
     // Submit button
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('Build');
     $this->add($submit);
     $this->setInputFilter($inputFilter);
 }
Esempio n. 27
0
 /** {@inheritdoc} */
 public function init()
 {
     parent::init();
     $inputFilter = new \Zend\InputFilter\InputFilter();
     // Agent options
     $agent = new \Zend\Form\Fieldset('Agent');
     $inputFilterAgent = new \Zend\InputFilter\InputFilter();
     $contactInterval = new Element\Text('contactInterval');
     $contactInterval->setLabel('Agent contact interval (in hours)')->setAttribute('size', '5');
     $agent->add($contactInterval);
     $inputFilterAgent->add($this->_getIntegerFilter('contactInterval', 1));
     $inventoryInterval = new Element\Text('inventoryInterval');
     $inventoryInterval->setLabel('Inventory interval (in days, 0 = always, -1 = never)')->setAttribute('size', '5');
     $agent->add($inventoryInterval);
     $inputFilterAgent->add($this->_getIntegerFilter('inventoryInterval', -1));
     $this->add($agent);
     $inputFilter->add($inputFilterAgent, 'Agent');
     // Download options
     $download = new \Zend\Form\Fieldset('Download');
     $inputFilterDownload = new \Zend\InputFilter\InputFilter();
     $packageDeployment = new Element\Checkbox('packageDeployment');
     $packageDeployment->setLabel('Enable package download')->setAttribute('onchange', 'toggle(this)');
     $download->add($packageDeployment);
     $downloadPeriodDelay = new Element\Text('downloadPeriodDelay');
     $downloadPeriodDelay->setLabel('Delay (in seconds) between periods')->setAttribute('size', '5');
     $download->add($downloadPeriodDelay);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadPeriodDelay', 1));
     $downloadCycleDelay = new Element\Text('downloadCycleDelay');
     $downloadCycleDelay->setLabel('Delay (in seconds) between cycles')->setAttribute('size', '5');
     $download->add($downloadCycleDelay);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadCycleDelay', 1));
     $downloadFragmentDelay = new Element\Text('downloadFragmentDelay');
     $downloadFragmentDelay->setLabel('Delay (in seconds) between fragments')->setAttribute('size', '5');
     $download->add($downloadFragmentDelay);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadFragmentDelay', 1));
     $downloadMaxPriority = new Element\Text('downloadMaxPriority');
     $downloadMaxPriority->setLabel('Maximum package priority')->setAttribute('size', '5');
     $download->add($downloadMaxPriority);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadMaxPriority', 1));
     $downloadTimeout = new Element\Text('downloadTimeout');
     $downloadTimeout->setLabel('Timeout (in days)')->setAttribute('size', '5');
     $download->add($downloadTimeout);
     $inputFilterDownload->add($this->_getIntegerFilter('downloadTimeout', 1));
     $this->add($download);
     $inputFilter->add($inputFilterDownload, 'Download');
     // Network scanning options
     $scan = new \Zend\Form\Fieldset('Scan');
     $inputFilterScan = new \Zend\InputFilter\InputFilter();
     $allowScan = new Element\Checkbox('allowScan');
     $allowScan->setLabel('Allow network scanning')->setAttribute('onchange', 'toggle(this)');
     $scan->add($allowScan);
     $subnets = new \Library\Form\Element\SelectSimple('scanThisNetwork');
     $subnets->setLabel('Always scan this network')->setEmptyOption('');
     $scan->add($subnets);
     $inputFilterScan->add(array('name' => 'scanThisNetwork', 'required' => false));
     $scanSnmp = new Element\Checkbox('scanSnmp');
     $scanSnmp->setLabel('Use SNMP');
     $scan->add($scanSnmp);
     $this->add($scan);
     $inputFilter->add($inputFilterScan, 'Scan');
     $submit = new \Library\Form\Element\Submit('Submit');
     $submit->setLabel('OK');
     $this->add($submit);
     $this->setInputFilter($inputFilter);
 }
Esempio n. 28
0
 /**
  * Prepare the attribute form
  *
  * @param $attributes array           
  * @return \ProductAdmin\Form\ProductForm
  */
 public function createAttributesElements(array $attributes)
 {
     $customHydrator = new ClassMethods(true);
     $parentFilter = new \Zend\InputFilter\InputFilter();
     $fieldset = new \Zend\Form\Fieldset('attributes');
     //         $fieldset->setUseAsBaseFieldset(true);
     $fieldset->setObject(new \Zend\Stdlib\ArrayObject());
     $fieldset->setFormFactory($this->getFormFactory());
     // thanks to jurians #zftalk irc
     $fieldInput = null;
     $inputFilter = new \Zend\InputFilter\InputFilter();
     foreach ($attributes as $attribute) {
         $formitem = array();
         $filterChain = new \Zend\Filter\FilterChain();
         $name = $attribute->getName();
         $label = $attribute->getLabel() ? $attribute->getLabel() : "-";
         $type = $attribute->getType() ? $attribute->getType() : "string";
         $isRequired = $attribute->getIsRequired();
         $sourceModel = $attribute->getSourceModel();
         $filters = $attribute->getFilters();
         $validators = $attribute->getValidators();
         $cssStyles = $attribute->getCss();
         $validators = !empty($validators) ? json_decode($validators, true) : array();
         // create the new form element array structure
         $formitem['attributes'] = $attribute->getCustomAttributes() ? json_decode($attribute->getCustomAttributes(), true) : json_decode($attribute->attributes, true);
         $formitem['attributes']['id'] = $name;
         $formitem['attributes']['class'] = !empty($attribute->basecss) ? $attribute->basecss : null;
         $formitem['attributes']['name'] = $name;
         $formitem['type'] = !empty($sourceModel) ? $sourceModel : $attribute->input_type;
         $formitem['options']['label'] = $label;
         if ($attribute->getData()) {
             $formitem['options']['value_options'] = json_decode($attribute->getData(), true);
         }
         $filterChain->attachByName('null');
         // set as default
         // set the css style of the element
         if (!empty($cssStyles)) {
             $formitem['attributes']['class'] .= " " . $cssStyles;
         }
         // Handle the dates
         if (!empty($type) && $type == "date") {
             $customHydrator->addStrategy($name, new DateTimeStrategy());
             $typeSource = 'Zend\\Form\\Element\\Date';
             $formitem['type'] = "\\Zend\\Form\\Element\\Date";
             $formitem['options']['format'] = 'd/m/Y';
         }
         // handle the validators preferences of the attribute
         foreach ($validators as $validator) {
             $formitem['validators'] = $validator;
         }
         // var_dump($type);
         // var_dump($customHydrator);
         //             var_dump($formitem);
         // Attach the form item into the form
         $fieldset->add($formitem);
         $fieldInput = new \Zend\InputFilter\Input($name);
         $fieldInput->setRequired($isRequired);
         // handle the filters preferences of the attribute
         if (!empty($filters)) {
             // get the filters attached to the attribute
             $filters = json_decode($filters, true);
             foreach ($filters as $filter) {
                 // if the filter is an array check it by name
                 if (is_array($filter)) {
                     // If the filter is a ...
                     if ($filter['name'] == "File\\RenameUpload") {
                         // create the filter Zend\InputFilter\FileInput
                         $thefilter = new \Zend\InputFilter\FileInput($filter['options']);
                         // ... but how to attach the new filter to the
                         // chain?
                         $chain = new \Zend\Filter\FilterChain();
                         // ... in this way it doesn't work!!
                         $chain->attachByName("filerenameupload", $filter['options']);
                         $filterChain->merge($chain);
                         // just for debugging it ...
                         $filtersApplied = $filterChain->getFilters();
                         //                             var_dump($filtersApplied->toArray());
                     }
                 } elseif ($filter == "cleanurl") {
                     // custom filter
                     $filterChain->attach(new \ProductAdmin\Form\Filter\Cleanurl());
                 } elseif (is_string($filter)) {
                     $filterChain->attachByName($filter);
                 }
             }
         }
         $fieldInput->setFilterChain($filterChain);
         $inputFilter->add($fieldInput);
     }
     $fieldset->setHydrator($customHydrator);
     $this->add($fieldset);
     $parentFilter->add($inputFilter, 'attributes');
     // thanks to GeeH #zftalk irc
     $this->setInputFilter($parentFilter);
     return $this;
 }
 /**
  * @throws \Opg\Common\Exception\UnusedException
  * @return InputFilter
  */
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new \Zend\InputFilter\InputFilter();
         $factory = new InputFactory();
         $inputFilter->add($factory->createInput(array('name' => 'name', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 1000))))));
         $inputFilter->add($factory->createInput(array('name' => 'type', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'InArray', 'options' => array('haystack' => array('Application processing', 'Appointment of new attorney', 'Call', 'Cancellation', 'Confirmation', 'Change of address', 'Court amendment', 'Disclaimer', 'Document capture', 'Email', 'Extension granted', 'Investigation', 'Imperfect application', 'Letter', 'LPA application received', 'Objections', 'Office copy', 'Registration', 'Rejected application', 'Revocation')))))));
         $inputFilter->add($factory->createInput(array('name' => 'description', 'required' => true, 'filters' => array(array('name' => 'StripTags'), array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'min' => 1, 'max' => 2000))))));
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }
 /**
  * @throws \Opg\Common\Exception\UnusedException
  * @return InputFilter
  */
 public function getInputFilter()
 {
     if (!$this->inputFilter) {
         $inputFilter = new \Zend\InputFilter\InputFilter();
         $factory = new InputFactory();
         $inputFilter->add($factory->createInput(array('name' => 'deputyshipOrder', 'required' => true)));
         $inputFilter->add($factory->createInput(array('name' => 'dueDate', 'required' => true, 'validators' => array(array('name' => 'Date')))));
         $inputFilter->add($factory->createInput(array('name' => 'reportingPeriodEndDate', 'required' => true, 'validators' => array(array('name' => 'Date')))));
         $inputFilter->add($factory->createInput(array('name' => 'revisedDueDate', 'required' => false, 'validators' => array(array('name' => 'Date')))));
         $inputFilter->add($factory->createInput(array('name' => 'numberOfChaseLetters', 'required' => true, 'validators' => array(array('name' => 'Int')))));
         $this->inputFilter = $inputFilter;
     }
     return $this->inputFilter;
 }