0) {
$step = $db->get_by_id('CRM_PROCES', $id);
$cp = new GraphViewProcessParser();
$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);
?>
TYPE == 'PROCES_INIT') : ?>
Widok mapy PARENT_ID; ?>
| mapa z zasobami
ID; ?>
- DESC; ?> DESC; ?>
| widok procesu z zasobami
OPIS; ?>
Viev_Zpc[$id]->PATH as $ind=>$id_include) : ?>
get_by_id('CRM_PROCES', $id_include); ?>
ID; ?> - DESC; ?> OPIS; ?>
ID."], Typ: ".$zasob->TYPE.", Nazwa: ".$zasob->DESC." (".$zasob->DESC_PL.")
".$zasob->OPIS;
echo "
Nadrzędny: Zasob: [".$zasob->P__ID."] , Typ: ".$zasob->P__TYPE.", Nazwa: ".$zasob->P__DESC." (".$zasob->P__DESC_PL.")
".$zasob->P__OPIS;
}
}
exit;
}
$graph = new stdClass();
$graph->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();
function graph__addNodeID($id, &$graph, $name = null, $path, $parent = null, $type, $once = null) {
if (!array_key_exists($id, $graph->treeItems)) {
$graph->treeItems[$id] = true;
if (empty($name)) $name = $id;
if (!empty($path)) {
$name = $name . " " . implode(',', $path);
}
$type_init = null;
if ($type == 'PROCES_INIT') $type_init = 'procesInit';
else if($type == 'RESOURCE') $type_init = 'RESOURCE';
$graph->elements->nodes[] = array('data' => array('id' => "{$id}", 'name' => $name, 'type' => $type_init));
}
if (!empty($parent)) {
if (isset($once)) {
if (!isset($graph->used_elements[$parent][$id]) && !isset($graph->used_elements[$id][$parent])) {
$graph->elements->edges[] = array('data' => array('source' => $parent, 'target' => $id));
}
} else {
$graph->elements->edges[] = array('data' => array('source' => $parent, 'target' => $id));
}
$graph->used_elements[$parent][$id] = 1;
$graph->used_elements[$id][$parent] = 1;
}
}
$id_zasob = V::get('id_zasob', '', $_REQUEST, 'int');
$PROCES_INIT_SCAN = V::get('PROCES_INIT_SCAN', '', $_REQUEST, 'int');
if (!empty($PROCES_INIT_SCAN)) {
$cp = new GraphViewProcessParser();
$PROCES_INIT_SCAN_STANOWISKO = V::get('PROCES_INIT_SCAN_STANOWISKO', '', $_REQUEST, 'int');
$PROCES_INIT_SCAN_USER = V::get('PROCES_INIT_SCAN_USER', '', $_REQUEST, 'int');
if (!empty($PROCES_INIT_SCAN_STANOWISKO)) {
$PROCES_INIT_SCAN_STANOWISKA = array($PROCES_INIT_SCAN_STANOWISKO);
$proces_list_obj = ProcesHelper::get_procesy_by_stanowiska($PROCES_INIT_SCAN_STANOWISKA);
foreach ($proces_list_obj as $obj) {
$init[$obj->ID] = $obj->ID;
}
} else if(!empty($PROCES_INIT_SCAN_USER)) {
$proces_list_obj = UsersHelper::get_group_by_user($PROCES_INIT_SCAN_USER, array('SHOW_IN_PERIOD_MARK' => 'YES'));
foreach ($proces_list_obj as $obj) {
$init[$obj->ID] = $obj->ID;
}
} else if(!empty($id_zasob)) {
$init = ProcesHelper::get_proces_init_by_zasob_id($id_zasob);
} else {
$init = $cp->get_proces_init($id_proces);
}
DEBUG_S(3,'lista procesow init',$init,__FILE__,__FUNCTION__,__LINE__);
foreach ($init as $id_proces) {
$tree = $cp->build_proces_init_tree($id_proces);
$cp->build_tree_flat_info($tree, null);
$cp->detect_tree_where_to_detail_cut($tree, 'nocut');
$cp->build_path_zoom_proces_cut($tree, $id_proces);
DEBUG_S(3,'get_proces_init',$init);
DEBUG_S(3,'tree->childs',$tree->Childs);
DEBUG_S(3,'tree->Parents',$tree->Parents);
DEBUG_S(3,'tree->Viev_Zpc',$tree->Viev_Zpc);
DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
DEBUG_S(3,'tree->get_resources_by_proceses_id',$tree->get_resources_by_proceses_id);
graph__addNodeID(0, $graph, $name = null, $path, null);
foreach ($tree->Viev_Zpc as $id => $obj) {
graph__addNodeID($id, $graph, $obj->DESC, null, ((isset($obj->PARENT))? $obj->PARENT : null), $tree->Childs[$id]->TYPE);
foreach ($obj->EXTERNAL_LINK as $link) {
graph__addNodeID($link, $graph, $tree->Viev_Zpc[$link]->DESC, null, $id, 'PROCES_INIT');
}
}
if (!empty($_REQUEST['RESOURCES'])) {
$resources = $cp->get_resources_by_proceses_id($tree->Childs, $id_proces, $id_zasob);
foreach ($resources['PARENT_ID'] as $ID => $DESC) {
graph__addNodeID("Z_{$ID}", $graph, $DESC, null, null, 'RESOURCE');
}
foreach ($resources['ID'] as $ID => $DESC) {
graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, $id_proces, 'RESOURCE');
graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, "Z_{$DESC['PARENT_ID']}", 'RESOURCE', 'once');
}
}
unset($tree);
}
}
else {
$cp = new GraphViewProcessParser();
$tree = $cp->build_proces_init_tree($id_proces);
$cp->build_tree_flat_info($tree, null);
$cp->detect_tree_where_to_detail_cut($tree);
$cp->build_path_zoom_proces_cut($tree, $id_proces);
DEBUG_S(3,'get_proces_init',$init);
DEBUG_S(3,'tree->childs',$tree->Childs);
DEBUG_S(3,'tree->Parents',$tree->Parents);
DEBUG_S(-3,'tree->Viev_Zpc',$tree->Viev_Zpc);
DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
DEBUG_S(3,'tree->Viev_Zpc_Parent_cut',$tree->Viev_Zpc_Parent_cut);
DEBUG_S(3,'tree->Viev_Zpc_found',$tree->Viev_Zpc_found);
graph__addNodeID(0, $graph, $name = null, $path, null);
foreach ($tree->Viev_Zpc as $id => $obj) {
graph__addNodeID($id, $graph, $obj->DESC, null, ((isset($obj->PARENT))? $obj->PARENT : null), $tree->Childs[$id]->TYPE);
foreach ($obj->INTERNAL_LINK as $link) {
graph__addNodeID($id, $graph, $tree->Viev_Zpc[$link]->DESC, null, $link, null);
}
foreach ($obj->EXTERNAL_LINK as $link) {
graph__addNodeID($link, $graph, $tree->Viev_Zpc[$link]->DESC, null, $id, 'PROCES_INIT');
}
}
if (!empty($_REQUEST['RESOURCES'])) {
$resources = $cp->get_resources_by_proceses_id($tree->Childs, $id_proces, $id_zasob);
foreach ($resources['PARENT_ID'] as $ID => $DESC) {
graph__addNodeID("Z_{$ID}", $graph, $DESC, null, null, 'RESOURCE');
}
foreach ($resources['ID'] as $ID => $DESC) {
graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, $id_proces, 'RESOURCE');
graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, "Z_{$DESC['PARENT_ID']}", 'RESOURCE');
}
}
}
foreach($graph->elements->nodes as $var) {
$nodes[$var['data']['id']] = $var['data']['id'];
}
foreach($graph->elements->edges as $var) {
if (!isset($nodes[$var['data']['source']])) echo "
FAIL1 ".$var['data']['source'];
if (!isset($nodes[$var['data']['target']])) echo "
FAIL2 ".$var['data']['target'];
}
DEBUG_S(3,'nodes',$graph->elements->nodes);
DEBUG_S(3,'edges',$graph->elements->edges);
?>
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
public function get_proces_init($id_proces) {
$db = DB::getDB();
$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}/%')
";
$res = $db->query($sql);
while ($h = $db->fetch($res)) {
$this->get_proces_init[] = $h->ID;
}
return $this->get_proces_init;
}
public function build_proces_init_tree($id_proces) {
$db = DB::getDB();
$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;
$this->build_tree_for_proces($tree, $id_proces, $id_proces);
return $tree;
}
public function build_tree_for_proces(&$tree, $cursor, $init_once = null) {
$db = DB::getDB();
$sqlOr = (!empty($init_once))? " or cp.ID={$init_once} " : "";
$sql = "select
cp.`ID`
, cp.`IF_TRUE_GOTO`
, cp.`IF_TRUE_GOTO_FLAG`
, cp.`TYPE`
from `CRM_PROCES` as cp
where
(cp.PARENT_ID={$cursor} {$sqlOr})
and cp.`A_STATUS` in('WAITING','NORMAL')
";
$res = $db->query($sql);
while ($h = $db->fetch($res)) {
if (empty($init_once)) $tree->Childs[$h->ID]->PARENT = $cursor;
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;
}
$this->build_tree_for_proces($tree, $h->ID, null);
}
}
public function get_resources_by_proceses_id($id_proces_obj, $id_proces, $filter_zasob) {
$db = DB::getDB();
$filter = "";
if (is_array($filter_zasob)) {
$filter = " and cz.ID in (".implode(',', $filter_zasob).") ";
}
else if (!empty($filter_zasob)) {
$filter = " and cz.ID={$filter_zasob}";
}
$sql = "select
cz.ID
, cz.PARENT_ID
, cz.`DESC`
, cz.`TYPE`
, czp.`DESC` as DESC_czp
, czp.`TYPE` as TYPE_czp
from CRM_WSKAZNIK as cw
left join CRM_LISTA_ZASOBOW as cz on(cz.ID=cw.ID_ZASOB)
left join CRM_LISTA_ZASOBOW as czp on(czp.ID=cz.PARENT_ID)
where cw.ID_PROCES in(".implode(',', array_keys($id_proces_obj)).")
and cw.A_STATUS in ('NORMAL','WAITING')
and czp.`TYPE` in ('TABELA')
{$filter}
";
$res = $db->query($sql);
while ($h = $db->fetch($res)) {
$found['ID'][$h->ID]['PARENT_ID'] = $h->PARENT_ID;
$found['ID'][$h->ID]['DESC'] = $h->DESC;
$found['PARENT_ID'][$h->PARENT_ID] = $h->DESC_czp;
}
return $found;
}
public function build_tree_flat_info(&$tree, $flat) {
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);
}
}
}
public 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) {
//przeciecie jezeli jest wiecej wyjsc niz jedno z zaglebieniami
$tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
}
if (isset($tree->Childs[$id]->GOTO_FLAG)) {
//przeciecie, jezeli jest wyjscie z kroku procesu do innego
$tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
}
if (isset($tree->Childs[$id]->IS_EXECUTED_BY)) {
//trzeba zbadac tez czy nie jest do niego dowiazywany w jakims miejscu proces
$tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
}
} else {
$tree->Childs[$id]->NO_CUT_FLAG = true;
}
}
}
public 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)) {
$this->zoom_process_links($tree, $init, $init);
}
if (!isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
$find[] = $init;
$this->zoom_process_links($tree, $init, $find[0]);
foreach($tree->Childs[$init]->CHILD as $id => $count) {
$this->search_parent_ids_till_cut($tree, $id, $find);
}
}
}
public function zoom_process_links($tree, $id, $root_id) {
$db = DB::getDB();
if (isset($tree->Childs[$id]->GOTO_FLAG)) {
if (isset($tree->Childs[$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;
} else {
$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
}
} else {
$tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
$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 . "}" . V::strShortUtf8($obj->DESC, 50);
if ($tree->Childs[$id]->GOTO_FLAG == 'GOTO_AND_RETURN') {
$tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->EXTERNAL_LINK[$root_id] = $root_id;
}
}
}
}
public function build_path_zoom_proces_cut(&$tree, $init, $path_zpc = array()) {
$db = DB::getDB();
foreach ($tree->Childs as $id => $obj) {
if (!isset($tree->Viev_Zpc_found[$id])) {
$find = array();
$this->search_parent_ids_till_cut($tree, $id, $find);
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;
$obj = $db->get_by_id('CRM_PROCES', $id);
$tree->Viev_Zpc[$id]->DESC = "{" . $id . "}" . V::strShortUtf8($obj->DESC, 50, '...');
}
}
foreach($tree->Viev_Zpc as $id => $obj) {
if (!isset($obj->PARENT)) {
foreach($tree->Viev_Zpc as $id_=>$obj_) {
if (isset($tree->Childs[$id_]->SOURCE)) {
if (in_array($tree->Childs[$id]->PARENT, $obj_->PATH)) {
$tree->Viev_Zpc[$id]->PARENT = $id_;
}
}
}
}
if (!isset($tree->Viev_Zpc[$id]->PARENT)) {
$tree->Viev_Zpc[$id]->PARENT = $tree->Childs[$id]->PARENT;
}
}
}
}