Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
landing.php
1<?php
3
10
20{
21
22 private $targetSiteId = 0;
23
24 public function __construct()
25 {
26 parent::__construct();
27 }
28
33 public function setTargetSiteId(int $targetSiteId): void
34 {
35 $this->targetSiteId = $targetSiteId;
36 }
37
45 public function add(Container $container, array $fields)
46 {
47 \Bitrix\Landing\Landing::disableCheckUniqueAddress();
48 $addResult = \Bitrix\Landing\Landing::add($fields);
49 \Bitrix\Landing\Landing::enableCheckUniqueAddress();
50
51 if ($addResult->isSuccess())
52 {
53 return $addResult->getId();
54 }
55 else
56 {
57 $this->result->addErrors($addResult->getErrors());
58 return false;
59 }
60 }
61
69 public function getFields(Container $container, $landingId)
70 {
71 $queryObject = \Bitrix\Landing\Landing::getList([
72 'select' => ['*'],
73 'filter' => ['ID' => $landingId]
74 ]);
75 return (($fields = $queryObject->fetch()) ? $fields : []);
76 }
77
85 public function prepareFieldsToCopy(Container $container, array $fields)
86 {
87 $siteId = $this->getSiteId($fields);
88
89 $fields['ACTIVE'] = 'N';
90 $fields['PUBLIC'] = 'N';
91 $fields['FOLDER'] = 'N';
92 $fields['SITE_ID'] = $siteId;
93 $fields['RULE'] = '';
94
95 unset($fields['ID']);
96
97 return $fields;
98 }
99
108 public function copyChildren(Container $container, $landingId, $copiedLandingId)
109 {
110 $results = [];
111
112 \Bitrix\Landing\Landing::setEditMode();
113
114 $landingInstance = \Bitrix\Landing\Landing::createInstance($copiedLandingId);
115 if ($landingInstance->exist())
116 {
117 $results[] = $this->copyBlocks($landingId, $copiedLandingId);
118
120 Hook::copyLanding($landingId, $copiedLandingId);
121
122 File::copyLandingFiles($landingId, $copiedLandingId);
123 if (($refs = TemplateRef::getForLanding($landingId)))
124 {
125 TemplateRef::setForLanding($copiedLandingId, $refs);
126 }
127 }
128
129 $landingErrorCollection = $landingInstance->getError();
130 if ($landingErrorCollection->getErrors())
131 {
132 $result = new Result();
133 $result->addErrors($landingErrorCollection->getErrors());
134 $results[] = $result;
135 }
136
137 return $this->getResult($results);
138 }
139
140 private function getSiteId(array $fields): int
141 {
142 return (int) ($this->targetSiteId ? $this->targetSiteId : $fields['SITE_ID']);
143 }
144
145 private function copyBlocks(int $landingId, int $copiedLandingId): Result
146 {
147 $result = new Result();
148
149 $blockMapIds = [];
150
151 $copiedLanding = \Bitrix\Landing\Landing::createInstance($copiedLandingId);
152 $copiedLanding->copyAllBlocks($landingId, false, $blockMapIds);
153
154 $result->setData(['LandingBlocks' => $blockMapIds]);
155
156 return $result;
157 }
158}
getFields(Container $container, $landingId)
Definition landing.php:69
setTargetSiteId(int $targetSiteId)
Definition landing.php:33
add(Container $container, array $fields)
Definition landing.php:45
copyChildren(Container $container, $landingId, $copiedLandingId)
Definition landing.php:108
prepareFieldsToCopy(Container $container, array $fields)
Definition landing.php:85
static copyLandingFiles($from, $to)
Definition file.php:559
static copyLanding($from, $to)
Definition hook.php:427
static setEditMode(bool $mode=true)
Definition hook.php:232
static setForLanding($id, array $data=array())