Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
converterobjectcolor.php
1<?php
2
3
5
6
9use \Bitrix\Main\Localization\Loc;
10use \Bitrix\Main\Update\Stepper;
11use \Bitrix\Main\Config\Option;
12use \Bitrix\Main\Loader;
13
14final class ConverterObjectColor extends Stepper
15{
16 const PORTION = 100;
17
18 protected static $moduleId = "calendar";
19
20 public static function className()
21 {
22 return get_called_class();
23 }
24
25 public function execute(array &$result)
26
27 {
28 if (Loader::includeModule("calendar")
29 && Option::get('calendar', 'needChangeColor', 'Y') === 'N')
30 {
32 }
33
34 $status = $this->loadCurrentStatus();
35
36 if ($status['finished'])
37 {
38 \CCalendar::ClearCache(['section_list', 'event_list']);
39
41 }
42
43 $newStatus = array(
44 'count' => $status['count'],
45 'steps' => $status['steps'],
46 'sectionFinished' => $status['sectionFinished'],
47 'finished' => $status['finished']
48 );
49
50 // 1. Update sections
51 if (!$status['sectionFinished'])
52 {
53 $sections = SectionTable::getList([
54 'filter' => [
55 '>ID' => $status['sectionLastId'],
56 ],
57 'limit' => self::PORTION,
58 'order' => [
59 'ID' => 'ASC',
60 ]
61 ])->fetchAll();
62
63 foreach ($sections as $section)
64 {
65 // 1. Replace colors
66 $color = self::getNewColor($section['COLOR']);
67 if (strtolower($color) != strtolower($section['COLOR']))
68 {
69 \CCalendarSect::Edit(array(
70 'arFields' => array(
71 'ID' => $section['ID'],
72 'COLOR' => $color
73 )
74 ));
75 }
76 $newStatus['sectionLastId'] = $section['ID'];
77 $newStatus['steps']++;
78 }
79
80
81 if (!empty($newStatus['sectionLastId']))
82 {
83 Option::set('calendar', 'changecolor', serialize($newStatus));
84
86 }
87
88 $newStatus['sectionFinished'] = true;
89 Option::set('calendar', 'eventindex', serialize($newStatus));
90 }
91
92 // 2. Update events
93 $events = EventTable::getList([
94 'filter' => [
95 '>ID' =>$status['eventLastId'] ?? null,
96 'DELETED' => 'N',
97 ],
98 'order' => [
99 'ID' => 'ASC',
100 ],
101 'limit' => self::PORTION,
102
103 ])->fetchAll();
104
105 foreach ($events as $event)
106 {
107 // 1. Replace colors
108 $color = self::getNewColor($event['COLOR']);
109 if (strtolower($color) != strtolower($event['COLOR']))
110 {
111 \CCalendarEvent::updateColor($event['ID'], $color);
112 }
113
114 $newStatus['eventLastId'] = $event['ID'];
115 $newStatus['steps']++;
116 }
117
118 if (!empty($newStatus['eventLastId']))
119 {
120 Option::set('calendar', 'changecolor', serialize($newStatus));
121
123 }
124
125 Option::set('calendar', 'needChangeColor', 'N');
126 Option::delete('calendar', array('name' => 'changecolor'));
127
129 }
130
131 private function loadCurrentStatus()
132 {
133 $status = Option::get('calendar', 'changecolor', 'default');
134 $status = ($status !== 'default' ? @unserialize($status, ['allowed_classes' => false]) : array());
135 $status = (is_array($status) ? $status : array());
136
137 if (empty($status))
138 {
139 $status = array(
140 'count' => self::getTotalCount(),
141 'steps' => 0,
142
143 'sectionLastId' => 0,
144 'eventLastId' => 0,
145
146 'sectionFinished' => false,
147 'finished' => false
148 );
149 }
150
151 return $status;
152 }
153
154 private function getTotalCount()
155 {
156 Loader::includeModule("calendar");
157 return \CCalendarEvent::GetCount() + \CCalendarSect::GetCount();
158 }
159
160 public function getNewColor($color)
161 {
162 $color = strtolower($color);
163 $colorTable = array(
164 // Biege
165 '#af7e00' => '#c3612c',
166 // blue
167 '#2fc6f6' => '#0092cc',
168 // gray
169 '#a8adb4' => '#838fa0',
170 // turquoise
171 '#47e4c2' => '#00b38c',
172 // orange
173 '#ffa900' => '#ffa900',
174 // blue2
175 '#56d1e0' => '#e89b06',
176 // violet
177 '#9985dd' => '#bd7ac9',
178 // red
179 '#f87396' => '#de2b24',
180 // green
181 '#9dcf00' => '#86b100',
182 );
183 if ($color && isset($colorTable[$color]))
184 return $colorTable[$color];
185 return $color;
186 }
187}