Exemplo n.º 1
0
 /**
  * @return bool
  */
 public static function validateDate(IControl $control)
 {
     $year = $control->year;
     $month = $control->month;
     $day = $control->day;
     if (!$control->isRequired() && $year === $month && $month === $day && $day === '') {
         return TRUE;
     } elseif ($year > 0 && $month > 0 && $day > 0) {
         return checkdate($month, $day, $year);
     } else {
         return FALSE;
     }
 }
 /**
  * @param \Nette\Forms\IControl
  * @return bool
  */
 public function isLicenseValid(IControl $control)
 {
     $licenses = $control->getValue();
     if (is_string($licenses)) {
         $licenses = array_map('trim', explode(',', $licenses));
     }
     foreach ($licenses as $license) {
         if (!$this->validators->isLicenseValid($license)) {
             return FALSE;
         }
     }
     return TRUE;
 }
Exemplo n.º 3
0
 /**
  * Validates against ruleset.
  * @return bool
  */
 public function validate($emptyOptional = FALSE)
 {
     $emptyOptional = $emptyOptional || $this->isOptional() && !$this->control->isFilled();
     foreach ($this as $rule) {
         if (!$rule->branch && $emptyOptional && $rule->validator !== Form::FILLED) {
             continue;
         }
         $success = $this->validateRule($rule);
         if ($success && $rule->branch && !$rule->branch->validate($rule->validator === Form::BLANK ? FALSE : $emptyOptional)) {
             return FALSE;
         } elseif (!$success && !$rule->branch) {
             $rule->control->addError(Validator::formatMessage($rule, TRUE));
             return FALSE;
         }
     }
     return TRUE;
 }
Exemplo n.º 4
0
Arquivo: ICO.php Projeto: zaxxx/zaxcms
 public static function validateData(Nette\Forms\IControl $control)
 {
     return strlen($control->code) && !is_int($control->code) && $control->isIcoValid($control->ico);
 }
Exemplo n.º 5
0
 /**
  * Is entered values within allowed range?
  *
  * @author   Jan Tvrdík
  * @param    DatePicker
  * @param    array             0 => minDate, 1 => maxDate
  * @return   bool
  */
 public static function validateRange(Nette\Forms\IControl $control, $range)
 {
     return ($range[0] === NULL || $control->getValue() >= $range[0]) && ($range[1] === NULL || $control->getValue() <= $range[1]);
 }
