|
@@ -0,0 +1,170 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class ACL {
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Ids List of Proces Init for given tabel (skip filters)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getTableProcesInitIds($idTable) {// TODO: use in TableAjax
|
|
|
|
|
+ $procesInitList = self::getTableProcesInitList($idTable);
|
|
|
|
|
+ return array_keys($procesInitList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * List of Proces Init for given table (skip filters)
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getTableProcesInitList($idTable) {// TODO: use in TableAjax
|
|
|
|
|
+ $tableProcesInitList = array();
|
|
|
|
|
+ $sqlIdProcesListSql = <<<SQL
|
|
|
|
|
+ select tpv.`ID_PROCES`
|
|
|
|
|
+ from `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` tpv
|
|
|
|
|
+ where tpv.`ID_TABLE`='{$idTable}'
|
|
|
|
|
+SQL;
|
|
|
|
|
+ $fetchTableProcesInitListSql = <<<SQL
|
|
|
|
|
+ -- time ~0.07 -- no goto and return
|
|
|
|
|
+ select p.`ID`, p.`DESC`
|
|
|
|
|
+ from `CRM_PROCES` p
|
|
|
|
|
+ where p.`ID` in(
|
|
|
|
|
+ select i.`idx_PROCES_INIT_ID`
|
|
|
|
|
+ from `CRM_PROCES_idx` i
|
|
|
|
|
+ where i.`ID_PROCES` in({$sqlIdProcesListSql})
|
|
|
|
|
+ )
|
|
|
|
|
+ and p.`TYPE`='PROCES_INIT'
|
|
|
|
|
+ order by p.`SORT_PRIO`
|
|
|
|
|
+SQL;
|
|
|
|
|
+ /*
|
|
|
|
|
+ SELECT p.`ID` , p.`DESC`
|
|
|
|
|
+ FROM `CRM_PROCES` p
|
|
|
|
|
+ WHERE p.`ID`
|
|
|
|
|
+ IN (
|
|
|
|
|
+ SELECT i.`idx_PROCES_INIT_ID`
|
|
|
|
|
+ FROM `CRM_PROCES_idx` i
|
|
|
|
|
+ WHERE i.`ID_PROCES`
|
|
|
|
|
+ IN (
|
|
|
|
|
+ SELECT tpv.`ID_PROCES`
|
|
|
|
|
+ FROM `CRM_PROCES_idx_TABLE_TO_PROCES_VIEW` tpv
|
|
|
|
|
+ WHERE tpv.`ID_TABLE` = '13051'
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ AND p.`TYPE` = 'PROCES_INIT'
|
|
|
|
|
+ order by p.`SORT_PRIO`
|
|
|
|
|
+ */
|
|
|
|
|
+ $fetchTableProcesInitListSql = <<<SQL
|
|
|
|
|
+ -- time ~0.15s
|
|
|
|
|
+ select p.`ID`, p.`DESC`
|
|
|
|
|
+ from `CRM_PROCES` p
|
|
|
|
|
+ where p.`ID` in(
|
|
|
|
|
+ select i.`idx_PROCES_INIT_ID`
|
|
|
|
|
+ from `CRM_PROCES_idx` i
|
|
|
|
|
+ where i.`ID_PROCES` in({$sqlIdProcesListSql})
|
|
|
|
|
+ union
|
|
|
|
|
+ select ig.`idx_PROCES_INIT_ID`
|
|
|
|
|
+ from `CRM_PROCES_idx` i
|
|
|
|
|
+ join `CRM_PROCES_idx` ig on(ig.`ID_PROCES`=i.`idx_PROCES_WITH_GROUPS_ID`)
|
|
|
|
|
+ where i.`ID_PROCES` in({$sqlIdProcesListSql})
|
|
|
|
|
+ )
|
|
|
|
|
+ and p.`TYPE`='PROCES_INIT'
|
|
|
|
|
+ order by p.`SORT_PRIO`
|
|
|
|
|
+SQL;
|
|
|
|
|
+ $fetchTableProcesInitListSql = <<<SQL
|
|
|
|
|
+ -- time ~0.14
|
|
|
|
|
+ select p.`ID`, p.`DESC`
|
|
|
|
|
+ from `CRM_PROCES` p
|
|
|
|
|
+ where p.`ID` in(
|
|
|
|
|
+ select i.`idx_PROCES_INIT_ID`
|
|
|
|
|
+ from `CRM_PROCES_idx` i
|
|
|
|
|
+ where i.`ID_PROCES` in({$sqlIdProcesListSql})
|
|
|
|
|
+ or i.`ID_PROCES` in(
|
|
|
|
|
+ select ig.`idx_PROCES_WITH_GROUPS_ID`
|
|
|
|
|
+ from `CRM_PROCES_idx` ig
|
|
|
|
|
+ where ig.`ID_PROCES` in({$sqlIdProcesListSql})
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ and p.`TYPE`='PROCES_INIT'
|
|
|
|
|
+ order by p.`SORT_PRIO`
|
|
|
|
|
+SQL;
|
|
|
|
|
+ //echo'<pre>$fetchTableProcesInitListSql('.$idTable.') ';print_r($fetchTableProcesInitListSql);echo'</pre>';
|
|
|
|
|
+ $tableProcesInitList = array();
|
|
|
|
|
+ $db = DB::getDB();
|
|
|
|
|
+ $res = $db->query($fetchTableProcesInitListSql);
|
|
|
|
|
+ while ($r = $db->fetch($res)) {
|
|
|
|
|
+ $tableProcesInitList[$r->ID] = $r->DESC;
|
|
|
|
|
+ }
|
|
|
|
|
+ return $tableProcesInitList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function getProcesInitMapTreeOnlyIds($ids) {
|
|
|
|
|
+ $mapTree = array();
|
|
|
|
|
+ $map = self::getProcesInitMapOnlyIds($ids);
|
|
|
|
|
+ foreach ($map as $r) {
|
|
|
|
|
+ if ('PROCES_INIT' == $r->TYPE) {
|
|
|
|
|
+ $mapTree[$r->ID_PROCES] = array();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ foreach ($map as $r) {
|
|
|
|
|
+ if ('GOTO_AND_RETURN' == $r->TYPE) {
|
|
|
|
|
+ $mapTree[$r->idx_MAIN_PROCES_INIT_ID][$r->ID_PROCES] = array();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ foreach ($map as $r) {
|
|
|
|
|
+ if ('GOTO_AND_RETURN_LVL2' == $r->TYPE) {
|
|
|
|
|
+ $mapTree[$r->idx_MAIN_PROCES_INIT_ID][$r->idx_GOTO_LVL2_INIT_ID][$r->ID_PROCES] = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $mapTree;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static function getProcesInitMapOnlyIds($ids) {
|
|
|
|
|
+ $map = array();
|
|
|
|
|
+ $sqlIds = V::filter($ids, array('V', 'filterPositiveInteger'));
|
|
|
|
|
+ $sqlIds = implode(',', $sqlIds);
|
|
|
|
|
+ if (empty($sqlIds)) return $map;
|
|
|
|
|
+ $sql = <<<SQL
|
|
|
|
|
+ select i.`ID_PROCES`
|
|
|
|
|
+ , i.`PARENT_ID`
|
|
|
|
|
+ , i.`TYPE`
|
|
|
|
|
+ , i.`idx_PROCES_INIT_ID`
|
|
|
|
|
+ , i.`idx_MAIN_PROCES_INIT_ID`
|
|
|
|
|
+ , i.`idx_PROCES_WITH_GROUPS_ID`
|
|
|
|
|
+ , IF(i.`TYPE`='GOTO_AND_RETURN_LVL2'
|
|
|
|
|
+ , (select ig.`idx_PROCES_INIT_ID`
|
|
|
|
|
+ from `CRM_PROCES_idx` ig
|
|
|
|
|
+ where ig.`ID_PROCES`=i.`PARENT_ID`
|
|
|
|
|
+ limit 1)
|
|
|
|
|
+ , 0
|
|
|
|
|
+ ) as idx_GOTO_LVL2_INIT_ID
|
|
|
|
|
+ from `CRM_PROCES_idx` i
|
|
|
|
|
+ where i.`ID_PROCES` in({$sqlIds})
|
|
|
|
|
+ and i.`idx_MAIN_PROCES_INIT_ID` in({$sqlIds})
|
|
|
|
|
+SQL;
|
|
|
|
|
+ DBG::_('DBG_MAP', '1', "MAP SQL", $sql, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
+ $db = DB::getDB();
|
|
|
|
|
+ $res = $db->query($sql);
|
|
|
|
|
+ while ($r = $db->fetch($res)) {
|
|
|
|
|
+ $map[] = $r;
|
|
|
|
|
+ }
|
|
|
|
|
+ //DBG::table("MAP", $map, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
|
|
+ return $map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function canGroupViewProces($idGroup, $idProcesInit) {
|
|
|
|
|
+ $isAllowed = false;
|
|
|
|
|
+ $idProcesInit = (int)$idProcesInit;
|
|
|
|
|
+ if (!$idProcesInit) return false;
|
|
|
|
|
+ $checkProcesAccessSql = <<<SQL
|
|
|
|
|
+ select count(*) as cnt
|
|
|
|
|
+ from `CRM_PROCES_idx_GROUP_to_INIT_VIEW` giv
|
|
|
|
|
+ where giv.`ID_GROUP` = '{$idGroup}'
|
|
|
|
|
+ and giv.`ID_PROCES_INIT` = '{$idProcesInit}'
|
|
|
|
|
+SQL;
|
|
|
|
|
+ $db = DB::getDB();
|
|
|
|
|
+ $res = $db->query($checkProcesAccessSql);
|
|
|
|
|
+ if ($r = $db->fetch($res)) {
|
|
|
|
|
+ if ($r->cnt > 0) {
|
|
|
|
|
+ $isAllowed = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return $isAllowed;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|