1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Wishes.php
См. документацию.
1<?php
2declare(strict_types=1);
3
4namespace Bitrix\Landing\Copilot\Data;
5
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Text\Emoji;
8use Exception;
9
10class Wishes
11{
12 private array $wishes = [];
13 private ?string $company = null;
14
20 public function setWishes(array $wishes): self
21 {
22 $this->wishes = array_filter($this->decodeArray($wishes), static fn($wish) => !empty(trim($wish)));
23
24 return $this;
25 }
26
32 public function addWish(string $wish): self
33 {
34 $wishDecoded = $this->decodeString($wish);
35
36 if (!empty(trim($wishDecoded)))
37 {
38 $this->wishes[] = $wishDecoded;
39 }
40
41 return $this;
42 }
43
48 public function setDemoWishes(): self
49 {
50 $this->wishes = [self::getDemoWish()];
51
52 return $this;
53 }
54
55 private static function getDemoWish(): string
56 {
57 return Loc::getMessage('LANDING_COPILOT_DEMO_WISH_' . (rand(1, 20)));
58 }
59
64 public function getWishes(): array
65 {
66 return $this->encodeArray($this->wishes);
67 }
68
74 public function setCompany(string $company): self
75 {
76 $companyDecoded = $this->decodeString($company);
77
78 if (!empty(trim($companyDecoded)))
79 {
80 $this->company = $companyDecoded;
81 }
82
83 return $this;
84 }
85
90 public function getCompany(): ?string
91 {
92 return $this->company !== null ? $this->encodeString($this->company) : null;
93 }
94
99 public function toArray(): array
100 {
101 $data = [];
102
103 if (!empty($this->wishes))
104 {
105 $data['wishes'] = $this->getWishes();
106 }
107 if (isset($this->company))
108 {
109 $data['company'] = $this->getCompany();
110 }
111
112 return $data;
113 }
114
120 public static function fromArray(array $data): self
121 {
122 $wishes = new self();
123
124 if (
125 isset($data['wishes'])
126 && is_array($data['wishes'])
127 )
128 {
129 $wishes->setWishes($data['wishes']);
130 }
131
132 if (
133 isset($data['company'])
134 && is_string($data['company'])
135 )
136 {
137 $wishes->setCompany($data['company']);
138 }
139
140 return $wishes;
141 }
142
148 private function decodeArray(array $array): array
149 {
150 return array_map([$this, 'decodeString'], $array);
151 }
152
158 private function encodeArray(array $array): array
159 {
160 return array_map([$this, 'encodeString'], $array);
161 }
162
168 private function decodeString(string $string): string
169 {
170 return Emoji::decode($string);
171 }
172
178 private function encodeString(string $string): string
179 {
180 return Emoji::encode($string);
181 }
182}
static fromArray(array $data)
Определения Wishes.php:120
setCompany(string $company)
Определения Wishes.php:74
addWish(string $wish)
Определения Wishes.php:32
setWishes(array $wishes)
Определения Wishes.php:20
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804