Quellcode durchsuchen

FixCrmProcesInitIdx: test map proces with goto and groups

Piotr Labudda vor 10 Jahren
Ursprung
Commit
9a952b4be6
2 geänderte Dateien mit 242 neuen und 0 gelöschten Zeilen
  1. 205 0
      SE/se-lib/CrmProcesMap.php
  2. 37 0
      SE/se-lib/Route/FixCrmProcesInitIdx.php

+ 205 - 0
SE/se-lib/CrmProcesMap.php

@@ -0,0 +1,205 @@
+<?php
+
+class CrmProcesMap {
+
+	public $initData = array();
+	public $initProcesWithGroups = array();
+	public $initProcesIds = array();
+	public $stepToRecDeepLvl = array();// Recurce Deep Level => ID_PROCES
+	public $stepToGroup = array();// recurse deep => [ID_PROCES => ?]
+	public $usedGroups = array();// ID_GROUPS => group name
+	public $gotoIds = array();
+	public $gotoData = array();
+
+	public function __construct($idProcesInit) {
+		$this->initData = $this->fetchProcesIdxForInit($idProcesInit);
+		$gotoIdsTodo = array();
+		foreach ($this->initData as $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 '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">TODO: $gotoIdsTodo = ';print_r($gotoIdsTodo);echo'</pre>';}
+		$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 '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">TODO:loop('.$i.'): $gotoData = ';print_r($gotoData);echo'</pre>';}
+			foreach ($gotoData as $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;
+			}
+		}
+		?>
+		<table class="table table-bordered">
+			<thead>
+				<tr>
+					<th>Lp.</th>
+					<th>idGroup</th>
+					<?php foreach ($this->stepToRecDeepLvl as $idProces => $deepLvl) : ?>
+						<th><?php echo $idProces; ?></th>
+					<?php endforeach; ?>
+				</tr>
+			</thead>
+			<tbody>
+				<?php $i = 0; foreach ($this->usedGroups as $idGroup => $groupName) : ?>
+					<tr>
+						<td><?php echo $i; ?></td>
+						<td><?php echo $idGroup; ?></td>
+						<?php foreach ($this->stepToRecDeepLvl as $idProces => $deepLvl) : ?>
+							<td><?php
+		if (array_key_exists($idProces, $this->stepToGroup)) {
+			if (in_array($idGroup, $this->stepToGroup[$idProces])) {
+				echo '#';
+			} else {
+				echo '.';
+			}
+		} else {
+			echo 'x';
+		}
+								?></td>
+						<?php endforeach; ?>
+					</tr>
+				<?php $i++; endforeach; ?>
+			</tbody>
+		</table>
+		<?php
+		if(V::get('DBG', '', $_REQUEST)){
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$this->initData = ';print_r($this->initData);echo'</pre>';
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$this->stepToGroup = ';print_r($this->stepToGroup);echo'</pre>';
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$this->stepToRecDeepLvl = ';print_r($this->stepToRecDeepLvl);echo'</pre>';
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$this->gotoIds = ';print_r($this->gotoIds);echo'</pre>';
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$this->initProcesIds = ';print_r($this->initProcesIds);echo'</pre>';
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$this->initProcesWithGroups = ';print_r($this->initProcesWithGroups);echo'</pre>';
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$this = ';print_r($this);echo'</pre>';
+		}
+		$usedGroups = $this->getGroupIdsForProcesInit($idProcesInit);
+		$usedGoto = $this->getGotoAnReturnIdsForProcesInit($idProcesInit);
+		if(V::get('DBG', '', $_REQUEST)){
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$usedGroups = ';print_r($usedGroups);echo'</pre>';
+			echo '<pre style="width:600px;border:1px solid red;max-height:300px;overflow:auto">$usedGoto = ';print_r($usedGoto);echo'</pre>';
+		}
+	}
+
+	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;
+	}
+
+}

+ 37 - 0
SE/se-lib/Route/FixCrmProcesInitIdx.php

@@ -38,6 +38,43 @@ jQuery(document).ready(function () {
 		SE_Layout::dol();
 	}
 
+	public function mapAction() {
+		SE_Layout::gora();
+		// echo '<a href="index.php?_route=FixCrmProcesInitIdx&_task=run">aktualizuj uprawnienia</a>';
+		$idProcesInit = V::get('id_proces_init', '', $_REQUEST, 'int');
+		?>
+<div class="jumbotron">
+  <div class="container">
+		<form class="form-inline" method="POST">
+			<input type="hidden" name="_route" value="FixCrmProcesInitIdx" />
+			<input type="hidden" name="_task" value="map" />
+			<input type="text" class="form-control" name="id_proces_init" value="<?php echo $idProcesInit; ?>" />
+			<button type="submit" id="fldExecuteBtn" class="btn btn-primary" autocomplete="off">
+				Pokaż mapę
+			</button>
+		</form>
+	</div>
+</div>
+<script type="text/javascript">
+jQuery(document).ready(function () {
+  jQuery('#fldExecuteBtn').on('click', function () {
+    jQuery(this).text(jQuery(this).text() + '...').attr('disabled', 'disabled');
+		jQuery(this).parent().submit();
+  })
+});
+</script>
+		<?php
+		if ($idProcesInit) {
+			$this->printProcesInitMap($idProcesInit);
+		}
+		SE_Layout::dol();
+	}
+
+	public function printProcesInitMap($idProcesInit) {
+		Lib::loadClass('CrmProcesMap');
+		$map = new CrmProcesMap($idProcesInit);
+	}
+
 	public function runAction() {
 		SE_Layout::gora();
 		SE_Layout::menu();