Example #1
0
 public function loadDefaultDecorators()
 {
     parent::loadDefaultDecorators();
     $this->removeDecorator('Label');
     $this->removeDecorator('HtmlTag');
     $this->addDecorator('HtmlTag', array('tag' => 'span', 'class' => 'spanImg'));
 }
 public function __construct($spec, $options = array())
 {
     $options = array_merge($options, array('disableLoadDefaultDecorators' => true));
     parent::__construct($spec, $options);
     $this->_decorator = new Monkeys_Form_Decorator_Composite();
     $this->addDecorator($this->_decorator);
 }
 /**
  * constructor
  * @param $spec
  * @param $options
  */
 public function __construct($spec, $options = null)
 {
     $objLoader = new PluginLoader();
     $objLoader->setPluginLoader($this->getPluginLoader(PluginLoader::TYPE_FORM_DECORATOR));
     $objLoader->setPluginType(PluginLoader::TYPE_FORM_DECORATOR);
     $this->setPluginLoader($objLoader, PluginLoader::TYPE_FORM_DECORATOR);
     parent::__construct($spec, $options);
 }
Example #4
0
 /**
  * Override isValid()
  *
  * Ensure that validation error messages mask password value.
  * 
  * @param  string $value 
  * @param  mixed $context 
  * @return bool
  */
 public function isValid($value, $context = null)
 {
     foreach ($this->getValidators() as $validator) {
         if ($validator instanceof Zend_Validate_Abstract) {
             $validator->setObscureValue(true);
         }
     }
     return parent::isValid($value, $context);
 }
 public function __construct($spec, $options = null)
 {
     $localOptions = array('filters' => array('StringTrim'), 'label' => 'Date and time', 'validators' => array(new \Tillikum\Validate\FormDatetime()));
     if (isset($options)) {
         $options = array_replace_recursive($localOptions, $options);
     } else {
         $options = $localOptions;
     }
     parent::__construct($spec, $options);
 }
Example #6
0
 public function __construct($spec, $options = null)
 {
     if (is_string($spec) && (null !== $options && is_string($options))) {
         $options = array('label' => $options);
     }
     if (!isset($options['ignore'])) {
         $options['ignore'] = true;
     }
     parent::__construct($spec, $options);
 }
Example #7
0
 public function __construct($spec, $options = null)
 {
     $localOptions = array('filters' => array('StringTrim'));
     if (isset($options)) {
         $options = array_replace_recursive($localOptions, $options);
     } else {
         $options = $localOptions;
     }
     parent::__construct($spec, $options);
 }
Example #8
0
 /**
  * Return label
  *
  * If no label is present, returns the currently set name.
  *
  * If a translator is present, returns the translated label.
  *
  * @return string
  */
 public function getLabel()
 {
     $value = parent::getLabel();
     if (null === $value) {
         $value = $this->getName();
     }
     if (null !== ($translator = $this->getTranslator())) {
         return $translator->translate($value);
     }
     return $value;
 }
Example #9
0
 public function getValue()
 {
     if (is_array($this->_value)) {
         $value = $this->_value['year'] . '-' . $this->_value['month'] . '-' . $this->_value['day'];
         if ($value == '--') {
             $value = null;
         }
         $this->setValue($value);
     }
     return parent::getValue();
 }
Example #10
0
 /**
  * Определяем массив ролей и уровней доступа и дергаем родительский конструктор
  *
  * @param unknown_type $spec
  * @param unknown_type $options
  */
 public function __construct($spec, $options = null)
 {
     /**
      * @see Phorm_User
      */
     require_once "Phorm/User.php";
     $User = new Phorm_User();
     $options['roles'] = $User->getRolesListAsPairs();
     $options['levels'] = $User->getAccessLevelsAsPairs();
     parent::__construct($spec, $options);
 }
Example #11
0
 public function isRequired()
 {
     $elements = $this->getElements();
     if (empty($elements)) {
         return parent::isRequired();
     }
     foreach ($elements as $el) {
         if ($el->isRequired()) {
             return true;
         }
     }
     return false;
 }
Example #12
0
 /**
  * Overloading: allow rendering specific decorators
  *
  * Call renderDecoratorName() to render a specific decorator.
  *
  * @param  string $method
  * @param  array $args
  * @return \MUtil_Html_HtmlElement or at least something that implements the \MUtil_Html_HtmlInterface interface
  * @throws \Zend_Form_Exception for invalid decorator or invalid method call
  */
 public function __call($method, $args)
 {
     if ('render' == substr($method, 0, 6)) {
         return parent::__call($method, $args);
     }
     $elem = \MUtil_Html::createArray($method, $args);
     $value = $this->getValue();
     if (!$value instanceof \MUtil_Html_ElementInterface) {
         $value = new \MUtil_Html_Sequence();
     }
     $value->append($elem);
     $this->setValue($value);
     return $elem;
 }
