Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
campaign.php
1
<?php
8
namespace
Bitrix\Sender\Entity
;
9
10
use
Bitrix\Main\Localization\Loc
;
11
use
Bitrix\Main\SiteTable
;
12
use Bitrix\Main\Entity\ExpressionField;
13
14
use
Bitrix\Sender\MailingTable
;
15
16
Loc::loadMessages
(__FILE__);
17
22
class
Campaign
extends
Base
23
{
25
private
static
$defaultId;
26
27
private
static
$defaultSiteId;
28
35
public
static
function
getList
(array $parameters = array())
36
{
37
if
(!isset($parameters[
'filter'
]))
38
{
39
$parameters[
'filter'
] = [];
40
}
41
if
(!isset($parameters[
'select'
]))
42
{
43
$parameters[
'select'
] = [
'*'
,
'SUBSCRIBER_COUNT'
];
44
}
45
$parameters[
'filter'
][
'=IS_TRIGGER'
] =
'N'
;
46
if
(in_array(
'SUBSCRIBER_COUNT'
, $parameters[
'select'
]))
47
{
48
$parameters[
'runtime'
][] =
new
ExpressionField
(
'SUBSCRIBER_COUNT'
,
'COUNT(DISTINCT %s)'
,
'SUBSCRIBER.CONTACT_ID'
);
49
}
50
51
return
MailingTable::getList($parameters);
52
}
53
63
public
static
function
getDefaultId
($siteId =
null
)
64
{
65
if
($siteId !==
null
)
66
{
67
if
(!SiteTable::getList([
68
'filter'
=> [
'ACTIVE'
=>
'Y'
,
'LID'
=> $siteId],
69
'cache'
=> [
'ttl'
=> 3600],
70
])->fetch())
71
{
72
$siteId =
null
;
73
}
74
}
75
if
($siteId ===
null
)
76
{
77
if
(!self::$defaultSiteId)
78
{
79
$defaultSite = SiteTable::getRow([
'select'
=> [
'ID'
],
'filter'
=> [
'=DEF'
=>
'Y'
]]);
80
self::$defaultSiteId = ($defaultSite ? $defaultSite[
'ID'
] : SITE_ID);
81
}
82
$siteId = self::$defaultSiteId;
83
}
84
85
if
(isset(self::$defaultId[$siteId]))
86
{
87
return
self::$defaultId[$siteId];
88
}
89
90
$row = MailingTable::getRow(array(
91
'select'
=> array(
'ID'
),
92
'filter'
=> array(
'=ACTIVE'
=>
'Y'
,
'=IS_TRIGGER'
=>
'N'
,
'SITE_ID'
=> $siteId),
93
'limit'
=> 1,
94
'order'
=> array(
'ID'
=>
'DESC'
)
95
));
96
if
($row)
97
{
98
self::$defaultId[$siteId] = $row[
'ID'
];
99
return
self::$defaultId[$siteId];
100
}
101
102
$result = MailingTable::add(array(
103
'NAME'
=>
Loc::getMessage
(
'SENDER_ENTITY_CAMPAIGN_NAME_DEFAULT'
),
104
'SITE_ID'
=> $siteId
105
));
106
if
($result->isSuccess())
107
{
108
self::$defaultId[$siteId] = $result->getId();
109
}
110
111
return
self::$defaultId[$siteId];
112
}
113
119
public
static
function
getSites
()
120
{
121
static
$sites =
null
;
122
if
($sites ===
null
)
123
{
124
$sites = SiteTable::getList([
'select'
=> [
'LID'
,
'NAME'
]])->fetchAll();
125
$sites = array_combine(
126
array_column($sites,
'LID'
),
127
array_column($sites,
'NAME'
)
128
);
129
}
130
131
return
$sites;
132
}
133
139
protected
function
getDefaultData
()
140
{
141
return
[
142
'NAME'
=>
''
,
143
'SITE_ID'
=> SITE_ID,
144
'ACTIVE'
=>
'Y'
,
145
'IS_PUBLIC'
=>
'Y'
,
146
];
147
}
148
156
protected
function
saveData
($id, array $data)
157
{
158
$this->filterDataByEntityFields(MailingTable::getEntity(), $data);
159
return
$this->saveByEntity(MailingTable::getEntity(), $id, $data);
160
}
161
168
public
function
loadData
($id)
169
{
170
return
static::getList([
'filter'
=> [
'=ID'
=> $id],
'limit'
=> 1])->fetch();
171
}
172
178
public
function
getSiteId
()
179
{
180
return
$this->
get
(
'SITE_ID'
) ?: SITE_ID;
181
}
182
188
public
function
getSiteName
()
189
{
190
$sites =
self::getSites
();
191
return
$this->
get
(
'SITE_ID'
) ? $sites[$this->
get
(
'SITE_ID'
)] :
null
;
192
}
193
199
public
function
getSubscriberCount
()
200
{
201
return
(
int
) $this->
get
(
'SUBSCRIBER_COUNT'
) ?: 0;
202
}
203
210
public
function
activate
($isActivate =
true
)
211
{
212
$this->
set
(
'ACTIVE'
, $isActivate ?
'Y'
:
'N'
);
213
$this->save();
214
215
/*
216
$result = MailingTable::update($this->getId(), ['ACTIVE' => $isActivate ? 'Y' : 'N']);
217
if ($result->isSuccess())
218
{
219
$this->set('ACTIVE', 'Y');
220
}
221
else
222
{
223
$this->errors->add($result->getErrors());
224
}
225
*/
226
227
return
$this;
228
}
229
235
public
function
deactivate
()
236
{
237
$this->
activate
(
false
);
238
return
$this;
239
}
240
246
public
function
remove
()
247
{
248
return
$this->removeByEntity(MailingTable::getEntity(), $this->
getId
());
249
}
250
257
public
static
function
removeById
($id)
258
{
259
return
static::create()->removeByEntity(MailingTable::getEntity(), $id);
260
}
261
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Fields\ExpressionField
Definition
expressionfield.php:25
Bitrix\Main\SiteTable
Definition
site.php:32
Bitrix\Sender\Connector\Base
Definition
base.php:13
Bitrix\Sender\Connector\Base\getId
getId()
Definition
base.php:206
Bitrix\Sender\Entity\Campaign
Definition
campaign.php:23
Bitrix\Sender\Entity\Campaign\getSiteId
getSiteId()
Definition
campaign.php:178
Bitrix\Sender\Entity\Campaign\activate
activate($isActivate=true)
Definition
campaign.php:210
Bitrix\Sender\Entity\Campaign\getList
static getList(array $parameters=array())
Definition
campaign.php:35
Bitrix\Sender\Entity\Campaign\loadData
loadData($id)
Definition
campaign.php:168
Bitrix\Sender\Entity\Campaign\deactivate
deactivate()
Definition
campaign.php:235
Bitrix\Sender\Entity\Campaign\getSites
static getSites()
Definition
campaign.php:119
Bitrix\Sender\Entity\Campaign\getDefaultId
static getDefaultId($siteId=null)
Definition
campaign.php:63
Bitrix\Sender\Entity\Campaign\getDefaultData
getDefaultData()
Definition
campaign.php:139
Bitrix\Sender\Entity\Campaign\getSiteName
getSiteName()
Definition
campaign.php:188
Bitrix\Sender\Entity\Campaign\removeById
static removeById($id)
Definition
campaign.php:257
Bitrix\Sender\Entity\Campaign\getSubscriberCount
getSubscriberCount()
Definition
campaign.php:199
Bitrix\Sender\Entity\Campaign\saveData
saveData($id, array $data)
Definition
campaign.php:156
Bitrix\Sender\MailingTable
Definition
mailing.php:21
Bitrix\Sender\Entity
Definition
ad.php:8
modules
sender
lib
entity
campaign.php
Создано системой
1.10.0