Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
numberfield.php
1<?php
9
10use Bitrix\Main\UI\Filter\NumberType as FilterNumberType;
11
17{
24 public function applyFilter(array &$filter = array())
25 {
26 $filterKey = $this->getFilterKey();
27 $data = $this->calcNumbers();
28
29 switch ($data['op'])
30 {
32 if (is_numeric($data['from']))
33 {
34 $filter["=$filterKey"] = $data['from'];
35 }
36 return;
37
40 $opMore = '>';
41 $opLess = '<';
42 break;
43
44 default:
45 $opMore = '>=';
46 $opLess = '<=';
47 break;
48
49 }
50
51 if (is_numeric($data['from']))
52 {
53 $filter["{$opMore}$filterKey"] = $data['from'];
54 }
55 if (is_numeric($data['to']))
56 {
57 $filter["{$opLess}$filterKey"] = $data['to'];
58 }
59 }
60
61 private function calcNumbers()
62 {
63 $result = array(
65 'from' => null,
66 'to' => null,
67 );
68 $value = $this->getValue();
69 if (!is_array($value) || count($value) === 0)
70 {
71 return $result;
72 }
73
74 $id = $this->getId();
75 if (isset($value["{$id}_numsel"]) && in_array($value["{$id}_numsel"], FilterNumberType::getList()))
76 {
77 $result['op'] = $value["{$id}_numsel"];
78 }
79
80 if (isset($value["{$id}_from"]))
81 {
82 $result['from'] = $value["{$id}_from"];
83 }
84
85 if (isset($value["{$id}_to"]))
86 {
87 $result['to'] = $value["{$id}_to"];
88 }
89
90 return $result;
91 }
92}