1 <?php
2
3 /**
4 * This file is part of the Grido (https://github.com/o5/grido)
5 *
6 * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz)
7 *
8 * For the full copyright and license information, please view
9 * the file LICENSE.md that was distributed with this source code.
10 */
11
12 namespace Grido\Components\Filters;
13
14 /**
15 * Check box filter.
16 *
17 * @package Grido
18 * @subpackage Components\Filters
19 * @author Petr Bugyík
20 */
21 class Check extends Filter
22 {
23 /* representation TRUE in URI */
24 const TRUE = '✓';
25
26 /** @var string */
27 protected $condition = 'IS NOT NULL';
28
29 /**
30 * @return \Nette\Forms\Controls\Checkbox
31 */
32 protected function getFormControl()
33 {
34 return new \Nette\Forms\Controls\Checkbox($this->label);
35 }
36
37 /**
38 * @param string $value
39 * @return array
40 * @internal
41 */
42 public function __getCondition($value)
43 {
44 $value = $value == self::TRUE
45 ? TRUE
46 : FALSE;
47
48 return parent::__getCondition($value);
49 }
50
51 /**
52 * @param bool $value
53 * @return NULL
54 * @internal
55 */
56 public function formatValue($value)
57 {
58 return NULL;
59 }
60
61 /**
62 * @param bool $value
63 * @return string
64 * @internal
65 */
66 public function changeValue($value)
67 {
68 return (bool) $value === TRUE
69 ? self::TRUE
70 : $value;
71 }
72 }
73