Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
filter.php
1
<?php
8
namespace
Bitrix\Sender\Stat
;
9
10
use
Bitrix\Main\ArgumentException
;
11
use
Bitrix\Main\Type\DateTime
;
12
13
class
Filter
14
{
15
CONST
PERIOD_WEEK
= 7;
16
CONST
PERIOD_MONTH
= 30;
17
CONST
PERIOD_MONTH_3
= 90;
18
CONST
PERIOD_MONTH_6
= 180;
19
CONST
PERIOD_MONTH_12
= 365;
20
21
protected
$values
= array(
22
'authorId'
=>
null
,
23
'chainId'
=>
null
,
24
'mailingId'
=>
null
,
25
'postingId'
=>
null
,
26
'periodFrom'
=>
null
,
27
'periodTo'
=>
null
,
28
'period'
=>
null
29
);
30
31
public
function
__construct
(array $values = array())
32
{
33
foreach
(
$values
as $name => $value)
34
{
35
$this->
set
($name, $value);
36
}
37
}
38
39
public
function
set
($name, $value =
null
)
40
{
41
if
(!array_key_exists($name, $this->values))
42
{
43
throw
new
ArgumentException
(
"Unknown filter \"$name\""
);
44
}
45
46
if
($value ===
'all'
)
47
{
48
$value =
null
;
49
}
50
51
if
($name ==
'period'
)
52
{
53
$this->
setPeriod
($value);
54
}
55
56
$this->values[$name] = $value;
57
}
58
59
public
function
get
($name)
60
{
61
if
(!array_key_exists($name, $this->values))
62
{
63
throw
new
ArgumentException
(
"Unknown filter \"$name\""
);
64
}
65
66
return
$this->values[$name];
67
}
68
69
public
function
getNames
()
70
{
71
return
array_keys($this->values);
72
}
73
74
public
function
getMappedArray
(array $map, array $filter = array())
75
{
76
foreach
($map as $name => $mappedName)
77
{
78
if
(!array_key_exists($name, $this->values))
79
{
80
throw
new
ArgumentException
(
"Unknown filter \"$name\""
);
81
}
82
83
if
(!$this->values[$name])
84
{
85
if
(isset($filter[$mappedName]))
86
{
87
unset($filter[$mappedName]);
88
}
89
90
continue
;
91
}
92
93
$filter[$mappedName] = $this->values[$name];
94
}
95
96
return
$filter;
97
}
98
99
public
function
clear
()
100
{
101
foreach
($this->values as $name => $value)
102
{
103
$this->values[$name] =
null
;
104
}
105
}
106
107
protected
function
setPeriod
($period = self::PERIOD_MONTH)
108
{
109
$date =
new
DateTime
();
110
$date->add(
'-'
. $period .
' DAY'
);
111
$this->
set
(
'periodFrom'
, $date);
112
$this->
set
(
'periodTo'
);
113
}
114
}
115
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\Sender\Stat\Filter
Definition
filter.php:14
Bitrix\Sender\Stat\Filter\__construct
__construct(array $values=array())
Definition
filter.php:31
Bitrix\Sender\Stat\Filter\setPeriod
setPeriod($period=self::PERIOD_MONTH)
Definition
filter.php:107
Bitrix\Sender\Stat\Filter\getNames
getNames()
Definition
filter.php:69
Bitrix\Sender\Stat\Filter\PERIOD_MONTH
CONST PERIOD_MONTH
Definition
filter.php:16
Bitrix\Sender\Stat\Filter\clear
clear()
Definition
filter.php:99
Bitrix\Sender\Stat\Filter\PERIOD_MONTH_12
CONST PERIOD_MONTH_12
Definition
filter.php:19
Bitrix\Sender\Stat\Filter\PERIOD_MONTH_6
CONST PERIOD_MONTH_6
Definition
filter.php:18
Bitrix\Sender\Stat\Filter\getMappedArray
getMappedArray(array $map, array $filter=array())
Definition
filter.php:74
Bitrix\Sender\Stat\Filter\PERIOD_MONTH_3
CONST PERIOD_MONTH_3
Definition
filter.php:17
Bitrix\Sender\Stat\Filter\PERIOD_WEEK
CONST PERIOD_WEEK
Definition
filter.php:15
Bitrix\Sender\Stat\Filter\$values
$values
Definition
filter.php:21
Bitrix\Sender\Stat
Definition
filter.php:8
modules
sender
lib
stat
filter.php
Создано системой
1.10.0