1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Agent.php
См. документацию.
1<?php
2
4
11
12class Agent
13{
14 private const RESTRICT_OPTION_NAME = 'restrict_default_open_event_category_creating';
15
16 private static bool $processing = false;
17
18 // return empty string '' to delete agent
19 public static function execute(): string
20 {
21 if (self::$processing)
22 {
23 return '';
24 }
25
26 self::$processing = true;
27
28 (new self())->run();
29
30 self::$processing = false;
31
32 return '';
33 }
34
35 public function run(): void
36 {
37 if (!Loader::includeModule('calendar'))
38 {
39 return;
40 }
41
42 $this->createCalendarType();
43 $this->createDefaultSection();
44 if ($this->shouldCreateDefaultCategory())
45 {
46 $this->createDefaultCategory();
47 }
48 }
49
50 protected function createCalendarType(): void
51 {
52 \CCalendarType::Edit([
53 'NEW' => true,
54 'arFields' => [
55 'XML_ID' => Dictionary::CALENDAR_TYPE['open_event'],
56 'NAME' => Loc::getMessage('CALENDAR_OPEN_EVENTS_DEFAULT_SECTION_NAME'),
57 'DESCRIPTION' => '',
58 ],
59 ]);
60 }
61
62 protected function createDefaultSection(): void
63 {
64 if ($this->hasOpenEventSection())
65 {
66 return;
67 }
68
69 \CCalendarSect::Edit([
70 'arFields' => [
71 'NAME' => Loc::getMessage('CALENDAR_OPEN_EVENTS_DEFAULT_SECTION_NAME'),
72 'DESCRIPTION' => Loc::getMessage('CALENDAR_OPEN_EVENTS_DEFAULT_SECTION_NAME'),
73 'CAL_TYPE' => Dictionary::CALENDAR_TYPE['open_event'],
74 'COLOR' => '#442056',
75 'TEXT_COLOR' => '#FFFFFF',
76 'OWNER_ID' => Common::SYSTEM_USER_ID,
77 'CREATED_BY' => Common::SYSTEM_USER_ID,
78 ],
79 ]);
80 }
81
82 private function hasOpenEventSection(): bool
83 {
84 $openEventSections = \CCalendarSect::GetList([
85 'arSelect' => ['ID', 'CAL_TYPE'],
86 'arFilter' => [
87 'CAL_TYPE' => Dictionary::CALENDAR_TYPE['open_event'],
88 ],
89 'limit' => 1,
90 'checkPermissions' => false,
91 'getPermissions' => false,
92 ]);
93
94 return !empty($openEventSections);
95 }
96
97 protected function createDefaultCategory(): void
98 {
99 DefaultCategoryService::getInstance()->createDefaultCategory();
100 }
101
102 private function shouldCreateDefaultCategory(): bool
103 {
104 return Config\Option::get(
105 moduleId: Common::CALENDAR_MODULE_ID,
106 name: self::RESTRICT_OPTION_NAME,
107 default: 'N',
108 ) !== 'Y';
109 }
110}
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения loader.php:13