ID_PROCES public $stepToGroup = array();// recurse deep => [ID_PROCES => ?] public $usedGroups = array();// ID_GROUPS => group name public $gotoIds = array(); public $procesData = array(); public function __construct($idProcesInit) { $this->initData = $this->fetchProcesIdxForInit($idProcesInit); $gotoIdsTodo = array(); foreach ($this->initData as $r) { $this->procesData[$r->ID_PROCES] = $r; $this->stepToRecDeepLvl[$r->ID_PROCES] = 0; $this->initProcesIds[$r->ID_PROCES] = true; $this->initProcesWithGroups[$r->idx_PROCES_WITH_GROUPS_ID] = true; if ($r->ID_GOTO_AND_RETURN > 0) { $gotoIdsTodo[$r->ID_GOTO_AND_RETURN][] = $r->ID_PROCES; } } if(V::get('DBG', '', $_REQUEST)){echo '
TODO: $gotoIdsTodo = ';print_r($gotoIdsTodo);echo'';} $loopLimit = 10; for ($i = 1; $i <= $loopLimit && !empty($gotoIdsTodo); $i++) { foreach ($gotoIdsTodo as $gotoId => $fromIds) { foreach ($fromIds as $fromId) { $this->gotoIds[$gotoId][] = $fromId; } } $gotoData = $this->fetchProcesIdxForGotoIds($gotoIdsTodo); $gotoIdsTodo = array(); if(V::get('DBG', '', $_REQUEST)){echo '
TODO:loop('.$i.'): $gotoData = ';print_r($gotoData);echo'';}
foreach ($gotoData as $r) {
$this->procesData[$r->ID_PROCES] = $r;
if (!array_key_exists($r->ID_PROCES, $this->stepToRecDeepLvl)) {
$this->stepToRecDeepLvl[$r->ID_PROCES] = $i;
} else {
continue;// ? throw new Exception("Loop detected");
}
if ($r->ID_GOTO_AND_RETURN > 0) {
$gotoIdsTodo[$r->ID_GOTO_AND_RETURN][] = $r->ID_PROCES;
}
}
}
$this->stepToGroup = $this->fetchGroupsByProcesIds(array_keys($this->stepToRecDeepLvl));
foreach ($this->stepToGroup as $idProces => $idGroups) {
foreach ($idGroups as $idGroup) {
$this->usedGroups[$idGroup] = true;
}
}
?>
| Lp. | idGroup | stepToRecDeepLvl as $idProces => $deepLvl) : ?>
{procesData[$idProces]->idx_PROCES_INIT_ID; ?>} |
|---|---|---|
| stepToRecDeepLvl as $idProces => $deepLvl) : ?> | stepToGroup)) { if (in_array($idGroup, $this->stepToGroup[$idProces])) { echo '#'; } else { echo '.'; } } else { echo 'x'; } ?> |
$this->stepToGroup = ';print_r($this->stepToGroup);echo''; echo '
$this->stepToRecDeepLvl = ';print_r($this->stepToRecDeepLvl);echo''; echo '
$this->gotoIds = ';print_r($this->gotoIds);echo''; echo '
$this->initProcesIds = ';print_r($this->initProcesIds);echo''; echo '
$this->initProcesWithGroups = ';print_r($this->initProcesWithGroups);echo''; echo '
$this = ';print_r($this);echo''; } $usedGroups = $this->getGroupIdsForProcesInit($idProcesInit); $usedGoto = $this->getGotoAnReturnIdsForProcesInit($idProcesInit); if(V::get('DBG', '', $_REQUEST)){ echo '
$usedGroups = ';print_r($usedGroups);echo''; echo '
$usedGoto = ';print_r($usedGoto);echo''; } } public function fetchProcesIdxForInit($idProcesInit) { $db = DB::getDB(); $data = array(); $sql = "select i.* , IF(p.`IF_TRUE_GOTO_FLAG`='GOTO_AND_RETURN' and p.`IF_TRUE_GOTO`>0 , p.`IF_TRUE_GOTO` , 0) as `ID_GOTO_AND_RETURN` from `CRM_PROCES_idx` i join `CRM_PROCES` p on(p.`ID`=i.`ID_PROCES`) where (i.`idx_PROCES_INIT_ID`='{$idProcesInit}' or i.`idx_PROCES_WITH_GROUPS_ID`='{$idProcesInit}') "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $data[] = $r; } return $data; } public function fetchProcesIdxForGotoIds($gotoIdsTodo) { $db = DB::getDB(); if (empty($gotoIdsTodo)) return; $sqlIds = array_keys($gotoIdsTodo); if (empty($sqlIds)) return; $sqlIds = implode(",", $sqlIds); $data = array(); $sql = "select i.* , IF(p.`IF_TRUE_GOTO_FLAG`='GOTO_AND_RETURN' and p.`IF_TRUE_GOTO`>0 , p.`IF_TRUE_GOTO` , 0) as `ID_GOTO_AND_RETURN` from `CRM_PROCES_idx` i join `CRM_PROCES` p on(p.`ID`=i.`ID_PROCES`) where (i.`idx_PROCES_INIT_ID` in({$sqlIds}) or i.`idx_PROCES_WITH_GROUPS_ID` in({$sqlIds})) "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $data[] = $r; } return $data; } public function fetchGroupsByProcesIds($procesIds) { $db = DB::getDB(); if (empty($procesIds)) return; $sqlIds = implode(",", $procesIds); $data = array(); $sql = "select gp.`ID_PROCES`, gp.`ID_GROUP` from `CRM_PROCES_idx_GROUP_to_PROCES` gp where gp.`ID_PROCES` in({$sqlIds}) "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $data[$r->ID_PROCES][] = $r->ID_GROUP; } return $data; } public function getGroupIdsForProcesInit($idProcesInit) { $usedGroups = array(); $db = DB::getDB(); $sql = " select gp.`ID_PROCES`, gp.`ID_GROUP` from ( select i.`idx_PROCES_WITH_GROUPS_ID` as `ID_PROCES` from `CRM_PROCES_idx` i where i.`idx_PROCES_INIT_ID`='{$idProcesInit}' group by i.`idx_PROCES_WITH_GROUPS_ID` ) gids join `CRM_PROCES_idx_GROUP_to_PROCES` gp on (gp.`ID_PROCES`=gids.`ID_PROCES`) "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $usedGroups[$r->ID_PROCES][] = $r->ID_GROUP; } return $usedGroups; } public function getGotoAnReturnIdsForProcesInit($idProcesInit) { $usedGoto = array(); $db = DB::getDB(); $sql = " select p.`ID`, p.`IF_TRUE_GOTO` from ( select i.`ID_PROCES` as `ID_PROCES` from `CRM_PROCES_idx` i where i.`idx_PROCES_INIT_ID`='{$idProcesInit}' group by i.`ID_PROCES` ) pids join `CRM_PROCES` p on (p.`ID`=pids.`ID_PROCES` and p.`IF_TRUE_GOTO_FLAG`='GOTO_AND_RETURN' and p.`IF_TRUE_GOTO`>0 ) "; $res = $db->query($sql); while ($r = $db->fetch($res)) { $usedGoto[$r->IF_TRUE_GOTO][] = $r->ID; } return $usedGoto; } }