superedit-GRAPH_VIEW_PROCES.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <?php
  2. function GRAPH_VIEW_PROCES() {
  3. $id_proces = V::get('id_proces', '', $_REQUEST, 'int');
  4. $id_zasob = V::get('id_zasob', '', $_REQUEST, 'int');
  5. $db = DB::getDB();
  6. $ajaxTask = V::get('ajaxTask', '', $_REQUEST);
  7. if ($ajaxTask == 'getInfo') {
  8. $id = V::get('id', 0, $_REQUEST, 'int');
  9. $id_zasob = V::get('id_zasob', '', $_REQUEST, 'int');
  10. if ($id > 0) {
  11. $step = $db->get_by_id('CRM_PROCES', $id);
  12. $cp = new GraphViewProcessParser();
  13. $tree = $cp->build_proces_init_tree($id);
  14. $cp->build_tree_flat_info($tree, null);
  15. $cp->detect_tree_where_to_detail_cut($tree);
  16. $cp->build_path_zoom_proces_cut($tree, $id);
  17. ?>
  18. <?php if ($step->TYPE == 'PROCES_INIT') : ?>
  19. <a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $step->PARENT_ID; ?>&PROCES_INIT_SCAN=1">Widok mapy <?php echo $step->PARENT_ID; ?></a>
  20. <?php endif; ?>
  21. <?php if (empty($_REQUEST['RESOURCES'])) : ?>
  22. <a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $step->PARENT_ID; ?>&PROCES_INIT_SCAN=1&RESOURCES=1&id_zasob=<?php echo $id_zasob; ?>"> | mapa z zasobami</a>
  23. <?php endif; ?>
  24. <p>
  25. <span style="color:red">
  26. <a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id; ?>"><?php echo $step->ID; ?></a>
  27. - <?php echo $step->DESC; ?> <?php echo $step->DESC; ?>
  28. </span>
  29. | <a href="?FUNCTION_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id; ?>&RESOURCES=1&id_zasob=<?php echo $id_zasob; ?>"> widok procesu z zasobami </a>
  30. </p>
  31. <p><?php echo $step->OPIS; ?></p>
  32. <?php foreach ($tree->Viev_Zpc[$id]->PATH as $ind=>$id_include) : ?>
  33. <?php if ($ind == 0) continue; //pierwszy wiersz wyswietlony wyzej ?>
  34. <?php $step = $db->get_by_id('CRM_PROCES', $id_include); ?>
  35. <p><b><?php echo $step->ID; ?></a> - <?php echo $step->DESC; ?></b> <font size="-3"><?php echo $step->OPIS; ?></font></p>
  36. <?php endforeach; ?>
  37. <?php
  38. }
  39. else {//zasob
  40. $id = V::get('id', 0, $_REQUEST);
  41. if ($id[0] == 'Z') {
  42. Lib::loadClass('ProcesHelper');
  43. $zasob = ProcesHelper::getZasobInfo(4975);
  44. echo "Zasob: [".$zasob->ID."], Typ: ".$zasob->TYPE.", Nazwa: ".$zasob->DESC." (".$zasob->DESC_PL.")<br>".$zasob->OPIS;
  45. echo "<hr> Nadrzędny: Zasob: [".$zasob->P__ID."] , Typ: ".$zasob->P__TYPE.", Nazwa: ".$zasob->P__DESC." (".$zasob->P__DESC_PL.")<br>".$zasob->P__OPIS;
  46. }
  47. }
  48. exit;
  49. }
  50. $graph = new stdClass();
  51. $graph->htmlID = "graph_proces_id_{$id_proces}";
  52. $graph->procesTreeFlat = array();
  53. $graph->procesTreeGoto = array();
  54. $graph->treeItems = array();
  55. $graph->elements = new stdClass();
  56. $graph->elements->nodes = array();
  57. $graph->elements->edges = array();
  58. function graph__addNodeID($id, &$graph, $name = null, $path, $parent = null, $type, $once = null) {
  59. if (!array_key_exists($id, $graph->treeItems)) {
  60. $graph->treeItems[$id] = true;
  61. if (empty($name)) $name = $id;
  62. if (!empty($path)) {
  63. $name = $name . " " . implode(',', $path);
  64. }
  65. $type_init = null;
  66. if ($type == 'PROCES_INIT') $type_init = 'procesInit';
  67. else if($type == 'RESOURCE') $type_init = 'RESOURCE';
  68. $graph->elements->nodes[] = array('data' => array('id' => "{$id}", 'name' => $name, 'type' => $type_init));
  69. }
  70. if (!empty($parent)) {
  71. if (isset($once)) {
  72. if (!isset($graph->used_elements[$parent][$id]) && !isset($graph->used_elements[$id][$parent])) {
  73. $graph->elements->edges[] = array('data' => array('source' => $parent, 'target' => $id));
  74. }
  75. } else {
  76. $graph->elements->edges[] = array('data' => array('source' => $parent, 'target' => $id));
  77. }
  78. $graph->used_elements[$parent][$id] = 1;
  79. $graph->used_elements[$id][$parent] = 1;
  80. }
  81. }
  82. $id_zasob = V::get('id_zasob', '', $_REQUEST, 'int');
  83. $PROCES_INIT_SCAN = V::get('PROCES_INIT_SCAN', '', $_REQUEST, 'int');
  84. if (!empty($PROCES_INIT_SCAN)) {
  85. $cp = new GraphViewProcessParser();
  86. $PROCES_INIT_SCAN_STANOWISKO = V::get('PROCES_INIT_SCAN_STANOWISKO', '', $_REQUEST, 'int');
  87. $PROCES_INIT_SCAN_USER = V::get('PROCES_INIT_SCAN_USER', '', $_REQUEST, 'int');
  88. if (!empty($PROCES_INIT_SCAN_STANOWISKO)) {
  89. Lib::loadClass('ProcesHelper');
  90. $PROCES_INIT_SCAN_STANOWISKA = array($PROCES_INIT_SCAN_STANOWISKO);
  91. $proces_list_obj = ProcesHelper::get_procesy_by_stanowiska($PROCES_INIT_SCAN_STANOWISKA);
  92. foreach ($proces_list_obj as $obj) {
  93. $init[$obj->ID] = $obj->ID;
  94. }
  95. } else if(!empty($PROCES_INIT_SCAN_USER)) {
  96. Lib::loadClass('UsersHelper');
  97. $proces_list_obj = UsersHelper::get_group_by_user($PROCES_INIT_SCAN_USER, array('SHOW_IN_PERIOD_MARK' => 'YES'));
  98. foreach ($proces_list_obj as $obj) {
  99. $init[$obj->ID] = $obj->ID;
  100. }
  101. } else if(!empty($id_zasob)) {
  102. Lib::LoadClass('ProcesHelper');
  103. $init = ProcesHelper::get_proces_init_by_zasob_id($id_zasob);
  104. } else {
  105. $init = $cp->get_proces_init($id_proces);
  106. }
  107. DEBUG_S(3,'lista procesow init',$init,__FILE__,__FUNCTION__,__LINE__);
  108. foreach ($init as $id_proces) {
  109. $tree = $cp->build_proces_init_tree($id_proces);
  110. $cp->build_tree_flat_info($tree, null);
  111. $cp->detect_tree_where_to_detail_cut($tree, 'nocut');
  112. $cp->build_path_zoom_proces_cut($tree, $id_proces);
  113. DEBUG_S(3,'get_proces_init',$init);
  114. DEBUG_S(3,'tree->childs',$tree->Childs);
  115. DEBUG_S(3,'tree->Parents',$tree->Parents);
  116. DEBUG_S(3,'tree->Viev_Zpc',$tree->Viev_Zpc);
  117. DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
  118. DEBUG_S(3,'tree->get_resources_by_proceses_id',$tree->get_resources_by_proceses_id);
  119. graph__addNodeID(0, $graph, $name = null, $path, null);
  120. foreach ($tree->Viev_Zpc as $id => $obj) {
  121. graph__addNodeID($id, $graph, $obj->DESC, null, ((isset($obj->PARENT))? $obj->PARENT : null), $tree->Childs[$id]->TYPE);
  122. foreach ($obj->EXTERNAL_LINK as $link) {
  123. graph__addNodeID($link, $graph, $tree->Viev_Zpc[$link]->DESC, null, $id, 'PROCES_INIT');
  124. }
  125. }
  126. if (!empty($_REQUEST['RESOURCES'])) {
  127. $resources = $cp->get_resources_by_proceses_id($tree->Childs, $id_proces, $id_zasob);
  128. foreach ($resources['PARENT_ID'] as $ID => $DESC) {
  129. graph__addNodeID("Z_{$ID}", $graph, $DESC, null, null, 'RESOURCE');
  130. }
  131. foreach ($resources['ID'] as $ID => $DESC) {
  132. graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, $id_proces, 'RESOURCE');
  133. graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, "Z_{$DESC['PARENT_ID']}", 'RESOURCE', 'once');
  134. }
  135. }
  136. unset($tree);
  137. }
  138. }
  139. else {
  140. $cp = new GraphViewProcessParser();
  141. $tree = $cp->build_proces_init_tree($id_proces);
  142. $cp->build_tree_flat_info($tree, null);
  143. $cp->detect_tree_where_to_detail_cut($tree);
  144. $cp->build_path_zoom_proces_cut($tree, $id_proces);
  145. DEBUG_S(3,'get_proces_init',$init);
  146. DEBUG_S(3,'tree->childs',$tree->Childs);
  147. DEBUG_S(3,'tree->Parents',$tree->Parents);
  148. DEBUG_S(-3,'tree->Viev_Zpc',$tree->Viev_Zpc);
  149. DEBUG_S(3,'tree->Viev_Zpc_Parent',$tree->Viev_Zpc_Parent);
  150. DEBUG_S(3,'tree->Viev_Zpc_Parent_cut',$tree->Viev_Zpc_Parent_cut);
  151. DEBUG_S(3,'tree->Viev_Zpc_found',$tree->Viev_Zpc_found);
  152. graph__addNodeID(0, $graph, $name = null, $path, null);
  153. foreach ($tree->Viev_Zpc as $id => $obj) {
  154. graph__addNodeID($id, $graph, $obj->DESC, null, ((isset($obj->PARENT))? $obj->PARENT : null), $tree->Childs[$id]->TYPE);
  155. foreach ($obj->INTERNAL_LINK as $link) {
  156. graph__addNodeID($id, $graph, $tree->Viev_Zpc[$link]->DESC, null, $link, null);
  157. }
  158. foreach ($obj->EXTERNAL_LINK as $link) {
  159. graph__addNodeID($link, $graph, $tree->Viev_Zpc[$link]->DESC, null, $id, 'PROCES_INIT');
  160. }
  161. }
  162. if (!empty($_REQUEST['RESOURCES'])) {
  163. $resources = $cp->get_resources_by_proceses_id($tree->Childs, $id_proces, $id_zasob);
  164. foreach ($resources['PARENT_ID'] as $ID => $DESC) {
  165. graph__addNodeID("Z_{$ID}", $graph, $DESC, null, null, 'RESOURCE');
  166. }
  167. foreach ($resources['ID'] as $ID => $DESC) {
  168. graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, $id_proces, 'RESOURCE');
  169. graph__addNodeID("Z_{$ID}", $graph, $DESC['DESC'], null, "Z_{$DESC['PARENT_ID']}", 'RESOURCE');
  170. }
  171. }
  172. }
  173. foreach($graph->elements->nodes as $var) {
  174. $nodes[$var['data']['id']] = $var['data']['id'];
  175. }
  176. foreach($graph->elements->edges as $var) {
  177. if (!isset($nodes[$var['data']['source']])) echo "<br>FAIL1 ".$var['data']['source'];
  178. if (!isset($nodes[$var['data']['target']])) echo "<br>FAIL2 ".$var['data']['target'];
  179. }
  180. DEBUG_S(3,'nodes',$graph->elements->nodes);
  181. DEBUG_S(3,'edges',$graph->elements->edges);
  182. ?>
  183. <style type="text/css">
  184. #<?php echo $graph->htmlID; ?>_wrap {
  185. position:relative;
  186. width:1100px;
  187. margin:0 auto;
  188. border:1px solid #ccc;
  189. }
  190. #<?php echo $graph->htmlID; ?> {
  191. height:860px;
  192. border-bottom:1px solid #ccc;
  193. }
  194. #<?php echo $graph->htmlID; ?>_info {
  195. padding:3px;
  196. }
  197. #<?php echo $graph->htmlID; ?>_wrap .actions { position:absolute; top:20px; left:-40px; margin:0; padding:0; list-style:none; }
  198. #<?php echo $graph->htmlID; ?>_wrap .actions button { border-radius:0; background:#fff; border:1px solid #ccc; }
  199. </style>
  200. <script src="./stuff/cytoscape.js/arbor.js"></script>
  201. <script src="./stuff/cytoscape.js/cytoscape.js"></script>
  202. <script>
  203. jQuery(loadInfo = function(nodeID){
  204. $.ajax({
  205. url: 'index.php?MENU_INIT=GRAPH_VIEW_PROCES&id_proces=<?php echo $id_proces; ?>&ajaxTask=getInfo&id=' + nodeID + '&id_zasob=<?php echo $id_zasob; ?>&HEADER_NOT_INIT=YES',
  206. type: 'GET',
  207. dataType: 'text',
  208. data: '',
  209. async: true,
  210. success: function (data) {
  211. jQuery('#<?php echo $graph->htmlID; ?>_info').html(data);
  212. },
  213. error: function (err) {
  214. console.log('err');
  215. }
  216. });
  217. });
  218. jQuery(loadCy = function(){
  219. jQuery('#<?php echo $graph->htmlID; ?>').cytoscape({
  220. layout: {
  221. name: 'arbor'
  222. },
  223. style: cytoscape.stylesheet()
  224. .selector('node')
  225. .css({
  226. 'shape': 'rectangle',
  227. 'width': '100px', 'height': '8px',
  228. 'font-size': '10px',
  229. 'content': 'data(name)',
  230. 'text-valign': 'center',
  231. 'color': 'white',
  232. 'text-outline-width': 2,
  233. 'text-outline-color': '#888'
  234. })
  235. .selector('edge')
  236. .css({
  237. 'target-arrow-shape': 'triangle'
  238. })
  239. .selector(':selected')
  240. .css({
  241. 'background-color': 'black',
  242. 'line-color': 'black',
  243. 'target-arrow-color': 'black',
  244. 'source-arrow-color': 'black'
  245. })
  246. .selector('.faded')
  247. .css({
  248. 'opacity': 0.25,
  249. 'text-opacity': 0
  250. })
  251. .selector('edge.neighborhood')
  252. .css({
  253. 'background-color': 'blue',
  254. 'color': 'orange'
  255. })
  256. .selector('node.procesInit')
  257. .css({
  258. 'background-color': 'red',
  259. 'text-outline-color': 'red',
  260. 'font-weight': 'bold'
  261. })
  262. .selector('node.RESOURCE')
  263. .css({
  264. 'background-color': 'black',
  265. 'text-outline-color': 'black',
  266. 'font-weight': 'normal','font-size': '8'
  267. })
  268. ,
  269. elements: <?php echo json_encode($graph->elements); ?>,
  270. ready: function(){
  271. var cy = this;
  272. window.cy_<?php echo $graph->htmlID; ?> = this;
  273. cy.elements("node[type = 'procesInit']").addClass('procesInit');
  274. cy.elements("node[type = 'RESOURCE']").addClass('RESOURCE');
  275. cy.elements("node[lvl > 1]").hide();
  276. cy.elements().unselectify();
  277. cy.on('tap', 'node', function(e){
  278. //console.log('on tap node', e)
  279. var node = e.cyTarget;
  280. var neighborhood = node.neighborhood().add(node);
  281. var nodeID = node.id();
  282. loadInfo(nodeID);
  283. cy.elements().addClass('faded').unselect();
  284. neighborhood.removeClass('faded');
  285. node.select();
  286. cy.edges().removeClass('neighborhood');
  287. node.connectedEdges().addClass('neighborhood');
  288. neighborhood.show();
  289. cy.center(neighborhood);
  290. });
  291. cy.on('tap', function(e){
  292. if (e.cyTarget === cy){
  293. cy.elements().removeClass('faded');
  294. }
  295. });
  296. },
  297. showOverlay: false
  298. });
  299. });
  300. jQuery(document).ready(function(){
  301. loadCy();
  302. var parent = $('#<?php echo $graph->htmlID; ?>')
  303. .parent()
  304. parent.find('.actions .cy-refresh')
  305. .on('mousedown touchstart', function(){
  306. loadCy();
  307. cy.attr('style', '');
  308. });
  309. parent.find('.actions .cy-zoom-plus')
  310. .on('mousedown touchstart', function(){
  311. window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() + 0.1);
  312. });
  313. parent.find('.actions .cy-zoom-minus')
  314. .on('mousedown touchstart', function(){
  315. window.cy_<?php echo $graph->htmlID; ?>.zoom(window.cy_<?php echo $graph->htmlID; ?>.zoom() - 0.1);
  316. });
  317. });
  318. </script>
  319. <div id="<?php echo $graph->htmlID; ?>_wrap">
  320. <div id="<?php echo $graph->htmlID; ?>"></div>
  321. <div id="<?php echo $graph->htmlID; ?>_info"></div>
  322. <ul class="actions">
  323. <li><button class="btn cy-refresh"><i title="Refresh" class="ico-refresh"></i></button></li>
  324. <li><button class="btn cy-zoom-plus"><i title="Zoom +" class="ico-plus"></i></button></li>
  325. <li><button class="btn cy-zoom-minus"><i title="Zoom -" class="ico-minus"></i></button></li>
  326. </ul>
  327. </div>
  328. <?php
  329. }
  330. class GraphViewProcessParser {
  331. // var $this->get_proces_init=array();
  332. // [proces_init] - A
  333. // [step] - flat 0
  334. // [step] - flat 3 , tree 2 , cut
  335. // [step] - flat 0 , tree 0
  336. // [step] - flat 1 , tree 1
  337. // [step] - flat 1 , tree 1
  338. // [step] - flat 0 , tree 0
  339. // [step] - flat 1 , tree 1
  340. // [step] - flat 0 , tree 0
  341. public function get_proces_init($id_proces) {
  342. $db = DB::getDB();
  343. $sql = "select
  344. p.`ID`
  345. , p.`DESC`
  346. from `CRM_PROCES` as p
  347. left join `_CRM_PROCES_INIT_STATS` as cs on(cs.`ID` = p.`ID`)
  348. where
  349. p.`A_STATUS` in('WAITING','NORMAL')
  350. and p.`TYPE`='PROCES_INIT'
  351. and (cs.`path` like '%/{$id_proces}/%' or cs.`path` like '%/{$id_proces}' or cs.`path` like '{$id_proces}/%')
  352. ";
  353. $res = $db->query($sql);
  354. while ($h = $db->fetch($res)) {
  355. $this->get_proces_init[] = $h->ID;
  356. }
  357. return $this->get_proces_init;
  358. }
  359. public function build_proces_init_tree($id_proces) {
  360. $db = DB::getDB();
  361. $tree->Childs[$id_proces]->PARENT = 0;
  362. $tree->Childs[$id_proces]->SOURCE = 'build_tree_for_proces';
  363. $tree->Parents[0]->CHILD[$id_proces] = $id_proces;
  364. $obj = $db->get_by_id('CRM_PROCES', $id_proces);
  365. $tree->Childs[$id_proces]->TYPE = $obj->TYPE;
  366. $this->build_tree_for_proces($tree, $id_proces, $id_proces);
  367. return $tree;
  368. }
  369. public function build_tree_for_proces(&$tree, $cursor, $init_once = null) {
  370. $db = DB::getDB();
  371. $sqlOr = (!empty($init_once))? " or cp.ID={$init_once} " : "";
  372. $sql = "select
  373. cp.`ID`
  374. , cp.`IF_TRUE_GOTO`
  375. , cp.`IF_TRUE_GOTO_FLAG`
  376. , cp.`TYPE`
  377. from `CRM_PROCES` as cp
  378. where
  379. (cp.PARENT_ID={$cursor} {$sqlOr})
  380. and cp.`A_STATUS` in('WAITING','NORMAL')
  381. ";
  382. $res = $db->query($sql);
  383. while ($h = $db->fetch($res)) {
  384. if (empty($init_once)) $tree->Childs[$h->ID]->PARENT = $cursor;
  385. if (empty($init_once)) $tree->Parents[$cursor]->CHILD[$h->ID] = $h->ID;
  386. $tree->Childs[$h->ID]->TYPE = $h->TYPE;
  387. $tree->Childs[$h->ID]->SOURCE = 'build_tree_for_proces';
  388. if ($h->IF_TRUE_GOTO > 0) {
  389. $tree->Childs[$h->ID]->GOTO_FLAG = $h->IF_TRUE_GOTO_FLAG;
  390. $tree->Childs[$h->ID]->IF_TRUE_GOTO = $h->IF_TRUE_GOTO;
  391. $tree->Childs[$h->IF_TRUE_GOTO]->IS_EXECUTED_BY[$h->ID] = $h->ID;
  392. }
  393. $this->build_tree_for_proces($tree, $h->ID, null);
  394. }
  395. }
  396. public function get_resources_by_proceses_id($id_proces_obj, $id_proces, $filter_zasob) {
  397. $db = DB::getDB();
  398. $filter = "";
  399. if (is_array($filter_zasob)) {
  400. $filter = " and cz.ID in (".implode(',', $filter_zasob).") ";
  401. }
  402. else if (!empty($filter_zasob)) {
  403. $filter = " and cz.ID={$filter_zasob}";
  404. }
  405. $sql = "select
  406. cz.ID
  407. , cz.PARENT_ID
  408. , cz.`DESC`
  409. , cz.`TYPE`
  410. , czp.`DESC` as DESC_czp
  411. , czp.`TYPE` as TYPE_czp
  412. from CRM_WSKAZNIK as cw
  413. left join CRM_LISTA_ZASOBOW as cz on(cz.ID=cw.ID_ZASOB)
  414. left join CRM_LISTA_ZASOBOW as czp on(czp.ID=cz.PARENT_ID)
  415. where cw.ID_PROCES in(".implode(',', array_keys($id_proces_obj)).")
  416. and cw.A_STATUS in ('NORMAL','WAITING')
  417. and czp.`TYPE` in ('TABELA')
  418. {$filter}
  419. ";
  420. $res = $db->query($sql);
  421. while ($h = $db->fetch($res)) {
  422. $found['ID'][$h->ID]['PARENT_ID'] = $h->PARENT_ID;
  423. $found['ID'][$h->ID]['DESC'] = $h->DESC;
  424. $found['PARENT_ID'][$h->PARENT_ID] = $h->DESC_czp;
  425. }
  426. return $found;
  427. }
  428. public function build_tree_flat_info(&$tree, $flat) {
  429. foreach ($tree->Childs as $id => $obj) {
  430. //sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
  431. foreach ($tree->Parents[$id]->CHILD as $child) {
  432. $tree->Childs[$id]->CHILD[$child] = count($tree->Parents[$child]->CHILD);
  433. }
  434. }
  435. }
  436. public function detect_tree_where_to_detail_cut(&$tree, $flag_not_to_cut = null) {
  437. foreach ($tree->Childs as $id => $obj) {
  438. //sprawdzmy czy nasz parent wymaga wyswietlenia osobnego podkroku w widoku szczegolowego procesu
  439. $control = 0;
  440. foreach ($obj->CHILD as $child) {
  441. if ($child > 0) $control++;
  442. }
  443. if (empty($flag_not_to_cut)) {
  444. if ($control > 1) {
  445. //przeciecie jezeli jest wiecej wyjsc niz jedno z zaglebieniami
  446. $tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
  447. }
  448. if (isset($tree->Childs[$id]->GOTO_FLAG)) {
  449. //przeciecie, jezeli jest wyjscie z kroku procesu do innego
  450. $tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
  451. }
  452. if (isset($tree->Childs[$id]->IS_EXECUTED_BY)) {
  453. //trzeba zbadac tez czy nie jest do niego dowiazywany w jakims miejscu proces
  454. $tree->Childs[$id]->TO_DETAIL_CUT_FLAG = true;
  455. }
  456. } else {
  457. $tree->Childs[$id]->NO_CUT_FLAG = true;
  458. }
  459. }
  460. }
  461. public function search_parent_ids_till_cut(&$tree, $init, &$find) {
  462. //szukam lancuchow do optymalizacji do miejsca flagi CUT, kojarzac od razu linki
  463. if (isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
  464. $this->zoom_process_links($tree, $init, $init);
  465. }
  466. if (!isset($tree->Childs[$init]->TO_DETAIL_CUT_FLAG)) {
  467. $find[] = $init;
  468. $this->zoom_process_links($tree, $init, $find[0]);
  469. foreach($tree->Childs[$init]->CHILD as $id => $count) {
  470. $this->search_parent_ids_till_cut($tree, $id, $find);
  471. }
  472. }
  473. }
  474. public function zoom_process_links($tree, $id, $root_id) {
  475. $db = DB::getDB();
  476. if (isset($tree->Childs[$id]->GOTO_FLAG)) {
  477. if (isset($tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO])) {
  478. if (isset($tree->Childs[$tree->Childs[$id]->IF_TRUE_GOTO]->SOURCE)) {
  479. $tree->Viev_Zpc[$root_id]->INTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
  480. } else {
  481. $tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
  482. }
  483. } else {
  484. $tree->Viev_Zpc[$root_id]->EXTERNAL_LINK[$tree->Childs[$id]->IF_TRUE_GOTO] = $tree->Childs[$id]->IF_TRUE_GOTO;
  485. $obj = $db->get_by_id('CRM_PROCES',$tree->Childs[$id]->IF_TRUE_GOTO);
  486. $tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->DESC = "{" . $obj->ID . "}" . substr($obj->DESC, 0, 50);
  487. if ($tree->Childs[$id]->GOTO_FLAG == 'GOTO_AND_RETURN') {
  488. $tree->Viev_Zpc[$tree->Childs[$id]->IF_TRUE_GOTO]->EXTERNAL_LINK[$root_id] = $root_id;
  489. }
  490. }
  491. }
  492. }
  493. public function build_path_zoom_proces_cut(&$tree, $init, $path_zpc = array()) {
  494. $db = DB::getDB();
  495. foreach ($tree->Childs as $id => $obj) {
  496. if (!isset($tree->Viev_Zpc_found[$id])) {
  497. $find = array();
  498. $this->search_parent_ids_till_cut($tree, $id, $find);
  499. foreach ($find as $find_id) {
  500. $tree->Viev_Zpc_found[$find_id] = $find[0];
  501. if ($find_id != $find[0]) {
  502. $tree->Viev_Zpc_Parent[$find_id] = $find[0];// TODO: moze byc to z bledem jak nadrzedny bedzie zbitym ciagiem
  503. }
  504. else {
  505. $tree->Viev_Zpc_Parent[$find_id] = $tree->Childs[$find_id]->PARENT;
  506. }
  507. }
  508. $tree->Viev_Zpc[$id]->PATH = $find;
  509. $obj = $db->get_by_id('CRM_PROCES', $id);
  510. $tree->Viev_Zpc[$id]->DESC = "{" . $id . "}" . substr($obj->DESC, 0, 50) . "...";
  511. }
  512. }
  513. foreach($tree->Viev_Zpc as $id => $obj) {
  514. if (!isset($obj->PARENT)) {
  515. foreach($tree->Viev_Zpc as $id_=>$obj_) {
  516. if (isset($tree->Childs[$id_]->SOURCE)) {
  517. if (in_array($tree->Childs[$id]->PARENT, $obj_->PATH)) {
  518. $tree->Viev_Zpc[$id]->PARENT = $id_;
  519. }
  520. }
  521. }
  522. }
  523. if (!isset($tree->Viev_Zpc[$id]->PARENT)) {
  524. $tree->Viev_Zpc[$id]->PARENT = $tree->Childs[$id]->PARENT;
  525. }
  526. }
  527. }
  528. }