superedit-GRAPH_VIEW_PROCES.php 20 KB

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