8namespace Bitrix\Sender\Entity;
10use Bitrix\Main\Application;
12use Bitrix\Main\Localization\Loc;
13use Bitrix\Main\Type\DateTime;
14use Bitrix\Sender\Connector;
15use Bitrix\Sender\ContactTable;
16use Bitrix\Sender\GroupConnectorTable;
17use Bitrix\Sender\GroupDealCategoryTable;
18use Bitrix\Sender\GroupTable;
19use Bitrix\Sender\Internals\Model\GroupCounterTable;
20use Bitrix\Sender\Internals\SqlBatch;
21use Bitrix\Sender\ListTable;
22use Bitrix\Sender\Posting\SegmentDataBuilder;
25Loc::loadMessages(__FILE__);
26Loc::loadMessages(__DIR__ .
'/letter.php');
43 $id = self::getIdByCode(self::CODE_ALL);
60 $row = self::getList(
array(
61 'select' =>
array(
'ID'),
64 'cache' =>
array(
'ttl' => 36000)
67 return $row ? $row[
'ID'] :
null;
90 'ENDPOINTS' =>
array(),
103 if (!is_array(
$data))
114 while($groupConnector = $groupConnectorDb->fetch())
116 if(empty($groupConnector[
'ENDPOINT']) || !is_array($groupConnector[
'ENDPOINT']))
121 $groupConnector[
'ENDPOINT'][
'FILTER_ID'] = $groupConnector[
'FILTER_ID'];
122 $data[
'ENDPOINTS'][] = $groupConnector[
'ENDPOINT'];
137 $endpoints =
$data[
'ENDPOINTS'];
138 unset(
$data[
'ENDPOINTS']);
141 && isset(
$data[
'STATUS'])
153 $dataCounters =
array();
158 foreach ($endpoints as $endpoint)
171 $connector->setFieldValues(is_array($endpoint[
'FIELDS']) ? $endpoint[
'FIELDS'] :
null);
172 $endpoint[
'FIELDS'] =
$connector->getFieldValues();
175 foreach (array_intersect($statFields, array_keys($endpoint[
'FIELDS'])) as $field)
181 $dataCounter = $isIncrementally
185 $groupConnector =
array(
188 'ENDPOINT' => $endpoint,
189 'ADDRESS_COUNT' => $dataCounter->getSummary()
192 if(isset($endpoint[
'FILTER_ID']))
194 $groupConnector[
'FILTER_ID'] = $endpoint[
'FILTER_ID'];
198 if($connectorResultDb->isSuccess())
200 $dataCounters[] = $dataCounter;
208 SegmentDataBuilder::actualize($id,
true);
211 SegmentDataBuilder::checkIsSegmentPrepared($id);
218 private function updateDealCategory(
int $groupId,
$connector)
220 $groupDealCategory = [];
222 foreach (
$connector->getFieldValues() as $fieldKey => $fieldValue)
224 if($fieldKey !=
'DEAL_CATEGORY_ID')
230 foreach ($fieldValue as $dealCategory)
232 $groupDealCategory[] = [
233 'GROUP_ID' => $groupId,
234 'DEAL_CATEGORY_ID' => $dealCategory
239 if(!empty($groupDealCategory))
252 return $this->
get(
'HIDDEN') ===
'Y';
262 return $this->
get(
'IS_SYSTEM') ===
'Y';
272 return $this->isFilterOnly;
306 $this->errors->setError(
new Error(
'Wrong contact set ID.'));
310 $this->data[
'ENDPOINTS'][] = [
311 'MODULE_ID' =>
'sender',
312 'CODE' =>
'contact_list',
314 'LIST_ID' => $contactSetId,
315 'SENDER_SELECT_ALL' =>
null,
328 foreach ($this->data[
'ENDPOINTS'] as $endpoint)
330 if ($endpoint[
'MODULE_ID'] !==
'sender' || $endpoint[
'CODE'] !==
'contact_list')
335 if (empty($endpoint[
'FIELDS'][
'LIST_ID']))
340 return $endpoint[
'FIELDS'][
'LIST_ID'];
363 $this->errors->setError(
new Error(
'Contact set not found.'));
387 $countByType =
array();
390 $count += $dataCounter->getSummary();
391 $list = $dataCounter->getList();
392 foreach ($list as $typeId => $typeCount)
394 if (!isset($countByType[$typeId]))
396 $countByType[$typeId] = 0;
399 $countByType[$typeId] += $typeCount;
410 GroupCounterTable::deleteByGroupId($segmentId);
412 foreach ($countByType as $typeId => $typeCount)
420 'GROUP_ID' => $segmentId,
421 'TYPE_ID' => $typeId,
426 SqlBatch::insert(GroupCounterTable::getTableName(), $insertRows);
439 $data = self::getAddressCounters(
array($segmentId));
452 $list = GroupCounterTable::getList(
array(
453 'select' =>
array(
'GROUP_ID',
'TYPE_ID',
'CNT'),
454 'filter' =>
array(
'=GROUP_ID' => $list),
455 'order' =>
array(
'GROUP_ID' =>
'ASC')
457 foreach ($list as $row)
459 $data[$row[
'GROUP_ID']][$row[
'TYPE_ID']] = $row[
'CNT'];
473 if (
count($list) === 0)
479 $now = Application::getConnection()->getSqlHelper()->convertToDbDateTime(
new DateTime());
481 foreach ($list as $element)
483 $id = $element[
'ID'];
484 if (!$id || !is_numeric($id))
497 $ids = implode(
', ', $ids);
498 $postfix = $isInclude ?
'' :
'_EXCLUDE';
500 $sql =
"UPDATE $tableName SET USE_COUNT$postfix = USE_COUNT$postfix + 1, DATE_USE$postfix = $now WHERE ID IN ($ids)";
501 Application::getConnection()->query($sql);
509 public function remove()
523 return $this->copyData(
526 'NAME' => Loc::getMessage(
'SENDER_ENTITY_LETTER_COPY_PREFIX') .
' ' .
$data[
'NAME'],
531 'USE_COUNT_EXCLUDE' => 0,
static getRowById($id, array $parameters=[])
static getList(array $parameters=array())
static addMulti($rows, $ignoreEvents=false)
static update($primary, array $data)
static getConnector(array $endpoint)
static updateUseCounters(array $list, $isInclude=true)
static getList(array $parameters=array())
static getAddressCounters(array $list)
static getAddressCounter($segmentId)
static getIdByCode($code)
setFilterOnlyMode($mode=true)
static updateAddressCounters($segmentId, array $counters)
appendContactSetConnector($contactSetId=null)
saveData($id, array $data)
static deleteList(array $filter)
static stat($event, $tag='', $label='')
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"