/
NumberOfChildrenField.php
54 lines (45 loc) · 1.79 KB
/
NumberOfChildrenField.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
<?php
namespace Concrete\Core\Page\Search\Field\Field;
use Concrete\Core\File\FileList;
use Concrete\Core\File\Type\Type;
use Concrete\Core\Search\Field\AbstractField;
use Concrete\Core\Search\Field\FieldInterface;
use Concrete\Core\Search\ItemList\ItemList;
class NumberOfChildrenField extends AbstractField
{
protected $requestVariables = [
'cChildrenSelect', 'cChildren'
];
public function getKey()
{
return 'number_of_children';
}
public function getDisplayName()
{
return t('# of Children');
}
/**
* @param FileList $list
* @param $request
*/
public function filterList(ItemList $list)
{
$symbol = '=';
if ($this->getData('cChildrenSelect') == 'gt') {
$symbol = '>';
} elseif ($this->getData('cChildrenSelect') == 'lt') {
$symbol = '<';
}
$list->filterByNumberOfChildren($this->getData('cChildren'), $symbol);
}
public function renderSearchField()
{
$html = '<div class="row row-cols-auto g-0 align-items-center"><div class="col-auto"><select name="cChildrenSelect" class="form-select">';
$html .= '<option value="gt"' . ($this->getData('cChildrenSelect') == 'gt' ? ' selected' : '') . '>' . t('More Than') . '</option>';
$html .= '<option value="eq"' . ($this->getData('cChildrenSelect') == 'eq' ? ' selected' : '') . '>' . t('Equal To') . '</option>';
$html .= '<option value="lt"' . ($this->getData('cChildrenSelect') == 'lt' ? ' selected' : '') . '>' . t('Fewer Than') . '</option>';
$html .= '</select></div>';
$html .= ' <div class="col-auto"><input type="number" name="cChildren" class="form-control" min="0" value="' . $this->getData('cChildren') . '" /></div></div>';
return $html;
}
}