Exemplo n.º 6
0
 /**
  * Filled validator: is control filled?
  * @param  Nette\Forms\IControl
  * @return bool
  */
 public static function validateFilled(IControl $control)
 {
     return $control->isFilled();
 }
 /**
  * Validates range
  *
  * @param \Nette\Forms\IControl $control control
  * @param array $range minimum and maximum dates and times
  * @return bool
  */
 public static function validateRange(IControl $control, $range)
 {
     if ($control->getValue() !== '') {
         if ($control->range['min'] !== NULL) {
             if ($control->getValue() < $control->range['min']) {
                 return FALSE;
             }
         }
         if ($control->range['max'] !== NULL) {
             if ($control->getValue() > $control->range['max']) {
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
Exemplo n.º 8
0
 /**
  * Rangle validator: is a control's value number in specified range?
  * @param  Nette\Forms\IControl
  * @param  array  min and max value pair
  * @return bool
  */
 public static function validateRange(IControl $control, $range)
 {
     return Nette\Utils\Validators::isInRange($control->getValue(), $range);
 }
Exemplo n.º 9
0
 /**
  * @param \Nette\Forms\IControl $control
  * @param $name
  * @return ManyToOne
  */
 public function setDependOn(\Nette\Forms\IControl $control, $name = NULL)
 {
     $_this = $this;
     $this->dependOn = array($control, $name ?: $control->name);
     $this->criteria = array($name => -1);
     $this->form->addSubmit($this->name . '_reload', 'reload')->setValidationScope(FALSE);
     $control->form->onBeforeRender[] = function ($form) use($_this, $control) {
         $control->getControlPrototype()->onChange = "\$('#frm{$form->name}-{$_this->name}_reload').click();";
     };
     $f = function ($form) use($_this, $control, $name) {
         $_this->setCriteria(array($name => $control->value));
     };
     $control->form->onAttached[] = $f;
     $control->form->onLoad[] = $f;
     return $this;
 }
Exemplo n.º 10
0
 public static function validateData(Nette\Forms\IControl $control)
 {
     return checkdate((int) $control->month, (int) $control->day, (int) $control->year) && $control->validTime($control->hour, $control->minute);
 }
Exemplo n.º 11
0
 /**
  * Filled validator: is control filled?
  * @param  IControl
  * @return bool
  */
 public static function validateFilled(IControl $control)
 {
     return count($control->getValue()) !== 0;
 }
Exemplo n.º 12
0
 public static function negativeNumber(IControl $control)
 {
     return (int) $control->getValue() < 0;
 }
Exemplo n.º 13
0
 /**
  * Renders 'control' part of visual row of controls.
  * @param \Nette\Forms\IControl $control
  * @return string
  */
 public function renderControl(\Nette\Forms\IControl $control)
 {
     if ($control instanceof \Nette\Forms\Controls\Checkbox) {
         $html = $control->getLabelPrototype();
         $caption = $html->getText();
         $html->setHtml((string) $control->getControl() . " " . $caption);
         return (string) $html;
     }
     return parent::renderControl($control);
 }
Exemplo n.º 14
0
 /**
  * @param \Nette\Forms\IControl
  * @return bool
  */
 public function validatePhoneNumber(\Nette\Forms\IControl $control)
 {
     $value = $control->getHttpData(Form::DATA_LINE, '[' . static::NAME_PREFIX . ']');
     $value .= $control->getHttpData(Form::DATA_LINE, '[' . static::NAME_NUMBER . ']');
     return $this->validatePhoneNumberString($value);
 }
 /**
  * @param  Forms\IControl $control
  * @return bool
  */
 public static function validateValid(Forms\IControl $control)
 {
     $httpRequest = $control->getHttpRequest();
     return $control->getReCaptcha()->validate($httpRequest->getRemoteAddress(), $httpRequest->getPost());
 }
 /**
  * Filled validator: has been any file uploaded?
  * @param Forms\IControl
  * @return bool
  */
 public static function validateFilled(Forms\IControl $control)
 {
     $files = $control->getValue();
     return count($files) > 0;
 }
Exemplo n.º 17
0
 /**
  * Renders 'control' part of visual row of controls.
  * @return string
  */
 public function renderControl(Nette\Forms\IControl $control)
 {
     $body = $this->getWrapper('control container');
     if ($this->counter % 2) {
         $body->class($this->getValue('control .odd'), TRUE);
     }
     $description = $control->getOption('description');
     if ($description instanceof Html) {
         $description = ' ' . $description;
     } elseif (is_string($description)) {
         $description = ' ' . $this->getWrapper('control description')->setText($control->translate($description));
     } else {
         $description = '';
     }
     if ($control->isRequired()) {
         $description = $this->getValue('control requiredsuffix') . $description;
     }
     $el = $control->getControl();
     if ($control instanceof Nette\Forms\Controls\TextInput || $control instanceof Nette\Forms\Controls\TextArea || $control instanceof Nette\Forms\Controls\SelectBox || $control instanceof Nette\Forms\Controls\MultiSelectBox) {
         $el->class($this->getValue("control form-control"), TRUE);
     }
     if ($control instanceof Nette\Forms\Controls\Checkbox) {
         //$el = $control->getLabel()->insert(0, $el);//reapair in NF 2.1RC3
         $elTemp = $el;
         $el = Html::el('div', array("class" => $this->getValue("pair containerCheckbox")));
         $el->setHtml($elTemp);
     }
     if ($this->isFormHorizontal() && $control instanceof Nette\Forms\Controls\Checkbox) {
         $div = Html::el('div', array("class" => $this->getValue("control col-offset")));
     } else {
         if ($this->isFormHorizontal()) {
             $div = Html::el('div', array("class" => $this->getValue("control col")));
         } else {
             $div = Html::el();
         }
     }
     $div->setHtml($el . $description . $this->renderErrors($control));
     return $body->addHtml($div);
 }
Exemplo n.º 18
0
 public static function validateData(Nette\Forms\IControl $control)
 {
     return $control->validDate($control->year, $control->month, $control->day) && $control->validTime($control->hour, $control->minute);
 }
 /**
  * @param IControl $control
  * @param string $key
  * @return Html
  */
 public function renderSingleControl(IControl $control, $key)
 {
     /** @noinspection PhpUndefinedMethodInspection */
     return $control->getControlPart($key);
 }
 public static function validateMinDistanceFrom(IControl $control, array $args)
 {
     list($distance, $point) = $args;
     return $control->getValue()->getDistanceTo(new GpsPoint($point)) >= $distance;
 }
Exemplo n.º 21
0
 /**
  * Filled validator: has been any checkbox checked?
  *
  * @param \Nette\Forms\IControl $control
  * @return bool
  */
 public static function validateChecked(Nette\Forms\IControl $control)
 {
     return $control->getValue() !== NULL;
 }
Exemplo n.º 22
0
 /**
  * @param BaseDateTime
  * @return bool
  */
 public static function validateValid(\Nette\Forms\IControl $control)
 {
     $value = $control->getValue();
     return is_null($value) || $value instanceof DateTime;
 }
 /**
  * Renders 'control' part of visual row of controls.
  * @return string
  */
 public function renderControl(Nette\Forms\IControl $control)
 {
     $body = $this->getWrapper('control container');
     if ($this->counter % 2) {
         $body->class($this->getValue('control .odd'), TRUE);
     }
     $description = $control->getOption('description');
     if ($description instanceof Html) {
         $description = ' ' . $description;
     } elseif (is_string($description)) {
         $description = ' ' . $this->getWrapper('control description')->setText($control->translate($description));
     } else {
         $description = '';
     }
     if ($control->isRequired()) {
         $description = $this->getValue('control requiredsuffix') . $description;
     }
     $control->setOption('rendered', TRUE);
     $el = $control->getControl();
     if ($el instanceof Html && $el->getName() === 'input') {
         $el->class($this->getValue("control .{$el->type}"), TRUE);
     }
     return $body->setHtml($el . $description . $this->renderErrors($control));
 }
 public function renderControlErrors(IControl $control)
 {
     $container = clone $this->prototypes->getControlErrors();
     foreach ($control->getErrors() as $error) {
         $el = clone $this->prototypes->getControlError();
         $this->addContent($el->getPlaceholder(), $error);
         $container->getPlaceholder()->addHtml($el);
     }
     return $container;
 }
Exemplo n.º 25
0
 /**
  * Renders 'control' part of visual row of controls.
  * @return string
  */
 public function renderControl(Nette\Forms\IControl $control)
 {
     $body = $this->getWrapper('control container');
     if ($this->counter % 2) {
         $body->class($this->getValue('control .odd'), TRUE);
     }
     $description = $control->getOption('description');
     if ($description instanceof Html) {
         $description = ' ' . $control->getOption('description');
     } elseif (is_string($description)) {
         $description = ' ' . $this->getWrapper('control description')->setText($control->translate($description));
     } else {
         $description = '';
     }
     if ($control->isRequired()) {
         $description = $this->getValue('control requiredsuffix') . $description;
     }
     if ($this->getValue('control errors')) {
         $description .= $this->renderErrors($control);
     }
     if ($control instanceof Nette\Forms\Controls\Checkbox || $control instanceof Nette\Forms\Controls\Button) {
         return $body->setHtml((string) $control->getControl() . (string) $control->getLabel() . $description);
     } else {
         return $body->setHtml((string) $control->getControl() . $description);
     }
 }
Exemplo n.º 26
0
 /**
  * @param IControl $control
  * @return bool
  */
 public static function validateDateInputFilled(IControl $control)
 {
     if (!$control instanceof static) {
         throw new InvalidArgumentException("Given control object must be instance of '" . get_class() . "'.");
     }
     return !$control->isEmpty();
 }
Exemplo n.º 27
0
 /**
  * Count/length validator. Range is array, min and max length pair.
  * @return bool
  * @internal
  */
 public static function validateLength(IControl $control, $range)
 {
     if (!is_array($range)) {
         $range = array($range, $range);
     }
     $value = $control->getValue();
     return Nette\Utils\Validators::isInRange(is_array($value) ? count($value) : Nette\Utils\Strings::length($value), $range);
 }
Exemplo n.º 28
0
	/**
	 * Filled validator: has been any filed?
	 *
	 * @param  \Nette\Forms\IControl
	 * @return bool
	 */
	public static function validateFilled(\Nette\Forms\IControl $control)
	{
		return (bool) count(array_filter(
			$control->getValue(), function($file) {
				return $file instanceof FileUpload && $file->isOK();
			}
		));
	}
Exemplo n.º 29
0
 /**
  * Is a control's value float number?
  * @return bool
  */
 public static function validateFloat(IControl $control)
 {
     $value = str_replace(array(' ', ','), array('', '.'), $control->getValue());
     if (Validators::isNumeric($value)) {
         $control->setValue((double) $value);
         return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 30
0
 /**
  * Is control not filled?
  * @return bool
  * @internal
  */
 public static function validateBlank(IControl $control)
 {
     return !$control->isFilled();
 }