<?php
 namespace App\Reports\Sources; abstract class ProgressManagerAbstract { protected ?int $idReportGeneration = null; protected array $specificPhasesAndStepsCfg; protected array $extraPhasesAndStepsCfg = [ 'preCustomFilters'=>[ 'applyPreCustomFilters'=>100, ], 'processingRecords' => [ 'loopResults' => 100, ], 'postCustomFilters'=>[ 'applyPostCustomFilters'=>100, ], 'writeReport' => [ 'indexingColumns'=>7, 'initialize'=>3, 'writeFile'=>90, ], 'pivotTables' => [ 'generatingPivots'=>100, ], 'extraOptions' => [ 'sendReportsByEmail'=>100, ], ]; protected int $lastTouch = 0; public function __construct(?int $idReportGeneration=null) { if (!$this->specificPhasesAndStepsCfg) { throw new \Exception("Phases and steps were not defined for  ".get_called_class()); } if ($idReportGeneration===null) { return ; } if ($idReportGeneration<=0) { throw new \Exception("Invalid report generation id `{$idReportGeneration}` on ".__METHOD__); } $this->idReportGeneration = $idReportGeneration; } public function getReportSource() { $ns = getClassNamespace(get_called_class()); return substr($ns, strrpos($ns, '\\')+1); } public function getIdReportGeneration() :?int { return $this->idReportGeneration; } protected function getAllPhasesAndSteps() :array { return array_merge($this->specificPhasesAndStepsCfg, $this->extraPhasesAndStepsCfg); } public function setStatus(string $phase, string $step, float $stepPercent) :void { if ($stepPercent<0 or $stepPercent>100) { throw new \Exception('Invalid value for `stepPercent` param on '.__METHOD__); } $allPas = $this->getAllPhasesAndSteps(); if (!key_exists($phase, $allPas)) { throw new \Exception("Invalid phase `{$phase}` called in ".get_called_class()); } if (!key_exists($step, $allPas[$phase])) { throw new \Exception("Invalid step `{$step}` on phase `{$phase}` called in ".get_called_class()); } if (!$this->idReportGeneration) { return ; } $currentTime = time(); if ($this->lastTouch and ($currentTime-$this->lastTouch)<=2) { return ; } $this->lastTouch = $currentTime; $reportGenProgress = \Entity\ReportGeneration::updateProgress($this->idReportGeneration); $reportGenProgress->phase = $phase; $reportGenProgress->step = $step; $reportGenProgress->stepPercent = $stepPercent; $reportGenProgress->save(); } public function getProgressDetails(string $phaseCode, string $stepCode, float $stepPercent): array { \App\Loader_Lang::getInstance()->loadAppFile("_customLoad/reports/generalData.lang.php"); $reportSource = $this->getReportSource(); $source = lcfirst($reportSource); \App\Loader_Lang::getInstance()->loadAppFile("_customLoad/reports/{$source}/phasesAndSteps.lang.php"); $_LANG = \App\Loader_Lang::getInstance()->getAll(); $return = [ 'phaseName' => $_LANG['reports']['phasesAndSteps']['general']['phases'][$phaseCode] ? : $_LANG['reports']['phasesAndSteps'][$source]['phaseName'][$phaseCode] ? : $phaseCode, 'stepName' => $_LANG['reports']['phasesAndSteps']['general']['steps'][$phaseCode][$stepCode] ? : $_LANG['reports']['phasesAndSteps'][$source]['stepName'][$phaseCode][$stepCode] ? : $stepCode, ]; return $return; } } 