12use Bitrix\Main\Entity\ExpressionField;
123 public function filter($name, $value =
null)
125 $this->
filter->set($name, $value);
137 if ($request->isPost())
139 $list = $this->
filter->getNames();
140 foreach ($list as $name)
142 $this->
filter->set($name, (
string) $request->get($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])
185 $this->
filter->set($name, (
string) $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)
219 $value = $this->
filter->get($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)
245 foreach ($items as $item)
247 if ($item[
'CODE'] == $dividerCode)
249 $divider = (float) $item[
'VALUE'];
260 foreach ($items as $item)
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'
343 new ExpressionField(
'DATE', $sqlHelper->getDatetimeToDateFunction(
'%s'),
'DATE_SENT'),
345 foreach ($select as $alias => $fieldName)
349 $select = array_keys($select);
352 $listDb = PostingTable::getList(array(
355 'runtime' => $runtime,
356 'order' => array(
'DATE' =>
'ASC'),
357 'cache' => array(
'ttl' => $this->
getCacheTtl(),
'cache_joins' =>
true)
359 while($item = $listDb->fetch())
362 foreach ($item as $name => $value)
364 if (!in_array($name, array(
'DATE')))
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'];
389 $counter[
'DATE'] = $date;
391 $list[$name][] = $counter;
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)
430 $listDb = PostingTable::getList(array(
431 'select' => array_keys($select),
433 'runtime' => $runtime,
434 'cache' => array(
'ttl' => $this->
getCacheTtl(),
'cache_joins' =>
true)
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'];
485 $query = PostingTable::query();
489 $query->cacheJoins(
true);
490 $result = $query->exec()->fetch();
502 $filter = array(
'=IS_UNSUB' =>
'N');
504 'mailingId' =>
'=MAILING_ID',
505 'periodFrom' =>
'>DATE_INSERT',
506 'periodTo' =>
'<DATE_INSERT',
510 $query = MailingSubscriptionTable::query();
514 $query->cacheJoins(
true);
515 $result = $query->exec()->fetch();
529 $clickDb = PostingClickTable::getList(array(
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())
549 $letter = Entity\Letter::createInstanceByPostingId($this->
filter->get(
'postingId'));
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',
607 $readDb = PostingTable::getList(array(
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;
673 $listDb = PostingTable::getList(array(
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];
718 $listDb = PostingTable::getList(array(
721 'CHAIN_ID' =>
'MAILING_CHAIN_ID',
722 'TITLE' =>
'MAILING_CHAIN.TITLE',
724 'MAILING_NAME' =>
'MAILING.NAME',
731 'order' => array(
'MAX_DATE_SENT' =>
'DESC'),
733 'cache' => array(
'ttl' => $this->
getCacheTtl(),
'cache_joins' =>
true)
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()
813 $listDb = MailingChainTable::getList(array(
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'])
829 $userList[] = $item[
'CREATED_BY'];
835 'NAME' =>
Loc::getMessage(
'SENDER_STAT_STATISTICS_FILTER_AUTHOR_FROM_ALL')
840 if (is_object($USER) && $USER->getID())
843 'ID' => $USER->getID(),
844 'NAME' =>
Loc::getMessage(
'SENDER_STAT_STATISTICS_FILTER_AUTHOR_FROM_ME')
848 $listDb = UserTable::getList(array(
857 'filter' => array(
'=ID' => $userList),
858 'order' => array(
'NAME' =>
'ASC')
860 while ($item = $listDb->fetch())
862 $name = \CUser::formatName(\CSite::getNameFormat(
true), $item,
true,
true);
static getConnection($name="")
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
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)