get_proces_init=array();
// [proces_init] - A
// [step] - flat 0
// [step] - flat 3 , tree 2 , cut
// [step] - flat 0 , tree 0
// [step] - flat 1 , tree 1
// [step] - flat 1 , tree 1
// [step] - flat 0 , tree 0
// [step] - flat 1 , tree 1
// [step] - flat 0 , tree 0
//funckcja do szukania proces_init
function get_proces_init($id_proces) {
$sql= "select p.`ID`,p.`DESC` from `CRM_PROCES` as p
LEFT JOIN _CRM_PROCES_INIT_STATS AS cs ON cs.ID = p.ID
where p.`A_STATUS` in('WAITING','NORMAL') and p.`TYPE`='PROCES_INIT'
and (cs.`path` like '%/".$id_proces."/%' or cs.`path` like '%/".$id_proces."' or cs.`path` like '".$id_proces."/%' )
";
// echo $sql;
$res=DB::query($sql);
while($h=DB::fetch($res)) {
$this->get_proces_init[]=$h->ID;
}
return $this->get_proces_init;
}
function build_proces_init_tree($id_proces) {
// $tree->Childs[$id_proces]=true;
$tree->Childs[$id_proces]->PARENT=0;
$tree->Childs[$id_proces]->SOURCE='build_tree_for_proces';
$tree->Parents[0]->CHILD[$id_proces]=$id_proces;
$obj=DB::get_by_id('CRM_PROCES',$id_proces);
$tree->Childs[$id_proces]->TYPE=$obj->TYPE;
// echo "here".$id_proces;
self::build_tree_for_proces($tree,$id_proces,$id_proces);
return $tree;
}
function build_tree_for_proces(&$tree,$cursor,$init_once=null) {
if(!empty($init_once)) $sql_or=" or ID={$init_once} "; else $sql_or="";
$sql="select `ID`,`IF_TRUE_GOTO`,`IF_TRUE_GOTO_FLAG` , `TYPE` from `CRM_PROCES` where ( PARENT_ID={$cursor} {$sql_or} ) and `A_STATUS` in ('WAITING','NORMAL')";
// echo "
sql: ".$sql;
$res=DB::query($sql);
while ($h=DB::fetch($res)) {
if(empty($init_once)) $tree->Childs[$h->ID]->PARENT=$cursor; //wyzwolenie tylko pozniejsze
if(empty($init_once)) $tree->Parents[$cursor]->CHILD[$h->ID]=$h->ID;
$tree->Childs[$h->ID]->TYPE=$h->TYPE;
$tree->Childs[$h->ID]->SOURCE='build_tree_for_proces';
if($h->IF_TRUE_GOTO>0) {
$tree->Childs[$h->ID]->GOTO_FLAG=$h->IF_TRUE_GOTO_FLAG;
$tree->Childs[$h->ID]->IF_TRUE_GOTO=$h->IF_TRUE_GOTO;
$tree->Childs[$h->IF_TRUE_GOTO]->IS_EXECUTED_BY[$h->ID]=$h->ID;
}
self::build_tree_for_proces($tree,$h->ID,null);
}
}
function build_tree_flat_info(&$tree,$flat) {
/* >> zbudowanie ile ma dzieci <<
$tree->Childs[3208] => stdClass Object
(
[PARENT] => 3123
[CHILD] => Array
(
>> [3219] => 1 <<
>> [3237] => 0 <<
>> [3209] => 0 <<
*/
foreach($tree->Childs as $id=>$obj) {
//sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
foreach($tree->Parents[$id]->CHILD as $child) {
$tree->Childs[$id]->CHILD[$child]=count($tree->Parents[$child]->CHILD);
}
}
}
function detect_tree_where_to_detail_cut(&$tree,$flag_not_to_cut=null) {
foreach($tree->Childs as $id=>$obj) {
//sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
$control=0;
foreach($obj->CHILD as $child) {
if($child>0) $control++;
}
if(empty($flag_not_to_cut)) {
if($control>1) $tree->Childs[$id]->TO_DETAIL_CUT_FLAG=true; //przeciecie jezeli jest wiecej wyjsc niz jedno z zaglebieniami
//przeciecie, jezeli jest wyjscie z kroku procesu do innego
if(isset($tree->Childs[$id]->GOTO_FLAG)) $tree->Childs[$id]->TO_DETAIL_CUT_FLAG=true;
//trzeba zbadac tez czy nie jest do niego dowiazywany w jakims miejscu proces
if(isset($tree->Childs[$id]->IS_EXECUTED_BY)) { $tree->Childs[$id]->TO_DETAIL_CUT_FLAG=true;
//echo "
Is executed by CUT!";
}
} else $tree->Childs[$id]->NO_CUT_FLAG=true;
}
}
function search_parent_ids_till_cut(&$tree,$init,&$find) {
//szukam lancuchow do optymalizacji do miejsca flagi CUT, kojarzac od razu linki
if(isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
//if(!empty($find))
//if($init==2444)
self::zoom_process_links($tree,$init,$init);
}
// $tree->Viev_Zpc_Parent_cut[$init]=$find[0];
if(!isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
$find[]=$init;
self::zoom_process_links($tree,$init,$find[0]);
foreach($tree->Childs[$init]->CHILD as $id=>$count) {
self::search_parent_ids_till_cut($tree,$id,$find);
}
} //else
// return $find;
}
function zoom_process_links($tree,$id,$root_id) {
//dobudowuje znaczniki dotyczace LINKOW oraz brakujace ID z tym zwiazane
//echo "
testuje zoom dla ".$id." root:".$root_id;
if(isset($tree->Childs[$id]->GOTO_FLAG)) {
if(isset( $tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO])) {
//adding internal link to the same process
//TODO trzeba przemyslec, czy dowiazywac linki do zagregowanych krokow, czy trzeba robic cut w tych miejscach - na ten moment domyslnie CUT
// if(empty($tree->Childs[$id]->NO_CUT_FLAG)) //tylko linki zewnetrzne jak flaga NOCUT!
//echo "... dodaje 218: ".$tree->Childs[$id]->IF_TRUE_GOTO;
if(isset($tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO]->SOURCE)) {
$tree->Viev_Zpc[$root_id]->INTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
//echo "dodalem Linka dla ".$root_id;
} else { //echo "To jest link external - bo referencyjny ID{$tree->Childs[$id]->IF_TRUE_GOTO}nie byl w procesie";
$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
}
} else { //echo "
Links zewnetrzny do ".$id." - ".$tree->Childs[$id]->IF_TRUE_GOTO;
$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO;
//$tree->Viev_Zpc_found[$tree->Childs[$id]->IF_TRUE_GOTO]=$tree->Childs[$id]->IF_TRUE_GOTO; //zeby tego rekordu nie przetwarzal ? TODO ?
$obj=DB::get_by_id('CRM_PROCES',$tree->Childs[$id]->IF_TRUE_GOTO);
$tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->DESC="{".$obj->ID."}".substr($obj->DESC,0,50);
if($tree->Childs[$id]->GOTO_FLAG=='GOTO_AND_RETURN') { //dodanie zwrotnej strzalki TODO dac inny typ strzalki!!
$tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->EXTERNAL_LINK[$root_id]=$root_id;
//echo "
GOTO_AND_RETURN!!!".$tree->Childs[$id]->IF_TRUE_GOTO." -- ".$root_id;
}
}
}
}
function build_path_zoom_proces_cut(&$tree,$init,$path_zpc=array()) {
//funkcja do pokazania procesow wyplaszczonych, z wypunktowanymi rozgalezieniami - buduje drzewo w sposob inteligentny
//szukam rekordow z gory do pierwszego CUT
foreach($tree->Childs as $id=>$obj) {
if(!isset($tree->Viev_Zpc_found[$id])) {
//echo "
szukam parentow dla ".$id;
self::search_parent_ids_till_cut($tree,$id,$find);
// echo "
find:238 for id {$id} ".implode(',', $find)." EOL. ";
if(empty($find)) { //echo " - Find empty for ".$id." adding ".$tree->Childs[$id]->PARENT;
//trzeba przeskanowac w find jest dany parent -> Viev_Zpc_found
// if(isset($tree->Childs[$id]->PARENT))
// $tree->Viev_Zpc_Parent[$id]=$tree->Childs[$id]->PARENT;
}
foreach($find as $find_id) {
$tree->Viev_Zpc_found[$find_id]=$find[0];
if($find_id<>$find[0]) $tree->Viev_Zpc_Parent[$find_id]=$find[0]; //todo moze byc to z bledem jak nadrzedny bedzie zbitym ciagiem
else $tree->Viev_Zpc_Parent[$find_id]=$tree->Childs[$find_id]->PARENT;
}
$tree->Viev_Zpc[$id]->PATH=$find;
//wykrycie parenta polega na znalezieniu jego naturalnego parenta i poszukaniu w ktorej jest grupie
//$tree->Viev_Zpc[$id]->PARENT=$tree->Viev_Zpc_Parent[$tree->Childs[$id]->PARENT] ;
$obj=DB::get_by_id('CRM_PROCES',$id);
$tree->Viev_Zpc[$id]->DESC="{".$id."}".substr($obj->DESC,0,50)."...";
unset($find);
}
}
//parenty trzeba zrobic za drugim rzutem
foreach($tree->Viev_Zpc as $id=>$obj) {
// echo "
256 wykrywam parenta dla {$id}";
{
//skanujemy wszystkie rekordy w Viev_Zpc w celu znalezienia czy danego ID parent nie jest w ktoryms z ID - tego szukamy
if(!isset($obj->PARENT)) //tylko dla tych ktore nie maja parentow
foreach($tree->Viev_Zpc as $id_=>$obj_) {
if(isset($tree->Childs[$id_]->SOURCE))
if(in_array($tree->Childs[$id]->PARENT, $obj_->PATH)) {
// echo "
206 Skanuje dla brakujacego parenta dla ".$id." i znalazlem".$id_;
$tree->Viev_Zpc[$id]->PARENT=$id_;
} //else echo "
199: nie znalazlem w ".$id_." path:".implode(',', $obj_->PATH);
}
if(!isset($tree->Viev_Zpc[$id]->PARENT)) { //jezeli nie znaleziono ta metoda to znaczy ze parent jest naturalny
$tree->Viev_Zpc[$id]->PARENT=$tree->Childs[$id]->PARENT;
// echo " - 204 ustawilem ostatecznie ".$tree->Childs[$id]->PARENT;
}
}
}
}
}
function GRAPH_VIEW_PROCES() {
$id_proces = V::get('id_proces', '', $_REQUEST, 'int');
// $id_proces = $_REQUEST['id_proces'];
//TOOD bug funkcji V nie mozna dac INT=0!!!
// if (empty($id_proces)) {
// echo'
'."Wrong ID".'
'; // return; // } $db = DB::getDB(); //$proces = $db->get_by_id('CRM_PROCES', $id_proces); //if (empty($proces)) { // echo''."Process {$id_proces} not exists".'
'; // return; //} $ajaxTask = V::get('ajaxTask', '', $_REQUEST); if ($ajaxTask == 'getInfo') { $id = V::get('id', 0, $_REQUEST, 'int'); if ($id > 0) { //TODO najlepiej wyslac to od razu w jsonie i przekazac jakos do uzycia do wykresu! $step = $db->get_by_id('CRM_PROCES', $id); $cp=new crm_proces_paser; $tree=$cp->build_proces_init_tree($id); $cp->build_tree_flat_info($tree,null); $cp->detect_tree_where_to_detail_cut($tree); $cp->build_path_zoom_proces_cut($tree,$id); //echo' (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($step);echo'';
?>
TYPE=='PROCES_INIT') echo "PARENT_ID}&PROCES_INIT_SCAN=1>Widok mapy {$step->PARENT_ID}"; ?>
".$step->ID." - ".$step->DESC; ?> DESC; ?>
OPIS; ?>
Viev_Zpc[$id]->PATH as $ind=>$id_include) { if($ind==0) continue; //pierwszy wiersz wyswietlony wyzej $step = $db->get_by_id('CRM_PROCES', $id_include); echo "".$step->ID." - ".$step->DESC." ".$step->OPIS."
"; } ?> htmlID = 'graph_proces_id_' . $id_proces; $graph->procesTreeFlat = array(); $graph->procesTreeGoto = array(); $graph->treeItems = array(); $graph->elements = new stdClass(); $graph->elements->nodes = array(); $graph->elements->edges = array(); /* elements: { nodes: [ { data: { id: 'j', name: 'Jerry' } }, { data: { id: 'e', name: 'Elaine' } }, { data: { id: 'k', name: 'Kramer' } }, { data: { id: 'g', name: 'George' } } ], edges: [ { data: { source: 'j', target: 'e' } }, { data: { source: 'j', target: 'k' } }, { data: { source: 'j', target: 'g' } }, { data: { source: 'e', target: 'j' } }, { data: { source: 'e', target: 'k' } }, { data: { source: 'k', target: 'j' } }, { data: { source: 'k', target: 'e' } }, { data: { source: 'k', target: 'g' } }, { data: { source: 'g', target: 'j' } } ] }, */ function graph__addNodeID($id, &$graph,$name=null,$path,$parent=null,$type) { if (!array_key_exists($id, $graph->treeItems)) { $graph->treeItems[$id]= true; if(empty($name)) $name=$id; if(!empty($path)) { $name=$name." ".implode(',', $path);// $path=array(); } //DEBUG_S(-3,'added id,name,path,parent',array($id,$name,$path,$parent),__FILE__,__FUNCTION__,__LINE__); if($type=='PROCES_INIT') $type_init='procesInit'; else $type_init=null; //echo $type_init.$id; $graph->elements->nodes[] = array('data'=>array('id'=>"".$id."", 'name'=>$name , 'type'=>$type_init)); //echo " (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r("TODO: add node ($kID); add edge from $kID to $vGotoID");echo'';
graph__addNodeID($kID, $graph);
//$graph->elements->edges[] = array('data'=>array('source'=>$kID, 'target'=>$vGotoID, 'type'=>'GOTO'));
}
}
}
}
*/
?>