2declare(strict_types=1);
4namespace Bitrix\Landing\Copilot\Data\Node;
7use Bitrix\Landing\Copilot\Data;
8use Bitrix\Landing\Copilot\Data\Block\Operator;
9use Bitrix\Landing\Copilot\Data\Type\NodeType;
10use Bitrix\Landing\Copilot\Data\Type\ImgValueDto;
11use Bitrix\Landing\Rights;
12use Bitrix\Main\Web\Uri;
16 protected const TYPE = NodeType::Img;
22 private array $values = [];
28 private array $sizeData = [];
29 private bool $editInStyle =
false;
30 private ?
array $genderData =
null;
40 if (isset(
$data[
'editInStyle']))
42 $this->editInStyle = (bool)
$data[
'editInStyle'];
45 if (isset(
$data[
'sizeData']))
47 foreach (
$data[
'sizeData'] as $position => $sizeData)
49 $this->sizeData[$position] = [
50 'width' => $sizeData[
'width'] ??
null,
51 'height' => $sizeData[
'height'] ??
null,
52 'aspectRatio' => $sizeData[
'aspectRatio'] ??
null,
57 if (isset(
$data[
'genderData']))
59 $this->genderData =
$data[
'genderData'];
63 if (isset(
$data[
'values']))
66 foreach (
$data[
'values'] as $position => $value)
69 if (isset($value[
'defaultSrc']))
71 $this->values[$position]->defaultSrc = $value[
'defaultSrc'];
73 if (isset($value[
'defaultSrc2x']))
75 $this->values[$position]->defaultSrc2x = $value[
'defaultSrc2x'];
77 if (isset($value[
'src']))
79 $this->values[$position]->src = $value[
'src'];
80 $this->values[$position]->src2x = $value[
'src2x'] ?? $value[
'src'];
81 if (isset($value[
'id']))
83 $this->values[$position]->id = $value[
'id'];
84 $this->values[$position]->id2x = $value[
'id2x'] ?? $value[
'id'];
93 $dataSrc[
'src'] =
$data[
'src'] ??
$data[
'defaultSrc'];
94 $dataSrc[
'src2x'] =
$data[
'src2x'] ??
$data[
'defaultSrc2x'];
97 is_array($dataSrc[
'src']) ?
count($dataSrc[
'src']) : 0,
98 is_array($dataSrc[
'src2x']) ?
count($dataSrc[
'src2x']) : 0
101 for ($position = 0; $position < $maxLength; $position++)
103 if (!isset($this->values[$position]))
108 if (isset($dataSrc[
'src'][$position]))
110 $src = $dataSrc[
'src'][$position];
111 $this->values[$position]->defaultSrc = $src;
112 $this->values[$position]->src = $src;
115 if (isset($dataSrc[
'src2x'][$position]))
117 $src2x = $dataSrc[
'src2x'][$position];
118 $this->values[$position]->defaultSrc2x = $src2x;
119 $this->values[$position]->src2x = $src2x;
132 if (isset($this->values[$position]))
134 $defaultSrc = $this->values[$position]->defaultSrc;
135 $defaultSrc2x = $this->values[$position]->defaultSrc2x;
139 if (isset($value[
'src']))
141 $newValue->defaultSrc = $defaultSrc ??
null;
142 $newValue->defaultSrc2x = $defaultSrc2x ??
null;
143 $newValue->src = $value[
'src'];
144 $newValue->src2x = $value[
'src2x'] ?? $value[
'src'];
145 if (isset($value[
'id']))
147 $newValue->id = $value[
'id'];
148 $newValue->id2x = $value[
'id2x'] ?? $value[
'id'];
151 $this->values[$position] = $newValue;
158 parent::setParentBlock($block);
182 foreach ($this->values as $pos => $value)
185 if (isset($value->defaultSrc))
187 $current[
'defaultSrc'] = $value->defaultSrc;
189 if (isset($value->defaultSrc2x))
191 $current[
'defaultSrc2x'] = $value->defaultSrc2x;
193 if (isset($value->src))
195 $current[
'src'] = $value->src;
196 $current[
'src2x'] = $value->src2x ?? $value->src;
198 if (isset($value->id))
200 $current[
'id'] = $value->id;
201 $current[
'id2x'] = $value->id2x ?? $value->id;
205 if (!empty($current))
207 $current[
'type'] =
'image';
208 $values[$pos] = $current;
212 if (isset($position))
214 $values = array_filter(
216 static function (
$key) use ($position){
217 return $key === $position;
228 return $this->sizeData;
233 foreach ($src as $position => $srcItem)
235 if (!isset($this->values[$position]))
238 $this->values[$position]->id =
null;
239 $this->values[$position]->id2x =
null;
240 $this->values[$position]->defaultSrc =
null;
241 $this->values[$position]->defaultSrc2x =
null;
244 if (is_string($srcItem))
246 $this->values[$position]->src = $srcItem;
247 $this->values[$position]->src2x = $srcItem;
250 if (is_array($srcItem))
252 $this->values[$position]->src = $srcItem[
'src'] ??
null;
253 $this->values[$position]->src2x = $srcItem[
'src2x'] ?? $this->values[$position]->src;
262 foreach ($defaultSrc as $position => $defaultSrcItem)
264 if (!isset($this->values[$position]))
267 $this->values[$position]->id =
null;
268 $this->values[$position]->id2x =
null;
269 $this->values[$position]->src =
null;
270 $this->values[$position]->src2x =
null;
273 if (is_string($defaultSrcItem))
275 $this->values[$position]->defaultSrc = $defaultSrcItem;
276 $this->values[$position]->defaultSrc2x = $defaultSrcItem;
279 if (is_array($defaultSrcItem))
281 $this->values[$position]->defaultSrc = $defaultSrcItem[
'src'] ??
null;
282 $this->values[$position]->defaultSrc2x =
283 $defaultSrcItem[
'src2x'] ?? $this->values[$position]->defaultSrc;
292 return $this->editInStyle;
298 $this->genderData = $genderData;
306 return $this->genderData;
311 $fileArray = self::makeFileArrayByPath(
$path);
313 if (!isset($fileArray, $sizeData))
318 $defaultSrc = $this->values[$position]->defaultSrc;
319 $defaultSrc2x = $this->values[$position]->defaultSrc2x;
322 $this->values[$position]->defaultSrc = $defaultSrc;
323 $this->values[$position]->defaultSrc2x = $defaultSrc2x;
325 foreach ([1, 2] as $x)
329 $fileArray[
'height'],
330 (
int)$sizeData[
'width'] * $x,
331 $sizeData[
'aspectRatio'],
346 $this->values[$position]->id = (int)$newFile[
'ID'];
347 $this->values[$position]->src = $newFile[
'SRC'];
351 $this->values[$position]->id2x = (int)$newFile[
'ID'];
352 $this->values[$position]->src2x = $newFile[
'SRC'];
365 private static function makeFileArrayByPath(
string $path): ?
array
379 $file = \CFile::GetByID($fileId)->Fetch();
380 $fileArray = \CFIle::makeFileArray($fileId);
382 if (isset($fileArray[
'tmp_name']))
385 (
int)$file[
'WIDTH'] > 0
386 && (
int)$file[
'HEIGHT'] > 0
389 $fileArray[
'width'] = (int)$file[
'WIDTH'];
390 $fileArray[
'height'] = (int)$file[
'HEIGHT'];
413 $aspects = Operator::getAllowedAspectRatios();
414 $aspect = $aspects[$aspectName] ?? 1;
416 $targetHeight = $targetWidth / $aspect;
419 $targetWidth > $sourceWidth
420 || $targetHeight > $sourceHeight
423 if (($targetHeight * $aspect) <= $sourceWidth)
425 $targetWidth = $sourceHeight * $aspect;
426 $targetHeight = $sourceHeight;
430 $targetWidth = $sourceWidth;
431 $targetHeight = $sourceWidth / $aspect;
436 'width' => $targetWidth,
437 'height' => $targetHeight,
443 $data = parent::toArray();
454 if (!$this->canApplyToLanding())
459 $block = $this->getBlockInstance();
470 foreach ($this->
getValues($position) as $pos => $value)
472 if (isset($value[
'id']))
476 if (isset($value[
'id2x']))
481 $dataToSave[$pos] = $value;
485 $updated = $block->updateNodes([
486 $this->getCode() => $dataToSave,
490 $saved = $block->save();
498 return $updated && $saved;
setGenderData(array $genderData)
__construct(string $code, array $data)
setDefaultSrc(array $defaultSrc)
setValue(array $value, int $position)
setImageFromPath(string $path, int $position)
getValues(?int $position=null)
toLanding(?int $position=null)
setParentBlock(Data\Block $block)
static matchResizeSize(int $sourceWidth, int $sourceHeight, int $targetWidth, string $aspectName)
static addToBlock(int $blockId, $fileId, bool $temp=false)
static savePicture($file, $ext=false, $params=array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
const BX_RESIZE_IMAGE_EXACT
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']