1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
DefaultCategoryService.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\OpenEvents\Service;
4
5use Bitrix\Calendar\Core\Common;
6use Bitrix\Calendar\Core\Common as CommonConst;
7use Bitrix\Calendar\Integration\HumanResources\Structure;
8use Bitrix\Calendar\OpenEvents\Controller\Request\EventCategory\CreateEventCategoryDto;
9use Bitrix\Calendar\OpenEvents\Internals\Entity\OpenEventCategory;
10use Bitrix\Calendar\OpenEvents\Internals\OpenEventCategoryTable;
11use Bitrix\Main\Config;
12
19{
20 public const PRIMARY_CATEGORY_OPTION_NAME = 'open_event_primary_category_id';
21 public const DEFAULT_CATEGORY_NAME = 'CALENDAR_OPEN_EVENTS_DEFAULT_CATEGORY_NAME';
22 public const DEFAULT_CATEGORY_DESCRIPTION = 'CALENDAR_OPEN_EVENTS_DEFAULT_CATEGORY_DESCRIPTION';
23
24 private static ?self $instance;
25
26 public static function getInstance(): self
27 {
28 self::$instance ??= new self();
29
30 return self::$instance;
31 }
32
33 public function createDefaultCategory(): void
34 {
35 if ($this->getCategory() !== null)
36 {
37 return;
38 }
39
40 $rootDepartmentId = Structure::getInstance()->getRootDepartmentId();
41
42 $createEventCategoryDto = new CreateEventCategoryDto(
43 self::DEFAULT_CATEGORY_NAME,
44 self::DEFAULT_CATEGORY_DESCRIPTION,
45 departmentIds: $rootDepartmentId ? [$rootDepartmentId] : [],
46 isPrimary: true,
47 );
48
49 $category = CategoryService::getInstance()->createEventCategory(
50 Common::SYSTEM_USER_ID,
51 $createEventCategoryDto,
52 );
53
54 $this->setCategoryId($category->getId());
55 }
56
57 public function setCategoryId(int $categoryId): void
58 {
60 CommonConst::CALENDAR_MODULE_ID,
61 self::PRIMARY_CATEGORY_OPTION_NAME,
62 $categoryId
63 );
64 }
65
66 public function getCategoryId(): ?int
67 {
68 return Config\Option::get(
69 CommonConst::CALENDAR_MODULE_ID,
70 self::PRIMARY_CATEGORY_OPTION_NAME,
71 null
72 );
73 }
74
75 public function getCategory(): ?OpenEventCategory
76 {
77 $category = OpenEventCategoryTable::query()
78 ->where('ID', $this->getCategoryId())
79 ->fetchObject();
80 if (!$category)
81 {
82 return null;
83 }
84
85 return $category;
86 }
87
88 private function __constructor()
89 {
90 }
91}
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261