/
SizeField.php
50 lines (43 loc) · 1.19 KB
/
SizeField.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
<?php
namespace Concrete\Core\File\Search\Field\Field;
use Concrete\Core\File\FileList;
use Concrete\Core\Search\Field\AbstractField;
use Concrete\Core\Search\ItemList\ItemList;
class SizeField extends AbstractField
{
protected $requestVariables = ['size_from', 'size_to'];
public function getKey()
{
return 'size';
}
public function getDisplayName()
{
return t('Size');
}
public function renderSearchField()
{
$form = \Core::make('helper/form');
$html = '';
$html .= $form->number('size_from', $this->getData('size_from'), array('min' => 0));
$html .= t('to');
$html .= $form->number('size_to', $this->getData('size_to'), array('min' => 1));
$html .= t('KB');
return $html;
}
/**
* @param FileList $list
* @param $request
*/
public function filterList(ItemList $list)
{
$from = 0;
$to = 0;
if (!empty($this->getData('size_from'))) {
$from = $this->getData('size_from');
}
if (!empty($this->getData('size_to'))) {
$to = $this->getData('size_to');
}
$list->filterBySize($from, $to);
}
}