Skip to content

Commit 9f845d3

Browse files
committed
Initial commit
0 parents  commit 9f845d3

6 files changed

Lines changed: 481 additions & 0 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
NasExt/FilterFormControl
2+
===========================
3+
4+
Data filter control for Nette Framework.
5+
6+
Requirements
7+
------------
8+
9+
NasExt/FilterFormControl requires PHP 5.3.2 or higher.
10+
11+
- [Nette Framework](https://github.com/nette/nette)
12+
13+
Installation
14+
------------
15+
16+
The best way to install NasExt/FilterFormControl is using [Composer](http://getcomposer.org/):
17+
18+
```sh
19+
$ composer require nasext/filter-form-control
20+
```
21+
22+
-----
23+
24+
Repository [http://github.com/nasext/filterformcontrol](http://github.com/nasext/filterformcontrol).

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "nasext/filter-form-control",
3+
"type": "library",
4+
"description": "Data form filter control for Nette Framework",
5+
"keywords": ["nette", "nasext", "FilterFormControl"],
6+
"license": ["MIT"],
7+
"authors": [
8+
{
9+
"name": "Dusan Hudak"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.3.0",
14+
"nette/nette": "@dev"
15+
},
16+
"autoload": {
17+
"psr-0": {
18+
"NasExt\\Controls\\": "src/"
19+
}
20+
}
21+
}

doc/en/index.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
NasExt/FilterFormControl
2+
===========================
3+
4+
Data filter control for Nette Framework.
5+
6+
Requirements
7+
------------
8+
9+
NasExt/FilterFormControl requires PHP 5.3.2 or higher.
10+
11+
- [Nette Framework](https://github.com/nette/nette)
12+
13+
Installation
14+
------------
15+
16+
The best way to install NasExt/FilterFormControl is using [Composer](http://getcomposer.org/):
17+
18+
```sh
19+
$ composer require nasext/filter-form-control
20+
```
21+
22+
23+
## Usage
24+
25+
```php
26+
class FooPresenter extends Presenter
27+
{
28+
29+
public function renderDefault()
30+
{
31+
/** @var NasExt\Controls\FilterFormControl $filter */
32+
$filter = $this['filter'];
33+
$filterData = $filter->getData(); // data for filter
34+
}
35+
36+
37+
/**
38+
* @return NasExt\Controls\FilterFormControl
39+
*/
40+
protected function createComponentFilter($name)
41+
{
42+
$control = new NasExt\Controls\FilterFormControl($this, $name);
43+
44+
$control->setDefaultValues(array('code' => 'some default value for code input'));
45+
46+
/** @var Form $form */
47+
$form = $control['form'];
48+
49+
$form->addText('code', 'Code');
50+
$form->addText('name', 'Name');
51+
52+
return $control;
53+
}
54+
}
55+
```
56+
57+
58+
###Use dataFilter callback for filtering data in persistent param in url
59+
If you need use special filter input use object in input, like Nette\Datetime,
60+
so you must translate this object to timestamp before set persistent parameter for url, and after load data from persistent parameter
61+
you need transform timestamp to Nette\Datetime object. For this process use setDataFilter().
62+
- FILTER_IN: use when transform object to string in process set persistent parameter for url
63+
- FILTER_OUT: use when transform string from persistent parameter to object
64+
```php
65+
/**
66+
* @return NasExt\Controls\FilterFormControl
67+
*/
68+
protected function createComponentFilter($name)
69+
{
70+
$control = new NasExt\Controls\FilterFormControl($this, $name);
71+
72+
$control->setDataFilter(function ($values, $filterType) {
73+
if (array_key_exists('date', $values) && !empty($values['date'])) {
74+
if ($filterType == FilterFormControl::FILTER_IN) {
75+
if ($values['date'] instanceof DateTime) {
76+
$values['date'] = $values['date']->getTimestamp();
77+
}else{
78+
$values['date'] = strtotime($values['date']);
79+
}
80+
} elseif ($filterType == FilterFormControl::FILTER_OUT) {
81+
if (!$values['date'] instanceof DateTime) {
82+
$date = new DateTime();
83+
$values['date'] = $date->setTimestamp($values['date']);
84+
}
85+
}
86+
}
87+
88+
return $values;
89+
});
90+
91+
/** @var Form $form */
92+
$form = $control['form'];
93+
94+
$form->addText('date', 'Date');
95+
96+
return $control;
97+
}
98+
}
99+
```
100+
101+
###FilterFormControl with ajax
102+
For use FilterFormControl with ajax use setAjaxRequest() and use events onFilter[], onReset[] for invalidateControl
103+
```php
104+
/**
105+
* @return NasExt\Controls\FilterFormControl
106+
*/
107+
protected function createComponentFilter($name)
108+
{
109+
$control = new NasExt\Controls\FilterFormControl($this, $name);
110+
// enable ajax request, default is false
111+
$control->setAjaxRequest();
112+
113+
$that = $this;
114+
$invalidateControl = function ($component, $values) use ($that) {
115+
if ($that->isAjax()) {
116+
$that->invalidateControl();
117+
}
118+
};
119+
120+
$control->onFilter[] = $invalidateControl;
121+
$control->onReset[] = $invalidateControl;
122+
123+
/** @var Form $form */
124+
$form = $control['form'];
125+
126+
$form->addText('code', 'Code');
127+
$form->addText('name', 'Name');
128+
129+
return $control;
130+
}
131+
```
132+
133+
###Set templateFile for FilterFormControl
134+
For set templateFile use setTemplateFile()
135+
```php
136+
/**
137+
* @return NasExt\Controls\FilterFormControl
138+
*/
139+
protected function createComponentFilter($name)
140+
{
141+
$control = new NasExt\Controls\FilterFormControl($this, $name);
142+
$control->setTemplateFile('myTemplate.latte');
143+
144+
/** @var Form $form */
145+
$form = $control['form'];
146+
147+
$form->addText('code', 'Code');
148+
$form->addText('name', 'Name');
149+
150+
return $control;
151+
}
152+
```
153+
154+
-----
155+
156+
Repository [http://github.com/nasext/filterformcontrol](http://github.com/nasext/filterformcontrol).

license.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2013 Dusan Hudak (http://dusan-hudak.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{control form}
2+

0 commit comments

Comments
 (0)