Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
category.php
1<?php
2
4
5
6
11
13{
15 private ?int $id;
17 private string $name = '';
19 private ?Error $error = null;
21 private ?array $rooms = null;
22
28 public function setId(?int $id): Category
29 {
30 $this->id = $id;
31
32 return $this;
33 }
34
40 public function setName(?string $name): Category
41 {
42 $this->name = Manager::checkCategoryName($name);
43
44 return $this;
45 }
46
51 public function setRooms(?array $rooms): Category
52 {
53 $this->rooms = $rooms;
54
55 return $this;
56 }
57
63 private function addError($error)
64 {
65 $this->error = $error;
66 }
67
71 public function getId(): int
72 {
73 return $this->id;
74 }
75
79 public function getName(): string
80 {
81 return $this->name;
82 }
83
87 public function getRooms() : ?array
88 {
89 return $this->rooms;
90 }
91
95 public function getError(): ?Error
96 {
97 return $this->error;
98 }
99
103 public function create(): Category
104 {
105 $section = RoomCategoryTable::add([
106 'NAME' => Emoji::encode($this->name),
107 ]);
108 if (!$section->isSuccess())
109 {
110 $this->addError(new Error('An error occurred while saving the category'));
111 }
112
113 $this->setId($section->getId());
114
115 return $this;
116 }
117
121 public function update(): Category
122 {
123 $section = RoomCategoryTable::update(
124 $this->id,
125 [
126 'NAME' => Emoji::encode($this->name),
127 ]
128 );
129 if (!$section->isSuccess())
130 {
131 $this->addError(new Error('An error occurred while saving the category'));
132 }
133 return $this;
134 }
135
139 public function delete(): Category
140 {
141 $category = RoomCategoryTable::delete($this->id);
142 if (!$category->isSuccess())
143 {
144 $this->addError(new Error('An error occurred while deleting the category'));
145 }
146 return $this;
147 }
148}
static checkCategoryName(?string $name)
Definition manager.php:224