36 private static $countId = 0;
48 if (static::class !== __CLASS__)
50 $title = static::getTitle();
51 $ids = [static::$moduleId => [static::class]];
52 return call_user_func([__CLASS__,
"getHtml"], $ids,
$title);
61 $ids = [$ids =>
null];
69 if (is_string($classesId))
71 $classesId = [$classesId];
73 if (is_array($classesId))
75 foreach ($classesId as $classId)
77 if ((
$option = Option::get($category, $classId)) !==
"")
83 elseif (is_null($classesId))
85 $options = Option::getForModule($category);
96 "title" =>
$option[
"title"] ??
'',
109 $id = ++self::$countId;
112 $progress =
$count > 0 ? intval($steps * 100 /
$count) : 0;
114<div
class=
"main-stepper main-stepper-show" id=
"{$id}-container" data-bx-steps-
count=
"{$count}">
115 <div
class=
"main-stepper-info" id=
"{$id}-title">{
$title}</div>
116 <div
class=
"main-stepper-inner">
117 <div
class=
"main-stepper-bar">
118 <div
class=
"main-stepper-bar-line" id=
"{$id}-bar" style=
"width:{$progress}%;"></div>
120 <div
class=
"main-stepper-steps"><span
id=
"{$id}-steps">{$steps}</span> / <span
id=
"{$id}-count">{
$count}</span></div>
121 <div
class=
"main-stepper-error-text" id=
"{$id}-error"></div>
125 $return = Json::encode($return);
127<div
class=
"main-stepper-block">{
$result}
128<script>BX.ready(
function(){
if (BX && BX[
"UpdateStepperRegister"]) { BX.UpdateStepperRegister({$id}, {$return}); }});</script>
137 return Loc::getMessage(
"STEPPER_TITLE");
149 $className = get_class($updater);
151 $option = Option::get(
"main.stepper." . $updater->getModuleId(), $className);
158 $updater->setOuterParams(func_get_args());
162 if ($updater->execute(
$option) === self::CONTINUE_EXECUTION)
165 $threshold = (float)(
$option[
"thresholdTime"] ?? self::THRESHOLD_TIME);
167 if ($executeTime > $threshold)
170 $delayCoefficient = (float)(
$option[
"delayCoefficient"] ?? self::DELAY_COEFFICIENT);
173 $pPERIOD = (int)round($executeTime + $executeTime * $delayCoefficient);
178 $option[
"lastTime"] = $executeTime;
179 $option[
"totalTime"] = (float)(
$option[
"totalTime"] ?? 0.0) + $executeTime;
180 $option[
"title"] = $updater::getTitle();
182 Option::set(
"main.stepper." . $updater->getModuleId(), $className, serialize(
$option));
184 return $className .
'::execAgent(' . $updater::makeArguments($updater->getOuterParams()) .
');';
187 Option::delete(
'main.stepper.' . $updater->getModuleId(), [
'name' => $className]);
188 Option::delete(
'main.stepper.' . $updater->getModuleId(), [
'name' =>
'\\' . $className]);
224 if (is_array($arguments))
226 foreach ($arguments as
$key =>
$val)
237 return implode(
", ", $arguments);
257 return static::$moduleId;
266 public static function bind($delay = 300, $withArguments = [])
269 $c = get_called_class();
270 self::bindClass($c, $c::getModuleId(), $delay, $withArguments);
281 public static function bindClass($className,
$moduleId, $delay = 300, $withArguments = [])
283 if (class_exists(
"\CAgent"))
286 $withArguments = is_array($withArguments) ? $withArguments : [];
288 $delay = (int)$delay;
292 $addAgent = (
'' !== call_user_func_array([$className,
"execAgent"], $withArguments));
297 if (Option::get(
"main.stepper." .
$moduleId, $className) ===
"")
299 Option::set(
"main.stepper." .
$moduleId, $className, serialize([]));
301 \CTimeZone::Disable();
303 $className .
'::execAgent(' . (empty($withArguments) ?
'' : call_user_func_array([$className,
"makeArguments"], [$withArguments])) .
');',
309 date(Main\Type\Date::convertFormatToPhp(\CSite::GetDateFormat()), time() + $delay),
314 \CTimeZone::Enable();
319 $connection = \Bitrix\Main\Application::getConnection();
323 if (!empty($withArguments))
325 $arguments = class_exists($className)
326 ? call_user_func_array([$className,
"makeArguments"], [$withArguments])
329 $name = $helper->forSql($className .
'::execAgent(' . $arguments .
');', 2000);
330 $className = $helper->forSql($className);
332 $agent =
$connection->query(
"SELECT ID FROM b_agent WHERE MODULE_ID='" .
$moduleId .
"' AND NAME = '" .
$name .
"' AND USER_ID IS NULL")->fetch();
336 "INSERT INTO b_agent (MODULE_ID, SORT, NAME, ACTIVE, AGENT_INTERVAL, IS_PERIOD, NEXT_EXEC)
337 VALUES ('" .
$moduleId .
"', 100, '" .
$name .
"', 'Y', 1, 'Y', " . ($delay > 0 ? $helper->addSecondsToDateTime($delay) : $helper->getCurrentDateTimeFunction()) .
")"
339 $merge = $helper->prepareMerge(
341 [
'MODULE_ID',
'NAME'],
343 'MODULE_ID' =>
'main.stepper.' .
$moduleId,
344 'NAME' => $className,
366 $data = Context::getCurrent()->getRequest()->getPost(
"stepper");
369 foreach (
$data as $stepper)
371 if ((
$option = Option::get(
"main.stepper." . $stepper[
"moduleId"], $stepper[
"class"])) !==
"" &&
372 (
$res = unserialize(
$option, [
'allowed_classes' =>
false])) && is_array(
$res))
375 "moduleId" => $stepper[
"moduleId"],
376 "class" => $stepper[
"class"],
377 "steps" =>
$res[
"steps"],
378 "count" =>
$res[
"count"],
392 private static function sendJson(
$result)
397 header(
'Content-Type:application/json; charset=UTF-8');
400 \CMain::finalActions();
407 $exceptionHandler =
$application->getExceptionHandler();
408 $exceptionHandler->writeToLog($exception);
writeToLog(\Exception $exception)
setOuterParams(array $outerParams)
static makeArguments($arguments=[])
static getHtml($ids=[], $title="")
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)