Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
indexcalendar.php
1<?php
2
4
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Main\Update\Stepper;
7use \Bitrix\Main\Config\Option;
8use \Bitrix\Main\Loader;
9
10
11final class IndexCalendar extends Stepper
12{
13 const PORTION = 40;
14
15 protected static $moduleId = "calendar";
16
17 public static function className()
18 {
19 return get_called_class();
20 }
21
22 public function execute(array &$result)
23 {
24 if (Loader::includeModule("calendar")
25 && Option::get('calendar', 'needEventIndex', 'Y') === 'N')
26 {
28 }
29
30 $status = $this->loadCurrentStatus();
31
32 if ($status['finished'])
33 {
35 }
36
37 $newStatus = array(
38 'count' => $status['count'],
39 'steps' => $status['steps'],
40 'sectionFinished' => $status['sectionFinished'],
41 'finished' => $status['finished']
42 );
43
44 // 1. Update sections
45 if (!$status['sectionFinished'])
46 {
47 $sections = \CCalendarSect::GetList(array(
48 'arFilter' => array(
49 '>ID' => $status['sectionLastId']
50 ),
51 'arOrder' => array('ID' => 'asc'),
52 'checkPermissions' => false,
53 'getPermissions' => false,
54 'limit' => self::PORTION
55 ));
56
57 foreach ($sections as $section)
58 {
59 // 1. Replace colors
60 $color = self::getNewColor($section['COLOR']);
61 if (mb_strtolower($color) != mb_strtolower($section['COLOR']))
62 {
63 \CCalendarSect::Edit(array(
64 'arFields' => array(
65 'ID' => $section['ID'],
66 'COLOR' => $color
67 )
68 ));
69 }
70 $newStatus['sectionLastId'] = $section['ID'];
71 $newStatus['steps']++;
72 }
73
74
75 if (!empty($newStatus['sectionLastId']))
76 {
77 Option::set('calendar', 'eventindex', serialize($newStatus));
78 $result = array(
79 'title' => Loc::getMessage("CALENDAR_INDEX_TITLE"),
80 'count' => $newStatus['count'],
81 'steps' => $newStatus['steps']
82 );
83
85 }
86
87 $newStatus['sectionFinished'] = true;
88 Option::set('calendar', 'eventindex', serialize($newStatus));
89 }
90
91 // 2. Update events
92 $events = \CCalendarEvent::GetList(array(
93 'arFilter' => array(
94 '>ID' => $status['eventLastId'],
95 'DELETED' => false
96 ),
97 'arOrder' => array('ID' => 'asc'),
98 'fetchAttendees' => true,
99 'parseRecursion' => false,
100 'checkPermissions' => false,
101 'parseDescription' => false,
102 'fetchSection' => true,
103 'limit' => self::PORTION
104 )
105 );
106
107 foreach ($events as $event)
108 {
109 // 1. Replace colors
110 $color = self::getNewColor($event['COLOR']);
111 if (mb_strtolower($color) != mb_strtolower($event['COLOR']))
112 {
113 \CCalendarEvent::updateColor($event['ID'], $color);
114 }
115
116 // 2. Fill searchable content
117 \CCalendarEvent::updateSearchIndex($event['ID'], array(
118 'events' => array($event)
119 ));
120
121 $newStatus['eventLastId'] = $event['ID'];
122 $newStatus['steps']++;
123 }
124
125 if (!empty($newStatus['eventLastId']))
126 {
127 Option::set('calendar', 'eventindex', serialize($newStatus));
128 $result = array(
129 'title' => Loc::getMessage("CALENDAR_INDEX_TITLE"),
130 'count' => $newStatus['count'],
131 'steps' => $newStatus['steps']
132 );
134 }
135
136 Option::set('calendar', 'needEventIndex', 'N');
137 Option::delete('calendar', array('name' => 'eventindex'));
138
140 }
141
142 private function loadCurrentStatus()
143 {
144 $status = Option::get('calendar', 'eventindex', 'default');
145 $status = ($status !== 'default' ? @unserialize($status, ['allowed_classes' => false]) : array());
146 $status = (is_array($status) ? $status : array());
147
148 if (empty($status))
149 {
150 $status = array(
151 'count' => self::getTotalCount(),
152 'steps' => 0,
153
154 'sectionLastId' => 0,
155 'eventLastId' => 0,
156
157 'sectionFinished' => false,
158 'finished' => false
159 );
160 }
161
162 return $status;
163 }
164
165 private function getTotalCount()
166 {
167 Loader::includeModule("calendar");
168 return \CCalendarEvent::GetCount() + \CCalendarSect::GetCount();
169 }
170
171 public function getNewColor($color)
172 {
173 $color = mb_strtolower($color);
174 $colorTable = array(
175 // Biege
176 '#daa187' => '#af7e00',
177 '#b47153' => '#af7e00',
178 // blue
179 '#78d4f1' => '#2fc6f6',
180 '#2fc7f7' => '#2fc6f6',
181 // gray
182 '#c8cdd3' =>'#a8adb4',
183 '#a7abb0' =>'#a8adb4',
184 // turquoise
185 '#43dad2' => '#47e4c2',
186 '#04b4ab' => '#47e4c2',
187 // orange
188 '#eece8f' => '#ffa900',
189 '#ffa801' => '#ffa900',
190 // blue2
191 '#5cd1df' => '#56d1e0',
192 '#aee5ec' => '#56d1e0',
193 // violet
194 '#b6a5f6' => '#9985dd',
195 '#6e54d1' => '#9985dd',
196 // red
197 '#f0b1a1' => '#f87396',
198 '#f73200' => '#f87396',
199 '#ee9b9a' => '#f87396',
200 '#fe5957' => '#f87396',
201 // green
202 '#82dc98' => '#9dcf00',
203 '#29ad49' => '#9dcf00',
204 '#cee669' => '#9dcf00'
205 );
206 if ($color && isset($colorTable[$color]))
207 return $colorTable[$color];
208 return $color;
209 }
210}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29