23 private const SITE_ID_OPTION_CODE =
'mainpage_site_id';
24 private const CREATION_OPTION_CODE =
'mainpage_creating';
25 private const CREATION_OPTION_PROCESS =
'process';
26 private const CREATION_OPTION_FULL =
'fully';
27 private const USE_DEMO_OPTION_CODE =
'use_demo_data_in_block_widgets';
28 private const FREE_MODE_OPTION_CODE =
'enable_at_free_tariff';
33 private ?
int $siteId =
null;
34 private ?
int $landingId =
null;
35 private ?
string $previewImg =
null;
36 private ?
string $pageTitle =
null;
37 private ?
string $scopeBefore =
null;
38 private bool $rightsBefore;
47 return Loader::includeModule(
'intranet');
52 if (Loader::includeModule(
'bitrix24'))
54 return Feature::isFeatureEnabled(
'main_page');
65 $this->onBeforeOperation();
67 $this->detectConnectedSite();
68 $this->detectConnectedPage();
70 $this->onAfterOperation();
77 private function detectConnectedSite(): void
89 if ($optionSiteId > 0)
91 $connectedSite = (Landing\Site::getList([
92 'select' => [
'LANDING_ID_INDEX'],
94 '=ID' => $optionSiteId,
96 'TYPE' => Type::SCOPE_CODE_MAINPAGE,
98 'CHECK_PERMISSIONS' =>
'N',
100 'cache' => [
'ttl' => 86400],
104 $this->siteId = $optionSiteId;
105 if (!$this->landingId && $connectedSite[
'LANDING_ID_INDEX'] > 0)
107 $this->landingId = (int)$connectedSite[
'LANDING_ID_INDEX'];
116 $exists = (Landing\Site::getList([
117 'select' => [
'ID',
'TYPE',
'ACTIVE',
'LANDING_ID_INDEX'],
120 'TYPE' => Type::SCOPE_CODE_MAINPAGE,
122 'CHECK_PERMISSIONS' =>
'N',
125 if ($exists && (
int)$exists[
'ID'])
127 $this->siteId = (int)$exists[
'ID'];
128 if (!$this->landingId && $exists[
'LANDING_ID_INDEX'] > 0)
130 $this->landingId = (int)$exists[
'LANDING_ID_INDEX'];
136 $newId = $this->createDefaultSite();
139 $this->siteId = $newId;
140 $this->landingId =
null;
144 if ($this->siteId && $this->siteId !== $optionSiteId)
146 Landing\Manager::setOption(self::SITE_ID_OPTION_CODE, $this->siteId);
152 private function createDefaultSite(): ?int
154 $new = Landing\Site::add([
155 'TITLE' => Loc::getMessage(
'LANDING_MAINPAGE_SITE_NAME'),
156 'CODE' => strtolower(Type::SCOPE_CODE_MAINPAGE),
157 'TYPE' => Type::SCOPE_CODE_MAINPAGE,
161 $defaultSiteId =
null;
162 if (
$new->isSuccess())
164 $defaultSiteId = (int)
$new->getId();
167 return $defaultSiteId;
174 private function detectConnectedPage(): void
178 $this->landingId =
null;
184 if ($this->landingId > 0)
186 $exists = (Landing\Landing::getList([
190 '=ID' => $this->landingId,
195 'cache' => [
'ttl' => 86400],
198 if ($exists && (
int)$exists[
'ID'])
200 $this->landingId = (int)$exists[
'ID'];
202 $this->detectPreviewImg();
203 $this->detectPageTitle();
207 $this->landingId =
null;
216 private function detectPreviewImg(): void
219 ? Landing\Manager::getUrlFromFile(Site::getPreview($this->
getConnectedSiteId(),
true))
227 private function detectPageTitle(): void
236 if (!Loader::includeModule(
'socialnetwork'))
242 if ($storedGroupId > 0)
247 $firstSubject = \CSocNetGroupSubject::GetList(
248 [
"SORT" =>
"ASC",
"NAME" =>
"ASC"],
257 "NAME" => Loc::getMessage(
'LANDING_MAINPAGE_SOCIAL_GROUP_FOR_PUBLICATION_NAME'),
262 "SUBJECT_ID" => $firstSubject[
'ID'] ?? 0,
263 "INITIATE_PERMS" =>
'E',
267 if ($newGroupId && $newGroupId > 0)
269 Option::set(
'landing',
'mainpage_id_publication_group', $newGroupId);
279 if (!self::isAvailable())
290 $this->onBeforeOperation();
294 (
new Publisher())->publish();
301 $newPageId = $installer->createDemoPage();
305 $newPageId = $installer->createPageByTemplate(
$code);
306 $this->onTemplateCreation();
314 $this->landingId = $newPageId;
316 $this->onAfterOperation();
331 private function onTemplateCreation(): void
333 EventManager::getInstance()->registerEventHandler(
335 'onLicenseHasChanged',
338 'onLicenseHasChanged'
340 self::setFreeTariffMode();
384 return $creating === self::CREATION_OPTION_FULL;
403 private function onBeforeOperation(): void
406 $this->scopeBefore = Type::getCurrentScopeId();
423 if (isset($connectedSiteId, $connectedPageId))
429 Landing\Site::update($connectedSiteId, [
430 'LANDING_ID_INDEX' => $connectedPageId,
433 if (Loader::includeModule(
'pull'))
438 'module_id' =>
'landing',
439 'command' =>
'Vibe:onCreate',
453 private function onAfterOperation(): void
455 if ($this->scopeBefore ===
null)
460 is_string($this->scopeBefore)
461 && $this->scopeBefore !== Type::SCOPE_CODE_MAINPAGE
467 if ($this->rightsBefore)
480 return (
int)$this->siteId > 0 ? (int)$this->siteId :
null;
491 ? (
int)$this->landingId
501 return $this->previewImg;
createPageByTemplate(?Templates $code=null, bool $publication=false)
createSonetGroupForPublicationOnce()
static setFreeTariffMode(bool $flag=true)
static isFreeTariffMode()
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)