1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
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
{
80
$defaultSite = SiteTable::getRow([
81
'select'
=> [
'LID'
,
'LANGUAGE_ID'
],
82
'filter'
=> [
'=DEF'
=>
'Y'
,
'=ACTIVE'
=>
'Y'
],
83
'cache'
=> [
'ttl'
=> 86400],
84
]);
85
self::$defaultSiteId = ($defaultSite ? $defaultSite[
'LID'
] :
SITE_ID
);
86
}
87
$siteId
= self::$defaultSiteId;
88
}
89
90
if
(isset(self::$defaultId[
$siteId
]))
91
{
92
return
self::$defaultId[
$siteId
];
93
}
94
95
$row =
MailingTable::getRow
(
array
(
96
'select'
=>
array
(
'ID'
),
97
'filter'
=>
array
(
'=ACTIVE'
=>
'Y'
,
'=IS_TRIGGER'
=>
'N'
,
'SITE_ID'
=>
$siteId
),
98
'limit'
=> 1,
99
'order'
=>
array
(
'ID'
=>
'DESC'
)
100
));
101
if
($row)
102
{
103
self::$defaultId[
$siteId
] = $row[
'ID'
];
104
return
self::$defaultId[
$siteId
];
105
}
106
107
$result
=
MailingTable::add
(
array
(
108
'NAME'
=> Loc::getMessage(
'SENDER_ENTITY_CAMPAIGN_NAME_DEFAULT'
),
109
'SITE_ID'
=>
$siteId
110
));
111
if
(
$result
->isSuccess())
112
{
113
self::$defaultId[
$siteId
] =
$result
->getId();
114
}
115
116
return
self::$defaultId[
$siteId
];
117
}
118
124
public
static
function
getSites
()
125
{
126
static
$sites
=
null
;
127
if
(
$sites
===
null
)
128
{
129
$sites
= SiteTable::getList([
'select'
=> [
'LID'
,
'NAME'
]])->fetchAll();
130
$sites
= array_combine(
131
array_column(
$sites
,
'LID'
),
132
array_column(
$sites
,
'NAME'
)
133
);
134
}
135
136
return
$sites
;
137
}
138
144
protected
function
getDefaultData
()
145
{
146
return
[
147
'NAME'
=>
''
,
148
'SITE_ID'
=>
SITE_ID
,
149
'ACTIVE'
=>
'Y'
,
150
'IS_PUBLIC'
=>
'Y'
,
151
];
152
}
153
161
protected
function
saveData
($id,
array
$data
)
162
{
163
$this->filterDataByEntityFields(
MailingTable::getEntity
(),
$data
);
164
return
$this->saveByEntity(
MailingTable::getEntity
(), $id,
$data
);
165
}
166
173
public
function
loadData
($id)
174
{
175
return
static::getList([
'filter'
=> [
'=ID'
=> $id],
'limit'
=> 1])->fetch();
176
}
177
183
public
function
getSiteId
()
184
{
185
return
$this->
get
(
'SITE_ID'
) ?:
SITE_ID
;
186
}
187
193
public
function
getSiteName
()
194
{
195
$sites
=
self::getSites
();
196
return
$this->
get
(
'SITE_ID'
) ?
$sites
[$this->
get
(
'SITE_ID'
)] :
null
;
197
}
198
204
public
function
getSubscriberCount
()
205
{
206
return
(
int
) $this->
get
(
'SUBSCRIBER_COUNT'
) ?: 0;
207
}
208
215
public
function
activate
($isActivate =
true
)
216
{
217
$this->
set
(
'ACTIVE'
, $isActivate ?
'Y'
:
'N'
);
218
$this->save();
219
220
/*
221
$result = MailingTable::update($this->getId(), ['ACTIVE' => $isActivate ? 'Y' : 'N']);
222
if ($result->isSuccess())
223
{
224
$this->set('ACTIVE', 'Y');
225
}
226
else
227
{
228
$this->errors->add($result->getErrors());
229
}
230
*/
231
232
return
$this;
233
}
234
240
public
function
deactivate
()
241
{
242
$this->
activate
(
false
);
243
return
$this;
244
}
245
251
public
function
remove
()
252
{
253
return
$this->removeByEntity(
MailingTable::getEntity
(), $this->
getId
());
254
}
255
262
public
static
function
removeById
($id)
263
{
264
return
static::create()->removeByEntity(
MailingTable::getEntity
(), $id);
265
}
266
}
Bitrix\Main\ORM\Data\DataManager\getEntity
static getEntity()
Определения
datamanager.php:65
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Определения
datamanager.php:398
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Определения
datamanager.php:431
Bitrix\Main\ORM\Data\DataManager\add
static add(array $data)
Определения
datamanager.php:877
Bitrix\Main\ORM\Fields\ExpressionField
Определения
expressionfield.php:25
Bitrix\Sender\Connector\Base
Определения
base.php:13
Bitrix\Sender\Connector\Base\getId
getId()
Определения
base.php:206
Bitrix\Sender\Entity\Campaign
Определения
campaign.php:23
Bitrix\Sender\Entity\Campaign\getSiteId
getSiteId()
Определения
campaign.php:183
Bitrix\Sender\Entity\Campaign\activate
activate($isActivate=true)
Определения
campaign.php:215
Bitrix\Sender\Entity\Campaign\getList
static getList(array $parameters=array())
Определения
campaign.php:35
Bitrix\Sender\Entity\Campaign\loadData
loadData($id)
Определения
campaign.php:173
Bitrix\Sender\Entity\Campaign\deactivate
deactivate()
Определения
campaign.php:240
Bitrix\Sender\Entity\Campaign\getSites
static getSites()
Определения
campaign.php:124
Bitrix\Sender\Entity\Campaign\getDefaultId
static getDefaultId($siteId=null)
Определения
campaign.php:63
Bitrix\Sender\Entity\Campaign\getDefaultData
getDefaultData()
Определения
campaign.php:144
Bitrix\Sender\Entity\Campaign\getSiteName
getSiteName()
Определения
campaign.php:193
Bitrix\Sender\Entity\Campaign\removeById
static removeById($id)
Определения
campaign.php:262
Bitrix\Sender\Entity\Campaign\getSubscriberCount
getSubscriberCount()
Определения
campaign.php:204
Bitrix\Sender\Entity\Campaign\saveData
saveData($id, array $data)
Определения
campaign.php:161
$sites
$sites
Определения
clear_component_cache.php:15
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$siteId
$siteId
Определения
ajax.php:8
SITE_ID
const SITE_ID
Определения
sonet_set_content_view.php:12
bitrix
modules
sender
lib
entity
campaign.php
Создано системой
1.14.0