Преглед изворни кода

ProcesHelper and FixCrmProcesInitIdx: create and use view for tables

Piotr Labudda пре 10 година
родитељ
комит
532ace035c
2 измењених фајлова са 59 додато и 48 уклоњено
  1. 17 11
      SE/se-lib/ProcesHelper.php
  2. 42 37
      SE/se-lib/Route/FixCrmProcesInitIdx.php

+ 17 - 11
SE/se-lib/ProcesHelper.php

@@ -468,21 +468,27 @@ class ProcesHelper {
 		return $ret;
 	}
 
-	public static function getZasobTableInfo($zasobID) {
-		$zasobObj = null;
+	public static function getZasobTableInfo($idTable) {
+		$tableInfo = null;
 		$db = DB::getDB();
-		$sql = "select z.`ID`, z.`DESC`, z.`DESC_PL`, z.`OPIS`
-				, zp.`ID` as P__ID, zp.`DESC` as P__DESC, zp.`TYPE` as P__TYPE
-			from `CRM_LISTA_ZASOBOW` as z
-				left join `CRM_LISTA_ZASOBOW` as zp on(zp.`ID`=z.`PARENT_ID`)
-			where z.`ID`='{$zasobID}'
-				and z.`TYPE`='TABELA'
-		";
+		$sql = <<<SQL
+			select tv.`ID_TABLE` as `ID`
+				, tv.`TABLE_NAME` as `DESC`
+				, tv.`TABLE_LABEL` as `DESC_PL`
+				, tv.`TABLE_DESCRIPTION` as `OPIS`
+				, zpp.`ID` as P__ID
+				, zpp.`DESC` as P__DESC
+				, zpp.`TYPE` as P__TYPE
+			from `CRM_PROCES_idx_TABLES_INFO_VIEW` as tv
+				join `CRM_LISTA_ZASOBOW` as zpp on(zpp.`ID`=tv.`ID_DATABASE`)
+			where tv.`ID_TABLE`='{$idTable}'
+			limit 1
+SQL;
 		$res = $db->query($sql);
 		if ($res) {
-			$zasobObj = $db->fetch($res);
+			$tableInfo = $db->fetch($res);
 		}
-		return $zasobObj;
+		return $tableInfo;
 	}
 
 	public static function getZasobTableInfoByUri($uri) {

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

@@ -476,27 +476,42 @@ SQL;
 				WHERE  `ADM_ACCOUNT` LIKE  '{$userLogin}'
 				GROUP BY ID_PROCES_INIT
 		*/
-		$sqlList['RemoveViewTableToProces'] = "DROP VIEW IF EXISTS `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW`";
-		$sqlList['InstallViewTableToProces'] = <<<SQL
-			CREATE VIEW `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` AS
+		$sqlList['RemoveViewTablesInfo'] = "DROP VIEW IF EXISTS `CRM_PROCES_idx_TABLES_INFO_VIEW`";
+		$sqlList['InstallViewTablesInfo'] = <<<SQL
+			CREATE VIEW `CRM_PROCES_idx_TABLES_INFO_VIEW` AS
 			select z.`ID` as `ID_CELL`
 					, z.`DESC` as `CELL_NAME`
+					, z.`DESC_PL` as `CELL_LABEL`
+					, z.`OPIS` as `CELL_DESCRIPTION`
+					, z.`SORT_PRIO` as `CELL_SORT_PRIO`
 					, zp.`ID` as `ID_TABLE`
 					, zp.`DESC` as `TABLE_NAME`
 					, zp.`DESC_PL` as `TABLE_LABEL`
 					, zp.`OPIS` as `TABLE_DESCRIPTION`
 					, zpp.`ID` as `ID_DATABASE`
-					, wsk.`ID_PROCES` as `ID_PROCES`
 				from `CRM_LISTA_ZASOBOW` z
 					join `CRM_LISTA_ZASOBOW` zp on(zp.`ID`=z.`PARENT_ID` and zp.`TYPE`='TABELA' and zp.`A_STATUS` in('WAITING','NORMAL'))
 					join `CRM_LISTA_ZASOBOW` zpp on(zpp.`ID`=zp.`PARENT_ID`
 						-- TODO: and zpp.`TYPE`='BAZA_DANYCH...'
 						and zpp.`A_STATUS` in('WAITING','NORMAL')
 					)
-					join `CRM_WSKAZNIK` wsk on(wsk.`ID_ZASOB`=z.`ID` and wsk.`A_STATUS` in('WAITING','NORMAL'))
-					join `CRM_PROCES` p on(p.`ID`=wsk.`ID_PROCES` and p.`A_STATUS` in('WAITING','NORMAL'))
 				where z.`TYPE`='KOMORKA'
 					and z.`A_STATUS` in('WAITING','NORMAL')
+SQL;
+		$sqlList['RemoveViewTableToProces'] = "DROP VIEW IF EXISTS `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW`";
+		$sqlList['InstallViewTableToProces'] = <<<SQL
+			CREATE VIEW `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` AS
+			select tv.`ID_CELL` as `ID_CELL`
+					, tv.`CELL_NAME` as `CELL_NAME`
+					, tv.`ID_TABLE` as `ID_TABLE`
+					, tv.`TABLE_NAME` as `TABLE_NAME`
+					, tv.`TABLE_LABEL` as `TABLE_LABEL`
+					, tv.`TABLE_DESCRIPTION` as `TABLE_DESCRIPTION`
+					, tv.`ID_DATABASE` as `ID_DATABASE`
+					, wsk.`ID_PROCES` as `ID_PROCES`
+				from `CRM_PROCES_idx_TABLES_INFO_VIEW` tv
+					join `CRM_WSKAZNIK` wsk on(wsk.`ID_ZASOB`=tv.`ID_CELL` and wsk.`A_STATUS` in('WAITING','NORMAL'))
+					join `CRM_PROCES` p on(p.`ID`=wsk.`ID_PROCES` and p.`A_STATUS` in('WAITING','NORMAL'))
 SQL;
 		$sqlList['RemoveViewUrlToProces'] = "DROP VIEW IF EXISTS `CRM_PROCES_idx_URL_TO_PROCES_VIEW`";
 		$sqlList['InstallViewUrlToProces'] = <<<SQL
@@ -515,13 +530,13 @@ SQL;
 		$sqlList['RemoveViewTableCellToProcesWithPerms'] = "DROP VIEW IF EXISTS `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW`";
 		$sqlList['InstallViewTableCellToProcesWithPerms'] = <<<SQL
 			CREATE VIEW `CRM_PROCES_idx_TABLE_TO_PROCES_PERMS_VIEW` AS
-			select z.`ID` as `ID_CELL`
-					, z.`DESC` as `CELL_NAME`
-					, zp.`ID` as `ID_TABLE`
-					, zp.`DESC` as `TABLE_NAME`
-					, zp.`DESC_PL` as `TABLE_LABEL`
-					, zp.`OPIS` as `TABLE_DESCRIPTION`
-					, zpp.`ID` as `ID_DATABASE`
+			select tv.`ID_CELL` as `ID_CELL`
+					, tv.`CELL_NAME` as `CELL_NAME`
+					, tv.`ID_TABLE` as `ID_TABLE`
+					, tv.`TABLE_NAME` as `TABLE_NAME`
+					, tv.`TABLE_LABEL` as `TABLE_LABEL`
+					, tv.`TABLE_DESCRIPTION` as `TABLE_DESCRIPTION`
+					, tv.`ID_DATABASE` as `ID_DATABASE`
 					, wsk.`ID_PROCES` as `ID_PROCES`
 					, replace(przyp.`FORM_TREAT`, ',', '') as FORM_TREAT
 					, IF(przyp.`FORM_TREAT` & 2,   1, 0) as PERM_R
@@ -532,26 +547,19 @@ SQL;
 					, IF(przyp.`FORM_TREAT` & 64,  1, 0) as PERM_O
 					, IF(przyp.`FORM_TREAT` & 128, 1, 0) as PERM_V
 					, IF(przyp.`FORM_TREAT` & 256, 1, 0) as PERM_E
-				from `CRM_LISTA_ZASOBOW` z
-					join `CRM_LISTA_ZASOBOW` zp on(zp.`ID`=z.`PARENT_ID` and zp.`TYPE`='TABELA' and zp.`A_STATUS` in('WAITING','NORMAL'))
-					join `CRM_LISTA_ZASOBOW` zpp on(zpp.`ID`=zp.`PARENT_ID`
-						-- TODO: and zpp.`TYPE`='BAZA_DANYCH...'
-						and zpp.`A_STATUS` in('WAITING','NORMAL')
-					)
-					join `CRM_WSKAZNIK` wsk on(wsk.`ID_ZASOB`=z.`ID` and wsk.`A_STATUS` in('WAITING','NORMAL'))
+				from `CRM_PROCES_idx_TABLES_INFO_VIEW` tv
+					join `CRM_WSKAZNIK` wsk on(wsk.`ID_ZASOB`=tv.`ID_CELL` and wsk.`A_STATUS` in('WAITING','NORMAL'))
 					join `CRM_PROCES` p on(p.`ID`=wsk.`ID_PROCES` and p.`A_STATUS` in('WAITING','NORMAL'))
 					join `CRM_PRZYPADEK` as przyp on (przyp.`ID`=wsk.`ID_PRZYPADEK`)
-				where z.`TYPE`='KOMORKA'
-					and z.`A_STATUS` in('WAITING','NORMAL')
 SQL;
 		$sqlExample_TableCellToProcesForInitTable = <<<SQL
-			select z.`ID` as `ID_CELL`
-					, z.`DESC` as `CELL_NAME`
-					, z.`DESC_PL` as `CELL_LABEL`
-					, z.`OPIS` as `CELL_DESC`
-					, z.`SORT_PRIO` as `SORT_PRIO`
-					, zp.`ID` as `ID_TABLE`
-					, zp.`DESC` as `TABLE_NAME`
+			select tv.`ID_CELL` as `ID_CELL`
+					, tv.`CELL_NAME` as `CELL_NAME`
+					, tv.`CELL_LABEL` as `CELL_LABEL`
+					, tv.`CELL_DESC` as `CELL_DESC`
+					, tv.`CELL_SORT_PRIO` as `SORT_PRIO`
+					, tv.`ID_TABLE` as `ID_TABLE`
+					, tv.`TABLE_NAME` as `TABLE_NAME`
 					, wsk.`ID_PROCES` as `ID_PROCES`
 					, sum(IF(przyp.`FORM_TREAT` & 2,   1, 0)) as PERM_R
 					, sum(IF(przyp.`FORM_TREAT` & 4,   1, 0)) as PERM_W
@@ -561,17 +569,14 @@ SQL;
 					, sum(IF(przyp.`FORM_TREAT` & 64,  1, 0)) as PERM_O
 					, sum(IF(przyp.`FORM_TREAT` & 128, 1, 0)) as PERM_V
 					, sum(IF(przyp.`FORM_TREAT` & 256, 1, 0)) as PERM_E
-				from `CRM_LISTA_ZASOBOW` z
-					join `CRM_LISTA_ZASOBOW` zp on(zp.`ID`=z.`PARENT_ID` and zp.`TYPE`='TABELA' and zp.`A_STATUS` in('WAITING','NORMAL'))
-					join `CRM_WSKAZNIK` wsk on(wsk.`ID_ZASOB`=z.`ID` and wsk.`A_STATUS` in('WAITING','NORMAL'))
+				from `CRM_PROCES_idx_TABLES_INFO_VIEW` tv
+					join `CRM_WSKAZNIK` wsk on(wsk.`ID_ZASOB`=tv.`ID_CELL` and wsk.`A_STATUS` in('WAITING','NORMAL'))
 					join `CRM_PROCES` p on(p.`ID`=wsk.`ID_PROCES` and p.`A_STATUS` in('WAITING','NORMAL'))
 					join `CRM_PRZYPADEK` as przyp on (przyp.`ID`=wsk.`ID_PRZYPADEK`)
-				where z.`TYPE`='KOMORKA'
-					and z.`A_STATUS` in('WAITING','NORMAL')
-					and zp.`ID`='{$idTable}'
+				where tv.`ID_TABLE`='{$idTable}'
 					and wsk.`ID_PROCES` in({$sqlIdProcesList})
-				group by z.`ID`, wsk.`ID_PROCES`
-				order by z.`SORT_PRIO`
+				group by tv.`ID_CELL`, wsk.`ID_PROCES`
+				order by tv.`CELL_SORT_PRIO`
 SQL;
 		$sqlExample_UrlToUserProces = <<<SQL
 			select zpv.*