Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
baseconfigurable.php
1<?php
2
4
10
11abstract class BaseConfigurable extends Base
12{
13 protected $options;
14
19
20 public function isConfigurable()
21 {
22 return true;
23 }
24
29 public function isDemo()
30 {
31 return ($this->getOption('is_demo') === true);
32 }
33
38 abstract public function isRegistered();
39
44 public function isConfirmed()
45 {
46 return $this->isRegistered();
47 }
48
54 public function setDefaultFrom($from)
55 {
56 return $this;
57 }
58
63 public function canUse()
64 {
65 return ($this->isRegistered() && $this->isConfirmed());
66 }
67
72 abstract public function register(array $fields);
73
77 abstract public function getOwnerInfo();
78
83 public function confirmRegistration(array $fields)
84 {
85 return new Result();
86 }
87
91 public function sendConfirmationCode()
92 {
93 return new Result();
94 }
95
99 public function getManageUrl(): string
100 {
101 if (defined('ADMIN_SECTION') && ADMIN_SECTION === true)
102 {
103 return 'messageservice_sender_sms.php?sender_id='.$this->getId();
104 }
105
106 return '/crm/configs/sms/?sender='.$this->getId(); //TODO: replace public path
107 }
108
112 abstract public function getExternalManageUrl();
113
119 abstract public function getMessageStatus(array $messageFields);
120
125 public function enableDemo()
126 {
127 $this->setOption('is_demo', true);
128 return $this;
129 }
130
135 public function disableDemo()
136 {
137 $this->setOption('is_demo', false);
138 return $this;
139 }
140
145 public function sync()
146 {
147 return $this;
148 }
149
150 protected function getCallbackUrl()
151 {
152 $id = $this->getId();
153 return $this->getHostUrl().'/bitrix/tools/messageservice/callback_'.$id.'.php';
154 }
155
162 private function getHostUrl()
163 {
164 $protocol = (\CMain::isHTTPS() ? 'https' : 'http');
165 if (defined("SITE_SERVER_NAME") && SITE_SERVER_NAME)
166 {
167 $host = SITE_SERVER_NAME;
168 }
169 else
170 {
171 $host =
172 Option::get('main', 'server_name', Context::getCurrent()->getServer()->getHttpHost())?:
173 Context::getCurrent()->getServer()->getHttpHost()
174 ;
175 }
176
177 $port = Context::getCurrent()->getServer()->getServerPort();
178 if($port <> 80 && $port <> 443 && $port > 0 && mb_strpos($host, ':') === false)
179 {
180 $host .= ':'.$port;
181 }
182 elseif($protocol == 'http' && $port == 80)
183 {
184 $host = str_replace(':80', '', $host);
185 }
186 elseif($protocol == 'https' && $port == 443)
187 {
188 $host = str_replace(':443', '', $host);
189 }
190
191 return $protocol . '://' . $host;
192 }
193
199 protected function setOptions(array $options)
200 {
201 $this->options = $options;
202 $providerId = $this->getId();
203 $providerType = mb_strtolower($this->getType());
204 Option::set('messageservice','sender.'.$providerType.'.'.$providerId, serialize($options));
205 return $this;
206 }
207
211 protected function getOptions(): array
212 {
213 $this->optionManager ??= new Providers\Base\Option($this->getType(), $this->getId());
214
215 return $this->optionManager->getOptions();
216 }
217
224 protected function setOption($optionName, $optionValue): BaseConfigurable
225 {
226 $this->optionManager ??= new Providers\Base\Option($this->getType(), $this->getId());
227 $this->optionManager->setOption($optionName, $optionValue);
228
229 return $this;
230 }
231
237 protected function getOption($optionName, $defaultValue = null)
238 {
239 $this->optionManager ??= new Providers\Base\Option($this->getType(), $this->getId());
240
241 return $this->optionManager->getOption($optionName, $defaultValue);
242 }
243
247 public function clearOptions(): bool
248 {
249 $this->optionManager ??= new Providers\Base\Option($this->getType(), $this->getId());
250 $this->optionManager->clearOptions();
251
252 return true;
253 }
254
255 public function getConfigComponentTemplatePageName(): string
256 {
257 return static::getId();
258 }
259
265 public function isTemplatesBased(): bool
266 {
267 return false;
268 }
269
283 public function getTemplatesList(array $context = null): array
284 {
285 return [];
286 }
287
291 public function prepareTemplate($templateData)
292 {
293 return $templateData;
294 }
295}
static getCurrent()
Definition context.php:241
getOption($optionName, $defaultValue=null)