1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
generatorcontext.php
См. документацию.
1<?php
2
3namespace Bitrix\Conversion;
4
5use Bitrix\Main\EventManager;
6use Bitrix\Main\Type\Date;
7use Bitrix\Main\Type\DateTime;
8use Bitrix\Main\Config\Option;
9
12{
13 private function setAttributes(array $attributes)
14 {
15 foreach ($attributes as $name => $value)
16 {
18 }
19 }
20
21 private static function appendCounters(array & $one, array $two)
22 {
23 foreach ($two as $name => $value)
24 {
25 if ($counter =& $one[$name])
26 {
27 $counter += $value;
28 }
29 else
30 {
31 $counter = $value;
32 }
33 }
34 }
35
36 private static function appendDayCounters(array & $one, array $two)
37 {
38 foreach ($two as $day => $twoCounters)
39 {
40 if ($oneCounters =& $one[$day])
41 {
42 self::appendCounters($oneCounters, $twoCounters);
43 }
44 else
45 {
46 $oneCounters = $twoCounters;
47 }
48 }
49 }
50
51 static public function generateInitialData(Date $from)
52 {
53 if ( ($to = Option::get('conversion', 'START_DATE_TIME', 'undefined')) != 'undefined'
54 && DateTime::isCorrect($to, 'Y-m-d H:i:s')
55 && ($to = new DateTime($to, 'Y-m-d H:i:s'))
56 && $to->format('Y-m-d H:i:s') > $from->format('Y-m-d H:i:s')
57 && Option::get('conversion', 'GENERATE_INITIAL_DATA', 'undefined') == 'undefined')
58 {
59 Option::set('conversion', 'GENERATE_INITIAL_DATA', 'generated');
60
61 $context = new self;
62
63 // generate data
64
65 $data = array();
66
67 foreach (EventManager::getInstance()->findEventHandlers('conversion', 'OnGenerateInitialData') as $handler)
68 {
69 $result = ExecuteModuleEventEx($handler, array($from, $to)); // TODO validate
70
71 foreach ($result as $row)
72 {
73 $context->id = null;
74 $context->attributes = array();
75 $context->setAttributes($row['ATTRIBUTES']);
76 $context->save();
77
78 if ($dayCounters =& $data[$context->id])
79 {
80 self::appendDayCounters($dayCounters, $row['DAY_COUNTERS']);
81 }
82 else
83 {
84 $dayCounters = $row['DAY_COUNTERS'];
85 }
86 }
87 }
88
89 unset($dayCounters);
90
91 // save data to database
92
93 $numerators = CounterManager::getTypes(array('GROUP' => 'day'));
94 unset($numerators['conversion_visit_day']);
95
96 foreach ($data as $id => $dayCounters)
97 {
98 $context->id = $id;
99
100 foreach ($dayCounters as $day => $counters)
101 {
102 $day = new Date($day, 'Y-m-d');
103
104 $visitSum = 0;
105 $visitQuantity = 0;
106
107 unset($counters['conversion_visit_day']);
108
109 foreach ($counters as $name => $value)
110 {
111 $context->addCounter($day, $name, $value);
112
113 if ($numerators[$name])
114 {
115 $visitSum += $value;
116 $visitQuantity += 1;
117 }
118 }
119
120 $context->addCounter($day, 'conversion_visit_day', $visitQuantity ? round($visitSum / $visitQuantity * 100) + 1 : 1);
121 }
122 }
123 }
124 }
125}
static generateInitialData(Date $from)
Определения generatorcontext.php:51
setAttribute($name, $value=null)
Определения basecontext.php:111
static getTypes(array $filter=null)
Определения typemanager.php:49
Определения date.php:9
format($format)
Определения date.php:110
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$context
Определения csv_new_setup.php:223
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
$name
Определения menu_edit.php:35
$counter
Определения options.php:5
$counters
Определения options.php:100