Example #13
0
 public function isValid($value, $context = null)
 {
     if (!is_array($value)) {
         return false;
     }
     $result = checkdate((int) $value['month'], (int) $value['day'], (int) $value['year']);
     if ($result == false) {
         $value = null;
     }
     if ($this->max_year && (int) $value['year'] > $this->max_year || $this->min_year && (int) $value['year'] < $this->min_year) {
         $value = null;
     }
     return parent::isValid($value, $context);
 }
Example #14
0
 /**
  * Validate upload
  * 
  * @param  string $value 
  * @param  mixed $context 
  * @return bool
  */
 public function isValid($value, $context = null)
 {
     if (isset($_FILES[$this->getName()])) {
         $value = $_FILES[$this->getName()]['tmp_name'];
         $context = $_FILES[$this->getName()];
         $context['destination'] = $this->_destination;
     }
     $isValid = parent::isValid($value, $context);
     // If it's valid, we move the file to its final destination
     if ($isValid && isset($this->_destination)) {
         $destination = is_dir($this->_destination) ? $this->_destination . '/' . $context['name'] : $this->_destination;
         move_uploaded_file($value, $destination);
     }
     return $isValid;
 }
 public function setValue($value)
 {
     if (is_array($value)) {
         if (isset($value['value'])) {
             parent::setValue($value['value']);
         }
         if (isset($value['overwrite'])) {
             if ($value['overwrite'] == '1' || $value['overwrite'] === true) {
                 $this->overwrite = true;
             } else {
                 $this->overwrite = false;
             }
         }
     } else {
         parent::setValue($value);
     }
 }
Example #16
0
 public function isValid($value, $context = null)
 {
     $fieldName = $this->getName();
     $auxiliaryFieldsNames = $this->getDayMonthYearTimeFieldNames($fieldName);
     if (isset($context[$auxiliaryFieldsNames['day']]) && isset($context[$auxiliaryFieldsNames['month']]) && isset($context[$auxiliaryFieldsNames['year']]) && isset($context[$auxiliaryFieldsNames['hour']]) && isset($context[$auxiliaryFieldsNames['minutes']]) && isset($context[$auxiliaryFieldsNames['ampm']])) {
         if ($context[$auxiliaryFieldsNames['year']] == '-' || $context[$auxiliaryFieldsNames['month']] == '-' || $context[$auxiliaryFieldsNames['day']] == '-' || $context[$auxiliaryFieldsNames['hour']] == '-' || $context[$auxiliaryFieldsNames['minutes']] == '-' || $context[$auxiliaryFieldsNames['ampm']] == '-') {
             $value = null;
         } else {
             $hour = $context[$auxiliaryFieldsNames['hour']];
             if ($context[$auxiliaryFieldsNames['ampm']] == 'pm') {
                 $hour += 12;
             }
             $value = str_pad($context[$auxiliaryFieldsNames['year']], 4, '0', STR_PAD_LEFT) . '-' . str_pad($context[$auxiliaryFieldsNames['month']], 2, '0', STR_PAD_LEFT) . '-' . str_pad($context[$auxiliaryFieldsNames['day']], 2, '0', STR_PAD_LEFT) . ' ' . str_pad($hour, 2, '0', STR_PAD_LEFT) . ':' . str_pad($context[$auxiliaryFieldsNames['minutes']], 2, '0', STR_PAD_LEFT) . ':00';
         }
         $this->setValue($value);
     }
     return parent::isValid($value, $context);
 }
Example #17
0
 public function isValid($value, $context = null)
 {
     // for a file upload, the value is not in the POST array, it's in $_FILES
     $key = $this->getName();
     if ($value === null) {
         if (isset($_FILES[$key])) {
             $value = $_FILES[$key];
         }
     }
     // auto insert ValidFile validator
     if ($this->isRequired() && $this->autoInsertValidFileValidator() && !$this->getValidator('ValidFile')) {
         $validators = $this->getValidators();
         $validFile = array('validator' => 'ValidFile', 'breakChainOnFailure' => true);
         array_unshift($validators, $validFile);
         $this->setValidators($validators);
         // do not use the automatic NotEmpty Validator as ValidFile replaces it
         $this->setAutoInsertNotEmptyValidator(false);
     }
     return parent::isValid($value, $context);
 }
