3namespace Bitrix\Landing;
5use Bitrix\Landing\History\ActionFactory;
6use Bitrix\Landing\History\Action\BaseAction;
7use Bitrix\Landing\Internals\BlockTable;
8use Bitrix\Landing\Internals\HistoryTable;
9use Bitrix\Landing\Internals\HistoryStepTable;
10use Bitrix\Landing\Internals\LandingTable;
11use Bitrix\Main\Type\DateTime;
29 self::ENTITY_TYPE_LANDING,
30 self::ENTITY_TYPE_DESIGNER_BLOCK,
79 self::$isActive =
true;
88 self::$isActive =
false;
93 self::$multiplyMode =
true;
98 self::$multiplyMode =
false;
107 return self::$isActive;
116 if (!in_array(
$entityType, self::AVAILABLE_TYPES,
true))
139 $res = HistoryTable::query()
141 ->where(
'ENTITY_TYPE',
'=', $this->entityType)
142 ->where(
'ENTITY_ID',
'=', $this->entityId)
143 ->setOrder([
'ID' =>
'ASC'])
148 while ($row =
$res->fetch())
150 $row[
'ID'] = (int)$row[
'ID'];
151 if (!is_array($row[
'ACTION_PARAMS']))
157 $row[
'STEP'] =
$step;
158 $row[
'ENTITY_ID'] = (int)$row[
'ENTITY_ID'];
159 $row[
'MULTIPLY_ID'] = (int)$row[
'MULTIPLY_ID'];
161 if ($row[
'MULTIPLY_ID'])
163 if ($multyId && $multyId !== $row[
'MULTIPLY_ID'])
171 $row[
'ACTION_PARAMS'] = [
173 'ACTION' => $row[
'ACTION'],
174 'ACTION_PARAMS' => $row[
'ACTION_PARAMS'],
178 $multyId = $row[
'MULTIPLY_ID'];
179 $row[
'MULTIPLY'] = [$row[
'MULTIPLY_ID']];
180 unset($row[
'MULTIPLY_ID']);
181 $this->stack[
$step] = $row;
185 $this->stack[
$step - 1][
'ACTION_PARAMS'][] = [
186 'ACTION' => $row[
'ACTION'],
187 'ACTION_PARAMS' => $row[
'ACTION_PARAMS'],
189 $this->stack[
$step - 1][
'MULTIPLY'][] = $row[
'ID'];
195 $this->stack[
$step] = $row;
211 $resDelete = HistoryTable::delete($id);
212 if ($resDelete->isSuccess())
215 if (
$step > $currentStep)
220 return $this->
saveStep(max(--$currentStep, 0));
233 if (!isset($this->stack[
$step]))
239 if ($this->step <= 1)
245 if (
$step >= $this->step)
247 $step = $this->step - 1;
275 if ($this->step >= $stackCount)
281 if ($step <= $this->step)
283 $step = $this->step + 1;
333 if (!isset($this->stack[
$step]))
338 $item = $this->stack[
$step];
345 if (isset($item[
'MULTIPLY']) && is_array($item[
'MULTIPLY']) && !empty($item[
'MULTIPLY']))
347 foreach ($item[
'MULTIPLY'] as $multyId)
349 $resDelete = HistoryTable::delete($multyId);
350 if (!$resDelete->isSuccess())
358 $resDelete = HistoryTable::delete($item[
'ID']);
359 if (!$resDelete->isSuccess())
366 unset($this->stack[
$step]);
368 if ($step <= $this->step)
370 return $this->
saveStep($this->step - 1);
384 foreach ($this->stack as $item)
386 $item[
'STEP'] =
$step;
387 $newStack[
$step] = $item;
393 $this->stack = $newStack;
407 $dateEnd->add(
'-' . $days .
' days');
409 $deleteBeforeStep = 0;
410 foreach ($this->stack as $stackItem)
412 $dateCurrent = DateTime::createFromUserTime($stackItem[
'DATE_CREATE']);
413 if ($dateEnd < $dateCurrent)
417 $deleteBeforeStep = $stackItem[
'STEP'];
428 return count($this->stack);
439 $step = HistoryStepTable::query()
442 ->where(
'ENTITY_ID',
'=', $this->entityId)
443 ->where(
'ENTITY_TYPE',
'=', $this->entityType)
450 $this->stepRowId =
$step[
'ID'];
451 $this->step =
$step[
'STEP'];
455 $this->migrateStep();
470 if ($this->stepRowId)
472 $res = HistoryStepTable::update($this->stepRowId, [
'STEP' =>
$step]);
476 $res = HistoryStepTable::add([
477 'ENTITY_ID' => $this->entityId,
478 'ENTITY_TYPE' => $this->entityType,
483 if (
$res->isSuccess())
485 $this->stepRowId =
$res->getId();
499 private function migrateStep(): void
503 if ($this->entityType === self::ENTITY_TYPE_LANDING)
510 $landing = LandingTable::query()
511 ->addSelect(
'HISTORY_STEP')
512 ->where(
'ID',
'=', $this->entityId)
516 $oldStep = $landing ? $landing[
'HISTORY_STEP'] :
null;
519 if ($this->entityType === self::ENTITY_TYPE_DESIGNER_BLOCK)
521 if (!array_key_exists(
'HISTORY_STEP_DESIGNER', BlockTable::getMap()))
526 $block = BlockTable::query()
527 ->addSelect(
'HISTORY_STEP_DESIGNER')
528 ->where(
'ID',
'=', $this->entityId)
532 $oldStep = $block ? $block[
'HISTORY_STEP_DESIGNER'] :
null;
535 $isNewStepExists = HistoryStepTable::query()
538 ->where(
'ENTITY_ID',
'=', $this->entityId)
539 ->where(
'ENTITY_TYPE',
'=', $this->entityType)
544 if ($oldStep && !$isNewStepExists)
557 foreach ($this->stack as
$step => $stackItem)
561 'id' => $stackItem[
'ID'],
562 'current' =>
$step === $this->step,
563 'command' => (is_callable([$actionClass,
'getJsCommandName']))
564 ? call_user_func([$actionClass,
'getJsCommandName'])
568 'entityType' => $this->entityType,
586 $actionName = strtoupper($actionName);
597 'ENTITY_TYPE' => $this->entityType,
599 'ACTION' => $actionName,
600 'ACTION_PARAMS' =>
$action->getParams(),
607 !empty($this->stack[$this->step])
620 if ($this->step < $stackCount)
629 (self::$multiplyMode && self::$multiplyStep !==
null)
630 ? self::$multiplyStep
639 self::$multiplyStep = $nextStep;
642 if (self::$multiplyMode && self::$multiplyId !==
null)
644 $fields[
'MULTIPLY_ID'] = self::$multiplyId;
647 $resAdd = HistoryTable::add(
$fields);
650 if (self::$multiplyMode && self::$multiplyId ===
null)
652 self::$multiplyId = $resAdd->getId();
653 HistoryTable::update(self::$multiplyId, [
654 'MULTIPLY_ID' => self::$multiplyId,
658 return $resAdd->isSuccess();
669 return $this->
saveStep($this->step - 1);
693 return $this->
saveStep($this->step + 1);
717 $undo ? $this->step : ($this->step + 1),
732 if (!isset($this->stack[
$step]))
737 $stepItem = $this->stack[
$step];
738 $stepId = $stepItem[
'ID'];
740 if (isset($this->actions[$stepId][
$direction]))
745 $params = $stepItem[
'ACTION_PARAMS'];
746 if ($this->entityType === self::ENTITY_TYPE_LANDING)
750 if ($this->entityType === self::ENTITY_TYPE_DESIGNER_BLOCK)
static getAction(string $actionName, ?bool $undo=false)
static getActionClass(string $actionName, ?bool $undo=false)
static compareSteps(array $prevStep, array $nextStep)
const MULTIPLY_ACTION_NAME
static getDirectionName(?bool $undo=false)
getActionForStep(int $step, bool $undo)
getJsCommand(bool $undo=true)
fixBrokenStep(int $step, int $id)
const ENTITY_TYPE_DESIGNER_BLOCK
static bool $multiplyMode
static unsetMultiplyMode()
__construct(int $entityId, string $entityType)
const ENTITY_TYPE_LANDING
push(string $actionName, array $params)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
</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']