-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumber.php
64 lines (54 loc) · 1.55 KB
/
Number.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* This file is part of the Grido (http://grido.bugyik.cz)
*
* Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
*
* For the full copyright and license information, please view
* the file LICENSE.md that was distributed with this source code.
*/
namespace Grido\Components\Filters;
/**
* Number input filter.
*
* @package Grido
* @subpackage Components\Filters
* @author Petr Bugyík
*/
class Number extends Text
{
/** @var string */
protected $condition;
/**
* @return \Nette\Forms\Controls\TextInput
*/
protected function getFormControl()
{
$control = parent::getFormControl();
$hint = 'Grido.HintNumber';
$control->getControlPrototype()->title = sprintf($this->translate($hint), rand(1, 9));
$control->getControlPrototype()->class[] = 'number';
return $control;
}
/**
* @param string $value
* @return Condition|bool
* @throws \Exception
* @internal
*/
public function __getCondition($value)
{
$condition = parent::__getCondition($value);
if ($condition === NULL) {
$condition = Condition::setupEmpty();
if (preg_match('/(<>|[<|>]=?)?([-0-9,|.]+)/', $value, $matches)) {
$value = str_replace(',', '.', $matches[2]);
$operator = $matches[1]
? $matches[1]
: '=';
$condition = Condition::setup($this->getColumn(), $operator . ' ?', $value);
}
}
return $condition;
}
}