Example #18
0
 /**
  * Определяем массив опций и дергаем родительский конструктор
  *
  * @param mixed $spec
  * @param array $options
  */
 public function __construct($spec, $options = null)
 {
     $this->translate = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('Translate');
     /**
      * Выделяем дополнительные элементы в отдельную форму и рендерим ее
      */
     require_once 'Phorm/Form.php';
     if (isset($options['elements']) && is_array($options['elements'])) {
         $config = array('elements' => $options['elements']);
         if (isset($options['paths']['prefixPath'])) {
             $config['prefixPath'] = array_values($options['paths']['prefixPath']);
         }
         if (isset($options['paths']['elementPrefixPath'])) {
             $config['elementPrefixPath'] = array_values($options['paths']['elementPrefixPath']);
         }
         /*foreach ($options as $key=>$option) {
         			if(!in_array($key,array('elements','prefixPath','elementPrefixPath'))) {
         				unset($options[$key]);
         			}
         		}*/
         $form = new Phorm_Form(null, null, $config);
         $form->removeDecorator('Form');
         $form->removeDecorator('DtDdWrapper');
         $form->setElementsBelongTo($spec . '[]');
         $this->renderform = $form->render() . '<div class="clear"></div>';
         unset($options['elements'], $config['elements']);
         foreach ($form->getElements() as $element) {
             $element->setAttrib('id', null);
         }
         $this->form = $form;
     }
     /**
      * Инициализируем родительский конструктор
      */
     parent::__construct($spec, $options);
 }
Example #19
0
 public function isValid($value, $context = null)
 {
     // Empty
     if ($this->getAllowEmpty() && (empty($value) || is_array($value) && 0 == count(array_filter($value)))) {
         return parent::isValid($value, $context);
     }
     $this->setValue($value);
     $value = $this->getValue();
     // Normal processing
     if (is_string($value)) {
         if (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})( (\\d{2}):(\\d{2})(:(\\d{2}))?)?$/', $value, $m)) {
             $year = $m[1];
             $month = $m[2];
             $day = $m[3];
             $hour = @$m[5];
             $minute = @$m[6];
         } else {
             $this->addError('Please select a date from the calendar.');
             return false;
         }
     } else {
         if (is_array($value)) {
             $m = explode('/', $value['date']);
             if (count($m) === 3) {
                 $year = $m[stripos($this->dateFormat, 'y')];
                 $month = $m[stripos($this->dateFormat, 'm')];
                 $day = $m[stripos($this->dateFormat, 'd')];
             } else {
                 $year = null;
                 $month = null;
                 $day = null;
             }
             if (isset($value['hour']) && in_array($value['hour'], $this->getHourOptions())) {
                 $hour = $value['hour'];
             }
             if (isset($value['minute']) && in_array($value['minute'], $this->getMinuteOptions())) {
                 $minute = $value['minute'];
             }
             if (isset($value['ampm']) && in_array($value['ampm'], $this->getAMPMOptions())) {
                 if ($value['ampm'] == 'pm' && $hour < 12 && null !== $hour) {
                     $hour += 12;
                 } else {
                     if ($value['ampm'] == 'AM' && $hour == 12) {
                         $hour = 0;
                     }
                 }
             }
         }
     }
     // Check validity
     if (!$year || !$month || !$day) {
         $this->addError('Please select a date from the calendar.');
         return false;
     }
     if (!$hour || !$minute) {
         $this->addError('Please select a time from the dropdown.');
         return false;
     }
     if ($month < 1 || $month > 12) {
         $this->addError('Please select a date from the calendar.');
         return false;
     }
     if ($day < 1 || $day > 31) {
         $this->addError('Please select a date from the calendar.');
         return false;
     }
     //if( $this->_useMilitaryTime() ) {
     if ($hour < 0 || $hour > 23) {
         $this->addError('Please select a time from the dropdown.');
         return false;
     }
     //} else {
     //  if( $hour < 1 || $hour > 12 ) {
     //    $this->addError('Please select a time from the dropdown.');
     //    return false;
     //  }
     //}
     if ($minute < 0 || $minute >= 60) {
         $this->addError('Please select a time from the dropdown.');
         return false;
     }
     return parent::isValid($value, $context);
 }
Example #20
0
 /**
  * Render CSRF token in form
  *
  * @param  Zend_View_Interface $view
  * @return string
  */
 public function render(Zend_View_Interface $view = null)
 {
     $this->initCsrfToken();
     return parent::render($view);
 }
