Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
type.php
1<?php
2namespace Bitrix\Landing\Site;
3
6
7class Type
8{
12 const SCOPE_CODE_GROUP = 'GROUP';
13
17 const SCOPE_CODE_KNOWLEDGE = 'KNOWLEDGE';
18
22 const PSEUDO_SCOPE_CODE_FORMS = 'crm_forms';
23
28 protected static $currentScopeClass = null;
29
34 protected static $scopeInit = false;
35
41 protected static function getScopeClass($scope)
42 {
43 $scope = trim($scope);
44 $class = __NAMESPACE__ . '\\Scope\\' . $scope;
45 if (class_exists($class))
46 {
47 return $class;
48 }
49
50 return null;
51 }
52
58 public static function getSiteTypeForms($siteCode)
59 {
60 if (preg_match('#^/' . self::PSEUDO_SCOPE_CODE_FORMS . '[\d]*/$#', $siteCode))
61 {
63 }
64 return null;
65 }
66
73 public static function setScope($scope, array $params = [])
74 {
75 //self::$scopeInit ||
76 if (!is_string($scope) || !$scope)
77 {
78 return;
79 }
80 //if (self::$currentScopeClass === null)
81 // always clear previous scope
82 if (true)
83 {
85 self::$currentScopeClass = self::getScopeClass($scope);
86 if (self::$currentScopeClass)
87 {
88 self::$scopeInit = true;
89 self::$currentScopeClass::init($params);
90 }
91 }
92 }
93
98 public static function clearScope()
99 {
100 self::$scopeInit = false;
101 self::$currentScopeClass = null;
102 }
103
109 public static function isPublicScope(?string $scope = null): bool
110 {
111 $scope = $scope ? mb_strtoupper($scope) : self::getCurrentScopeId();
112 return !($scope === 'KNOWLEDGE' || $scope === 'GROUP');
113 }
114
119 public static function getPublicationPath()
120 {
121 if (self::$currentScopeClass !== null)
122 {
123 return self::$currentScopeClass::getPublicationPath();
124 }
125
126 return null;
127 }
128
133 public static function getKeyCode()
134 {
135 if (self::$currentScopeClass !== null)
136 {
137 return self::$currentScopeClass::getKeyCode();
138 }
139
140 return 'ID';
141 }
142
147 public static function getDomainId()
148 {
149 if (self::$currentScopeClass !== null)
150 {
151 return self::$currentScopeClass::getDomainId();
152 }
153 return '';
154 }
155
160 public static function getCurrentScopeId()
161 {
162 if (self::$currentScopeClass !== null)
163 {
164 return self::$currentScopeClass::getCurrentScopeId();
165 }
166 return null;
167 }
168
174 public static function getFilterType($strict = false)
175 {
176 if (self::$currentScopeClass !== null)
177 {
178 return self::$currentScopeClass::getFilterType();
179 }
180
181 // compatibility, huh
182 return $strict ? null : ['PAGE', 'STORE', 'SMN'];
183 }
184
189 public static function getExcludedHooks(): array
190 {
191 if (self::$currentScopeClass !== null)
192 {
193 return self::$currentScopeClass::getExcludedHooks();
194 }
195
196 return [];
197 }
198
204 public static function isEnabled($code)
205 {
206 if (is_string($code))
207 {
208 $code = mb_strtoupper(trim($code));
209 $types = Site::getTypes();
210 if (array_key_exists($code, $types))
211 {
212 return true;
213 }
214 }
215
216 return false;
217 }
218
225 public static function getOperationsForSite(int $siteId): ?array
226 {
227 if (
228 self::$currentScopeClass !== null
229 && is_callable([self::$currentScopeClass, 'getOperationsForSite'])
230 )
231 {
232 return self::$currentScopeClass::getOperationsForSite($siteId);
233 }
234
235 return null;
236 }
237}
static setExpectedType($type)
Definition role.php:545
static getPublicationPath()
Definition type.php:119
static getOperationsForSite(int $siteId)
Definition type.php:225
static getExcludedHooks()
Definition type.php:189
static isEnabled($code)
Definition type.php:204
static setScope($scope, array $params=[])
Definition type.php:73
static getScopeClass($scope)
Definition type.php:41
static getSiteTypeForms($siteCode)
Definition type.php:58
static isPublicScope(?string $scope=null)
Definition type.php:109
static $currentScopeClass
Definition type.php:28
static getFilterType($strict=false)
Definition type.php:174
const PSEUDO_SCOPE_CODE_FORMS
Definition type.php:22
static getCurrentScopeId()
Definition type.php:160
static getTypes()
Definition site.php:279