23 parent::__construct();
24 if (class_exists(self::getConnectorClass()))
35 return AI\Image::class;
46 self::getConnectorClass(),
68 foreach ($block->getNodes() as $node)
71 $node->getType() === NodeType::Img
72 && !$node->isAvatarNode()
75 $placeholders = $node->getPlaceholders();
76 $imageCount +=
count($placeholders);
89 if (!isset($this->siteData))
94 if (!empty($this->entities))
99 $filter = Query::filter()->logic(
'or');
100 $landingId = $this->siteData->getLandingId();
102 foreach ($this->siteData->getBlocks() as $block)
104 foreach ($block->getNodes() as $node)
107 $node->getType() === NodeType::Img
108 && !empty($node->getPromptTexts())
120 foreach ($node->getPromptTexts() as $position => $prompt)
138 ->where(
'LANDING_ID',
'=', $landingId)
139 ->where(
'BLOCK_ID',
'=', $block->getId())
140 ->where(
'NODE_CODE',
'=', $node->getCode())
141 ->where(
'POSITION',
'=', $position)
149 if (!empty($this->entities))
151 $generationId = $this->generation->getId();
152 $res = RequestToEntitiesTable::query()
161 ->where(
'STEP_REF.GENERATION_ID',
'=', $generationId)
162 ->where(
'REQUEST_REF.DELETED',
'=',
'N')
169 foreach (
$rows as $row)
172 (
int)$row[
'LANDING_ID'],
173 (
int)$row[
'BLOCK_ID'],
175 (
int)$row[
'POSITION'],
177 if (isset($this->entities[
$key]))
179 $this->entities[
$key]->requestId = (int)$row[
'REQUEST_ID'];
194 return "l{$landingId}_b{$blockId}_n{$nodeCode}_p{$position}";
199 if (!isset($this->siteData, $this->stepId))
222 $timer = $this->generation->getTimer();
223 if (!$timer->check())
225 throw new \RuntimeException(
"The maximum execution time has been reached, step {$this->stepId} was aborted");
230 $prompt->setMarkers([
'format' =>
'square']);
233 if (
$request->send($prompt, $this->connector))
238 RequestToEntitiesTable::add([
240 'ENTITY_TYPE' => RequestEntities::Image->value,
241 'LANDING_ID' =>
$entity->landingId,
242 'BLOCK_ID' =>
$entity->blockId,
243 'NODE_CODE' =>
$entity->nodeCode,
244 'POSITION' =>
$entity->position,
256 $landingId = $this->siteData->getLandingId();
257 foreach ($this->requests as
$request)
267 $timer = $this->generation->getTimer();
268 if (!$timer->check())
270 throw new \RuntimeException(
"The maximum execution time has been reached, step {$this->stepId} was aborted");
274 $relation = RequestToEntitiesTable::query()
276 ->where(
'REQUEST_ID',
'=',
$request->getId())
277 ->where(
'LANDING_ID',
'=', $landingId)
278 ->where(
'ENTITY_TYPE',
'=', RequestEntities::Image->value)
287 $blockId = (int)$relation[
'BLOCK_ID'];
288 $nodeCode = $relation[
'NODE_CODE'];
289 $position = (int)($relation[
'POSITION'] ?? 0);
291 foreach ($this->siteData->getBlocks([$blockId]) as $blockData)
293 foreach ($blockData->getNodes([$nodeCode]) as $nodeData)
297 if ($this->applyNode($nodeData, $position,
$request))
305 if ($this->fixNode($nodeData, $position))
320 $nodeData->getType() === NodeType::Img
321 && empty($nodeData->getGenderData())
332 ->setImageFromPath((
string)
$url, $position)
333 ->toLanding($position)
336 $values = $nodeData->getValues($position);
340 'blockId' => (
string)$nodeData->getParentBlock()?->getId(),
341 'selector' => $nodeData->getCode(),
342 'position' => $position,
343 'value' => !empty($values) ? array_shift($values) : [],
344 'isEditInStyle' => $nodeData->isEditInStyle(),
361 private function fixNode(
Node $node,
int $position): bool
364 $node->getType() !== NodeType::Img
365 || !empty($node->getGenderData())
371 $findInNode =
function (Node $node): ?
array
374 $node->getType() !== NodeType::Img
375 || !empty($node->getGenderData())
381 foreach ($node->getValues() as $value)
383 if (isset($value[
'id'], $value[
'id2x'], $value[
'src'], $value[
'src2x']))
396 $selectedValue = $findInNode($node);
401 && $node->getParentBlock()->getParentSite()
404 foreach ($node->getParentBlock()->getParentSite()->getBlocks() as $block)
406 foreach ($block->getNodes() as $otherNode)
408 $selectedValue = $findInNode($otherNode);
424 ->
setValue($selectedValue, $position)
425 ->toLanding($position)
431 'blockId' => (
string)$node->getParentBlock()?->getId(),
432 'selector' => $node->getCode(),
433 'position' => $position,
434 'value' => !empty($selectedValue) ? $selectedValue : [],
435 'isEditInStyle' => $node->isEditInStyle(),