Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectionmodel.php
1<?php
2
4
7
9{
10 private static array $cache = [];
11
12 private int $id = 0;
13 private string $type = '';
14 private int $ownerId = 0;
15
16 public static function createFromId(int $itemId): AccessibleItem
17 {
18 if (!isset(static::$cache[$itemId]))
19 {
20 $model = new self();
21 $model->setId($itemId);
22 static::$cache[$itemId] = $model;
23 }
24
25 return static::$cache[$itemId];
26 }
27
28 public static function createNew(): self
29 {
30 return new self();
31 }
32
33 public static function createFromArray(array $fields): self
34 {
35 if (($fields['ID'] ?? false) && (int)$fields['ID'] > 0)
36 {
37 $model = self::createFromId((int)$fields['ID']);
38 }
39 else
40 {
41 $model = self::createNew();
42 }
43
44 if (($fields['CAL_TYPE'] ?? false) && is_string($fields['CAL_TYPE']))
45 {
46 $model->setType($fields['CAL_TYPE']);
47 }
48
49 if (($fields['OWNER_ID'] ?? false) && (int)$fields['OWNER_ID'] > 0)
50 {
51 $model->setOwnerId((int)$fields['OWNER_ID']);
52 }
53
54 return $model;
55 }
56
57 public static function createFromEventModel(EventModel $eventModel): self
58 {
59 if ($eventModel->getSectionId() > 0)
60 {
61 $model = self::createFromId($eventModel->getSectionId());
62 }
63 else
64 {
65 $model = self::createNew();
66 }
67
68 $model
69 ->setType($eventModel->getSectionType())
70 ->setOwnerId($eventModel->getOwnerId())
71 ;
72
73 return $model;
74 }
75
76 public static function createFromEventModelParentFields(EventModel $eventModel): self
77 {
78 if ($eventModel->getSectionId() > 0)
79 {
80 $model = self::createFromId($eventModel->getParentEventSectionId());
81 }
82 else
83 {
84 $model = self::createNew();
85 }
86
87 $model
88 ->setType($eventModel->getParentEventSectionType())
89 ->setOwnerId($eventModel->getParentEventOwnerId())
90 ;
91
92 return $model;
93 }
94
95 public function setId(int $id): self
96 {
97 $this->id = $id;
98 return $this;
99 }
100
101 public function getId(): int
102 {
103 return $this->id;
104 }
105
106 public function setType(string $type): self
107 {
108 $this->type = $type;
109 return $this;
110 }
111
112 public function getType(): string
113 {
114 return $this->type;
115 }
116
117 public function setOwnerId(int $ownerId): self
118 {
119 $this->ownerId = $ownerId;
120 return $this;
121 }
122
123 public function getOwnerId(): int
124 {
125 return $this->ownerId;
126 }
127}
static createFromEventModelParentFields(EventModel $eventModel)
static createFromEventModel(EventModel $eventModel)