8namespace Bitrix\Sender\Stat;
10use Bitrix\Main\Application;
11use Bitrix\Main\Context;
12use Bitrix\Main\Entity\ExpressionField;
13use Bitrix\Main\Localization\Loc;
14use Bitrix\Main\Type\Date;
15use Bitrix\Main\UserTable;
16use Bitrix\Main\Web\Uri;
17use Bitrix\Sender\Entity;
18use Bitrix\Sender\MailingChainTable;
19use Bitrix\Sender\MailingSubscriptionTable;
20use Bitrix\Sender\Message;
21use Bitrix\Sender\PostingClickTable;
22use Bitrix\Sender\PostingTable;
24Loc::loadMessages(__FILE__);
136 $request = Context::getCurrent()->getRequest();
139 $list = $this->
filter->getNames();
140 foreach ($list as
$name)
162 $isFilterSet =
false;
165 $userOptionFilters = \CUserOptions::getOption(
167 self::USER_OPTION_FILTER_NAME,
172 $list = $this->
filter->getNames();
173 foreach ($list as
$name)
176 !isset($userOptionFilters[
$name])
177 || !$userOptionFilters[
$name]
178 || !$this->checkFilterValue($userOptionFilters[
$name])
194 if (!$isFilterSet && !$this->
filter->get(
'period'))
196 $this->
filter->set(
'period', Filter::PERIOD_MONTH);
202 private function checkFilterValue(
$filter)
216 $list = $this->
filter->getNames();
217 foreach ($list as
$name)
228 \CUserOptions::setOption(
'sender', self::USER_OPTION_FILTER_NAME,
$filter,
false, $this->userId);
236 $maxEfficiency = self::AVERAGE_EFFICIENCY * 2;
238 $efficiency = $efficiency > $maxEfficiency ? $maxEfficiency : $efficiency;
242 protected static function div($dividendCode, $dividerCode,
$items)
247 if ($item[
'CODE'] == $dividerCode)
249 $divider = (float) $item[
'VALUE'];
262 if ($item[
'CODE'] == $dividendCode)
264 $dividend = (float) $item[
'VALUE'];
265 $dividend = $dividend > $divider ? $divider : $dividend;
270 return $dividend / $divider;
275 $formatted = number_format($number, $num,
'.',
' ');
276 $formatted = mb_substr($formatted, -($num + 1)) ==
'.'.str_repeat(
'0', $num)? mb_substr($formatted, 0, -2) : $formatted;
282 $value = (float) $value;
283 $percentValue = $percentBase > 0 ? $value / $percentBase : 0;
287 'VALUE' => round($value, 3),
288 'VALUE_DISPLAY' => self::formatNumber($value),
289 'PERCENT_VALUE' => round($percentValue, 3),
290 'PERCENT_VALUE_DISPLAY' => self::formatNumber($percentValue * 100),
298 '=MAILING.IS_TRIGGER' =>
'N',
299 '=MAILING_CHAIN.MESSAGE_CODE' =>
Message\iBase::CODE_MAIL
303 'chainId' =>
'=MAILING_CHAIN_ID',
304 'periodFrom' =>
'>DATE_SENT',
305 'periodTo' =>
'<DATE_SENT',
306 'mailingId' =>
'=MAILING_ID',
307 'postingId' =>
'=ID',
308 'authorId' =>
'=MAILING_CHAIN.CREATED_BY',
328 public function getCountersDynamic()
333 'SEND_ALL' =>
'COUNT_SEND_ALL',
334 'SEND_ERROR' =>
'COUNT_SEND_ERROR',
335 'SEND_SUCCESS' =>
'COUNT_SEND_SUCCESS',
336 'READ' =>
'COUNT_READ',
337 'CLICK' =>
'COUNT_CLICK',
338 'UNSUB' =>
'COUNT_UNSUB'
340 $sqlHelper = Application::getConnection()->getSqlHelper();
343 new ExpressionField(
'DATE', $sqlHelper->getDatetimeToDateFunction(
'%s'),
'DATE_SENT'),
345 foreach (
$select as $alias => $fieldName)
355 'runtime' => $runtime,
356 'order' =>
array(
'DATE' =>
'ASC'),
359 while($item = $listDb->fetch())
362 foreach ($item as
$name => $value)
372 $date = $item[
'DATE']->getTimestamp();
377 foreach ($item as
$name => $value)
379 if (!in_array(
$name,
array(
'READ',
'CLICK',
'UNSUB')))
385 $base = $item[
'SEND_SUCCESS'];
395 $effCounter[
'DATE'] = $date;
396 $list[
'EFFICIENCY'][] = $effCounter;
410 if ($this->counters !==
null)
418 'SEND_ALL' =>
'COUNT_SEND_ALL',
419 'SEND_ERROR' =>
'COUNT_SEND_ERROR',
420 'SEND_SUCCESS' =>
'COUNT_SEND_SUCCESS',
421 'READ' =>
'COUNT_READ',
422 'CLICK' =>
'COUNT_CLICK',
423 'UNSUB' =>
'COUNT_UNSUB'
426 foreach (
$select as $alias => $fieldName)
431 'select' => array_keys(
$select),
433 'runtime' => $runtime,
436 while ($item = $listDb->fetch())
441 $this->counters = $list;
448 'SEND_ALL' => (int)$postingData[
'COUNT_SEND_ALL'],
449 'SEND_ERROR' => (
int)$postingData[
'COUNT_SEND_ERROR'],
450 'SEND_SUCCESS' => (int)$postingData[
'COUNT_SEND_SUCCESS'],
451 'READ' => (
int)$postingData[
'COUNT_READ'],
452 'CLICK' => (int)$postingData[
'COUNT_CLICK'],
453 'UNSUB' => (
int)$postingData[
'COUNT_UNSUB']
463 foreach ($item as
$name => $value)
465 if (mb_substr(
$name, 0, 4) ==
'SEND')
467 $base = $item[
'SEND_ALL'];
471 $base = $item[
'SEND_SUCCESS'];
504 'mailingId' =>
'=MAILING_ID',
505 'periodFrom' =>
'>DATE_INSERT',
506 'periodTo' =>
'<DATE_INSERT',
530 'select' =>
array(
'URL',
'CNT'),
532 '=POSTING_ID' => $this->
filter->get(
'postingId'),
537 'group' =>
array(
'URL'),
538 'order' =>
array(
'CNT' =>
'DESC'),
541 while($click = $clickDb->fetch())
550 $linkParams = $letter->getMessage()->getConfiguration()->get(
'LINK_PARAMS');
557 parse_str($linkParams, $parametersTmp);
558 if (!is_array($parametersTmp) || empty($parametersTmp))
562 $linkParams = array_keys($parametersTmp);
565 foreach ($list as $index => $item)
567 $item[
'URL'] = (
new Uri($item[
'URL']))
568 ->deleteParams($linkParams,
true)
570 $item[
'URL'] = urldecode($item[
'URL']);
571 if (!isset($groupedList[$item[
'URL']]))
573 $groupedList[$item[
'URL']] = 0;
575 $groupedList[$item[
'URL']] += $item[
'CNT'];
578 foreach ($groupedList as
$url => $cnt)
580 $list[] = [
'URL' =>
$url,
'CNT' => $cnt];
596 for (
$i = 0;
$i < 24;
$i++)
602 'DAY_HOUR_DISPLAY' => (mb_strlen(
$i) == 1 ?
'0' :
'') .
$i .
':00',
608 'select' =>
array(
'DAY_HOUR',
'CNT'),
612 new ExpressionField(
'DAY_HOUR',
'HOUR(%s)',
'POSTING_READ.DATE_INSERT'),
614 'order' =>
array(
'DAY_HOUR' =>
'ASC'),
616 while($read = $readDb->fetch())
618 $read[
'DAY_HOUR'] = intval($read[
'DAY_HOUR']);
619 if (array_key_exists($read[
'DAY_HOUR'], $list))
621 $list[$read[
'DAY_HOUR']][
'CNT'] = $read[
'CNT'];
628 for (
$i = 0;
$i < 24;
$i+=$step)
630 for ($j = 1; $j < $step; $j++)
632 $list[
$i][
'CNT'] += $list[
$i + $j][
'CNT'];
633 unset($list[
$i + $j]);
639 $list = array_values($list);
653 $len =
count($timeList);
654 $weightList =
array();
655 for (
$i = 0;
$i <= $len;
$i++)
666 $weight = $timeList[
$i][
'CNT'] + $timeList[$j][
'CNT'];
667 $weightList[
$i] = $weight;
674 'select' =>
array(
'COUNT_SEND_ALL'),
676 '=MAILING_CHAIN_ID' => $chainId
678 'order' =>
array(
'DATE_CREATE' =>
'DESC'),
680 if ($item = $listDb->fetch())
682 $deliveryTime = intval($item[
'COUNT_SEND_ALL'] * 1/10 * 1/3600);
685 if ($deliveryTime <= 0)
691 foreach ($weightList as
$i => $weight)
702 $timeList[
$i][
'DELIVERY_TIME'] = $deliveryTime;
703 return $timeList[
$i];
721 'CHAIN_ID' =>
'MAILING_CHAIN_ID',
722 'TITLE' =>
'MAILING_CHAIN.TITLE',
724 'MAILING_NAME' =>
'MAILING.NAME',
731 'order' =>
array(
'MAX_DATE_SENT' =>
'DESC'),
736 while ($item = $listDb->fetch())
738 $dateSentFormatted =
'';
739 if ($item[
'MAX_DATE_SENT'])
741 $dateSentFormatted =
\FormatDate(
'x', $item[
'MAX_DATE_SENT']->getTimestamp());
745 'ID' => $item[
'CHAIN_ID'],
746 'NAME' => $item[
'TITLE'] ? $item[
'TITLE'] : $item[
'SUBJECT'],
747 'MAILING_ID' => $item[
'MAILING_ID'],
748 'MAILING_NAME' => $item[
'MAILING_NAME'],
749 'DATE_SENT' => (
string) $item[
'MAX_DATE_SENT'],
750 'DATE_SENT_FORMATTED' => $dateSentFormatted,
763 $period = $this->
getFilter()->get(
'period');
767 'name' =>
'authorId',
768 'value' => $this->
getFilter()->
get(
'authorId'),
769 'list' => $this->getAuthorList(),
773 'value' => $period ? $period : Filter::PERIOD_MONTH,
788 Filter::PERIOD_MONTH,
789 Filter::PERIOD_MONTH_3,
790 Filter::PERIOD_MONTH_6,
791 Filter::PERIOD_MONTH_12
795 foreach ($list as $period)
799 'NAME' => Loc::getMessage(
'SENDER_STAT_STATISTICS_FILTER_PERIOD_' . $period)
811 protected function getAuthorList()
814 'select' => [
'CREATED_BY',
'MAX_DATE_INSERT'],
815 'group' => [
'CREATED_BY'],
816 'runtime' => [
new ExpressionField(
'MAX_DATE_INSERT',
'MAX(%s)',
'DATE_INSERT'),],
818 'order' => [
'MAX_DATE_INSERT' =>
'DESC'],
819 'cache' => [
'ttl' => $this->
getCacheTtl(),
'cache_joins' =>
true]
822 while ($item = $listDb->fetch())
824 if (!$item[
'CREATED_BY'])
835 'NAME' => Loc::getMessage(
'SENDER_STAT_STATISTICS_FILTER_AUTHOR_FROM_ALL')
843 'ID' =>
$USER->getID(),
844 'NAME' => Loc::getMessage(
'SENDER_STAT_STATISTICS_FILTER_AUTHOR_FROM_ME')
848 $listDb = UserTable::getList(
array(
858 'order' =>
array(
'NAME' =>
'ASC')
860 while ($item = $listDb->fetch())
862 $name = \CUser::formatName(\CSite::getNameFormat(
true), $item,
true,
true);
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
static getList(array $parameters=array())
static createInstanceByPostingId($postingId)
initFromArray($postingData)
createListFromItem($item)
static getCounterCalculation($code, $value, $percentBase=0)
static calculateEfficiency($counters, $maxEfficiency=null)
__construct(Filter $filter=null)
static create(Filter $filter=null)
static formatNumber($number, $num=1)
filter($name, $value=null)
static div($dividendCode, $dividerCode, $items)
CONST USER_OPTION_FILTER_NAME
initFilterFromUserOption()
getReadingByDayTime($step=2)
getRecommendedSendTime($chainId=null)
</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
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
</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."%"