Example #21
0
 /**
  * Set value
  *
  * If value matches checked value, sets to that value, and sets the checked
  * flag to true.
  *
  * Any other value causes the unchecked value to be set as the current
  * value, and the checked flag to be set as false.
  *
  *
  * @param  mixed $value
  * @return Zend_Form_Element_Checkbox
  */
 public function setValue($value)
 {
     if ($value == $this->getCheckedValue()) {
         parent::setValue($value);
         $this->checked = true;
     } else {
         parent::setValue($this->getUncheckedValue());
         $this->checked = false;
     }
     return $this;
 }
 /**
  * Constructor
  *
  * $spec may be:
  * - string: name of element
  * - array: options with which to configure element
  * - Zend_Config: Zend_Config with options for configuring element
  *
  *
  * Chosen options can be set in array two ways first by DQL second simple array.
  *
  * To set options by DQL $options array structure should be like:
  *  [
  *      'dql' => "select u.username from \\Entities\\User where u.username IS NOT NULL", //mandatory
  *      'db'  => "default" //Optional if db is not default. Some project may have more then one.
  *  ]
  * 
  * To set options by array $options array structure should be like:
  *  [
  *      'options' => [ 'option1' => 'option1', 'option2' => 'option2', 'option3' => 'option3' ], //mandatory
  *  ]
  *
  *
  * @param  string|array|Zend_Config $spec
  * @return void
  *
  * @see setChosenOptions()
  * @see setChosenOptionsByDql()
  */
 public function __construct($spec, $options = null)
 {
     if (isset($options['options'])) {
         $this->setChosenOptions($options['options']);
         unset($options['options']);
     } else {
         if (isset($options['dql'])) {
             if (isset($options['db'])) {
                 $this->setChosenOptionsByDql($options['dql'], $options['db']);
                 unset($options['db']);
             } else {
                 $this->setChosenOptionsByDql($options['dql']);
             }
             unset($options['dql']);
         }
     }
     parent::__construct($spec, $options);
 }
 public function __construct($spec, $options = null)
 {
     parent::__construct($spec, $options);
 }
Example #24
0
 /**
  * Is the captcha valid?
  *
  * @param  mixed $value
  * @param  mixed $context
  * @return boolean
  */
 public function isValid($value, $context = null)
 {
     $this->getCaptcha()->setName($this->getName());
     $belongsTo = $this->getBelongsTo();
     if (empty($belongsTo) || !is_array($context)) {
         return parent::isValid($value, $context);
     }
     $name = $this->getFullyQualifiedName();
     $root = substr($name, 0, strpos($name, '['));
     $segments = substr($name, strpos($name, '['));
     $segments = ltrim($segments, '[');
     $segments = rtrim($segments, ']');
     $segments = explode('][', $segments);
     array_unshift($segments, $root);
     array_pop($segments);
     $newContext = $context;
     foreach ($segments as $segment) {
         if (array_key_exists($segment, $newContext)) {
             $newContext = $newContext[$segment];
         }
     }
     return parent::isValid($value, $newContext);
 }
Example #25
0
 public function getValue()
 {
     return parent::getValue();
 }
Example #26
0
 /**
  * Set translator object for localization
  *
  * @param  Zend_Translate|null $translator
  * @return Zend_Form_Element_File
  */
 public function setTranslator($translator = null)
 {
     $adapter = $this->getTransferAdapter();
     $adapter->setTranslator($translator);
     parent::setTranslator($translator);
     return $this;
 }
 /**
  * Render form element
  * Checks for decorator interface to prevent errors
  *
  * @param  Zend_View_Interface $view
  * @return string
  */
 public function render(Zend_View_Interface $view = null)
 {
     $marker = false;
     foreach ($this->getDecorators() as $decorator) {
         if ($decorator instanceof Zend_Form_Decorator_Marker_File_Interface) {
             $marker = true;
         }
     }
     if (!$marker) {
         require_once 'Zend/Form/Element/Exception.php';
         throw new Zend_Form_Element_Exception('No file decorator found... unable to render file element');
     }
     return parent::render($view);
 }
 /**
  * Render
  *
  * Ensure that options property is set when rendering.
  * 
  * @param  Zend_View_Interface $view 
  * @return string
  */
 public function render(Zend_View_Interface $view = null)
 {
     $this->options = array('checked' => $this->getCheckedValue(), 'unChecked' => $this->getUncheckedValue());
     return parent::render($view);
 }
 /**
  * Is the value provided valid?
  *
  * Autoregisters InArray validator if necessary.
  *
  * @param  string $value
  * @param  mixed $context
  * @return bool
  */
 public function isValid($value, $context = null)
 {
     if ($this->registerInArrayValidator()) {
         if (!$this->getValidator('InArray')) {
             $multiOptions = $this->getMultiOptions();
             $options = array();
             foreach ($multiOptions as $opt_value => $opt_label) {
                 // optgroup instead of option label
                 if (is_array($opt_label)) {
                     $options = array_merge($options, array_keys($opt_label));
                 } else {
                     $options[] = $opt_value;
                 }
             }
             $this->addValidator('InArray', true, array($options));
         }
     }
     return parent::isValid($value, $context);
 }
Example #30
0
 public function getLabel()
 {
     return parent::getLabel() . $this->getTranslator()->translate($this->hash->getType());
 }