|
|
@@ -27,12 +27,9 @@ class ProcesHelper {
|
|
|
}
|
|
|
|
|
|
public static function getWskaznikiByIds($ids, $params = array()) {
|
|
|
- $wskazniki = array();
|
|
|
- if (empty($ids)) {
|
|
|
- return $wskazniki;
|
|
|
- }
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select
|
|
|
+ if (empty($ids)) return [];
|
|
|
+ $sql = "
|
|
|
+ select
|
|
|
clz.*
|
|
|
, w.`ID_PROCES`
|
|
|
, w.`ID` as CW_ID, w.`TYP` as CW_TYP, w.`OPIS_ZASOB` as OPIS_ZASOB, w.`SORT_PRIO` as CW_SORT_PRIO, w.`ID_PRZYPADEK` as CW_ID_PRZYPADEK
|
|
|
@@ -46,9 +43,9 @@ class ProcesHelper {
|
|
|
and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
order by w.`SORT_PRIO` asc, w.`ID` asc
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $wskazniki[$r->ID_PROCES][$r->CW_ID] = $r;
|
|
|
+ $wskazniki = array();
|
|
|
+ foreach (DB::getPDO()->fetchAll($sql) as $row) {
|
|
|
+ $wskazniki[ $row['ID_PROCES'] ][ $row['CW_ID'] ] = (object)$row;
|
|
|
}
|
|
|
|
|
|
if (1 == V::get('group_stanowiska', '', $params)) {
|
|
|
@@ -72,110 +69,6 @@ class ProcesHelper {
|
|
|
return $wskazniki;
|
|
|
}
|
|
|
|
|
|
- public static function get_list_for_user_count($user_groups, $params = array()) {
|
|
|
- $ret = array();
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = self::_get_list_for_user_sql($user_groups, $params, true);
|
|
|
- $res = $db->query($sql);
|
|
|
- if ($r = $db->fetch($res)) {
|
|
|
- $ret = $r->cnt;
|
|
|
- }
|
|
|
- return $ret;
|
|
|
- }
|
|
|
-
|
|
|
- public static function get_list_for_user($user_groups, $params = array()) {
|
|
|
- $ret = array();
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = self::_get_list_for_user_sql($user_groups, $params);
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $ret[] = $r;
|
|
|
- }
|
|
|
- return $ret;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * TODO: find user proces
|
|
|
- */
|
|
|
- public static function _get_list_for_user_sql($user_groups, $params = array(), $count = false) {
|
|
|
- $sql_select = array();
|
|
|
- $sql_limit = "";
|
|
|
- $sql_where = "";
|
|
|
-
|
|
|
- if ($count) {
|
|
|
- $sql_select[] = "count(1) as cnt";
|
|
|
- } else {
|
|
|
- $sql_select[] = "t.*";
|
|
|
- $sql_limit = V::get('limit', '10', $params);
|
|
|
- $sql_offset = V::get('offset', '0', $params);
|
|
|
- $sql_limit = "limit {$sql_limit} offset {$sql_offset}";
|
|
|
- }
|
|
|
-
|
|
|
- $sql_select = implode(", ", $sql_select);
|
|
|
- $sql = "select
|
|
|
- {$sql_select}
|
|
|
- from `CRM_PROCES_LOG` as t
|
|
|
- -- left join `` as p on(p.``=t.``)
|
|
|
- where
|
|
|
- {$sql_where}
|
|
|
- {$sql_limit}
|
|
|
- ";
|
|
|
- return $sql;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Get allowed Stanowiska ID for given proces.
|
|
|
- * @param $proces_id - proces ID
|
|
|
- * @returns array of Stanowiska ID
|
|
|
- * Search recursively up by p.PARENT_ID, stop when find p.PROCES_INIT or find z.STANOWISKO
|
|
|
- */
|
|
|
- public static function get_allowed_stanowiska_by_proces_id($proces_id) {
|
|
|
- $ret = array();
|
|
|
- $proces_id = intval($proces_id);
|
|
|
- if ($proces_id <= 0) return $ret;
|
|
|
- // TODO: DB::get_by_id('CRM_PROCES', $proces_id);
|
|
|
- // TODO: check TYPE=PROCES_INIT -> get STANOWISKO and stop
|
|
|
- // TODO: find wskazniki STANOWISKO
|
|
|
- // TODO: if !empty return else recursive - TODO: add recursive limit!
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select
|
|
|
- p.`TYPE` as p__TYPE
|
|
|
- , z.`ID` as z__ID
|
|
|
- , z.`TYPE` as z__TYPE
|
|
|
- from `CRM_PROCES` as p
|
|
|
- left join `CRM_WSKAZNIK` as w on(w.`ID_PROCES`=p.`ID`)
|
|
|
- left join `CRM_LISTA_ZASOBOW` as z on (z.`ID`=w.`ID_ZASOB`)
|
|
|
- where
|
|
|
- p.`ID`='{$proces_id}'
|
|
|
- and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
- and z.`TYPE`='STANOWISKO'
|
|
|
- ";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $ret[] = $r->z__ID;
|
|
|
- }
|
|
|
- //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">ret: ';print_r($ret);echo'</pre>';
|
|
|
- return $ret;
|
|
|
- }
|
|
|
-
|
|
|
- public static function getProcesByUser($user_name, $groups) {
|
|
|
- $ret = array();
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select plog.*
|
|
|
- from `CRM_PROCES_LOG` as plog
|
|
|
- where
|
|
|
- ( plog.`A_RECORD_CREATE_AUTHOR`='{$user_name}'
|
|
|
- or plog.`A_RECORD_UPDATE_AUTHOR`='{$user_name}'
|
|
|
- )
|
|
|
- order by plog.ID DESC
|
|
|
- ";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $ret[$r->ID] = $r;
|
|
|
- }
|
|
|
- return $ret;
|
|
|
- }
|
|
|
-
|
|
|
public static function split_wskazniki_by_table(&$wsk) {
|
|
|
$wsk_split = array();
|
|
|
echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">wsk: ';print_r($wsk);echo'</pre>';
|
|
|
@@ -198,22 +91,16 @@ class ProcesHelper {
|
|
|
* @param $stanowiska_id - array of integer
|
|
|
*/
|
|
|
public static function get_procesy_by_stanowiska($stanowiska_id = array()) {
|
|
|
- $db = DB::getDB();
|
|
|
- $ret = array();
|
|
|
- if (empty($stanowiska_id)) {
|
|
|
- return $ret;
|
|
|
- }
|
|
|
+ if (empty($stanowiska_id)) return [];
|
|
|
$sql_stanowiska_id = array();
|
|
|
foreach ($stanowiska_id as $v_id) {
|
|
|
$v_id = intval($v_id);
|
|
|
- if ($v_id > 0) {
|
|
|
- $sql_stanowiska_id[] = "'{$v_id}'";
|
|
|
- }
|
|
|
- }
|
|
|
- if (empty($sql_stanowiska_id)) {
|
|
|
- return $ret;
|
|
|
+ if ($v_id > 0) $sql_stanowiska_id[] = "'{$v_id}'";
|
|
|
}
|
|
|
- $sql = "select
|
|
|
+ if (empty($sql_stanowiska_id)) return [];
|
|
|
+ $ret = array();
|
|
|
+ $sql = "
|
|
|
+ select
|
|
|
p.`ID`
|
|
|
, p.`PARENT_ID`
|
|
|
, p.`TYPE`
|
|
|
@@ -235,11 +122,9 @@ class ProcesHelper {
|
|
|
and z.`ID` in (" . implode(",", $sql_stanowiska_id) . ")
|
|
|
order by p.`TEST_SORT_PRIO` DESC, p.`ID` ASC
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $ret[] = $r;
|
|
|
- }
|
|
|
- return $ret;
|
|
|
+ return array_map(function ($row) {
|
|
|
+ return (object)$row;
|
|
|
+ }, DB::getPDO()->fetchAll($sql));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -247,9 +132,8 @@ class ProcesHelper {
|
|
|
* @return array ID => TEST_SORT_PRIO
|
|
|
*/
|
|
|
public static function get_procesy_init_list_order() {
|
|
|
- $ret = array();
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select
|
|
|
+ $sql = "
|
|
|
+ select
|
|
|
p.`ID`
|
|
|
, p.`TEST_SORT_PRIO`
|
|
|
from `CRM_PROCES` as p
|
|
|
@@ -258,11 +142,9 @@ class ProcesHelper {
|
|
|
and p.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
order by p.`TEST_SORT_PRIO` DESC, p.`ID` ASC
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $ret[$r->ID]= $r->TEST_SORT_PRIO;
|
|
|
- }
|
|
|
- return $ret;
|
|
|
+ return array_map(function ($row) {
|
|
|
+ return $row['TEST_SORT_PRIO'];
|
|
|
+ }, DB::getPDO()->fetchAllByKey($sql, 'ID'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -270,46 +152,42 @@ class ProcesHelper {
|
|
|
*/
|
|
|
public static function get_procesy_init_list() {
|
|
|
$ret = array();
|
|
|
- $db = DB::getDB();
|
|
|
- $sql = "select
|
|
|
+ $sql = "
|
|
|
+ select
|
|
|
p.`ID`
|
|
|
, p.`PARENT_ID`
|
|
|
, p.`TYPE`
|
|
|
, p.`DESC`
|
|
|
, p.`TEST_SORT_PRIO`
|
|
|
--- , w.`ID` as w__ID
|
|
|
--- , w.`OPIS_ZASOB` as w__OPIS_ZASOB
|
|
|
--- , z.`ID` as z__ID
|
|
|
+ -- , w.`ID` as w__ID
|
|
|
+ -- , w.`OPIS_ZASOB` as w__OPIS_ZASOB
|
|
|
+ -- , z.`ID` as z__ID
|
|
|
, cps.`path`
|
|
|
, p.`TEST_SORT_PRIO`
|
|
|
, p.`SORT_PRIO`
|
|
|
from `CRM_PROCES` as p
|
|
|
--- left join `CRM_WSKAZNIK` as w on(w.`ID_PROCES`=p.`ID`)
|
|
|
--- left join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=w.`ID_ZASOB`)
|
|
|
+ -- left join `CRM_WSKAZNIK` as w on(w.`ID_PROCES`=p.`ID`)
|
|
|
+ -- left join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=w.`ID_ZASOB`)
|
|
|
left join `_CRM_PROCES_STATS_proc_wiev` as cps on(p.`ID`=cps.`ID`)
|
|
|
where
|
|
|
p.`TYPE`='PROCES_INIT'
|
|
|
and p.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
--- and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
--- and w.`ID_PRZYPADEK`=1
|
|
|
--- and z.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
--- and z.`TYPE`='STANOWISKO'
|
|
|
--- and z.`ID` is not null
|
|
|
+ -- and w.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
+ -- and w.`ID_PRZYPADEK`=1
|
|
|
+ -- and z.`A_STATUS` in('WAITING','NORMAL','MONITOR')
|
|
|
+ -- and z.`TYPE`='STANOWISKO'
|
|
|
+ -- and z.`ID` is not null
|
|
|
order by p.`TEST_SORT_PRIO` DESC, p.`ID` ASC
|
|
|
";
|
|
|
- $res = $db->query($sql);
|
|
|
- while ($r = $db->fetch($res)) {
|
|
|
- $ret[] = $r;
|
|
|
- }
|
|
|
- return $ret;
|
|
|
+ return array_map(function ($row) {
|
|
|
+ return (object)$row;
|
|
|
+ }, DB::getPDO()->fetchAll($sql));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Przeniesienie procesu w kolejności w testach.
|
|
|
*/
|
|
|
public static function proces_init_move($proces_id, $sort_prio_dir) {
|
|
|
- $db = DB::getDB();
|
|
|
-
|
|
|
$proces_list = self::get_procesy_init_list();
|
|
|
$proces_list = array_reverse($proces_list);
|
|
|
|
|
|
@@ -339,6 +217,7 @@ class ProcesHelper {
|
|
|
$wsk_order[$wsk[$proces_id] + 1] = $tmp;
|
|
|
}
|
|
|
if (empty($wsk_order)) return;
|
|
|
+ $db = DB::getDB();
|
|
|
foreach ($wsk_order as $k_sort_prio => $v_proces_id) {
|
|
|
$sql = "update `CRM_PROCES` set `TEST_SORT_PRIO`='{$k_sort_prio}' where `ID`='{$v_proces_id}'; ";
|
|
|
$db->query($sql);
|
|
|
@@ -347,19 +226,12 @@ class ProcesHelper {
|
|
|
}
|
|
|
|
|
|
public static function proces_flag($proces_id, $goto_id, $flag) {
|
|
|
- $ret = '';
|
|
|
switch ($flag) {
|
|
|
- case 'GOTO':
|
|
|
- $ret = '<span style="color:#FF0000">' . "→" . '</span>' . $goto_id;
|
|
|
- break;
|
|
|
- case 'GOTO_AND_RETURN':
|
|
|
- $ret = '<span style="color:#FF0000">' . "→" . '</span>' . $goto_id . '<span style="color:#FF0000">' . "↵" . '</span>';
|
|
|
- break;
|
|
|
- case 'FORK':
|
|
|
- $ret = '<span style="color:#FF0000">' . "⊕→" . '</span>' . $goto_id;
|
|
|
- break;
|
|
|
+ case 'GOTO': return '<span style="color:#FF0000">' . "→" . '</span>' . $goto_id;
|
|
|
+ case 'GOTO_AND_RETURN': return '<span style="color:#FF0000">' . "→" . '</span>' . $goto_id . '<span style="color:#FF0000">' . "↵" . '</span>';
|
|
|
+ case 'FORK': return '<span style="color:#FF0000">' . "⊕→" . '</span>' . $goto_id;
|
|
|
}
|
|
|
- return $ret;
|
|
|
+ return '';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -374,7 +246,8 @@ class ProcesHelper {
|
|
|
$ret = array();
|
|
|
$return_by = V::get('return_by', '', $params);
|
|
|
$db = DB::getDB();
|
|
|
- $sql = "select
|
|
|
+ $sql = "
|
|
|
+ select
|
|
|
p.`ID`
|
|
|
, p.`IF_TRUE_GOTO`
|
|
|
, p.`IF_TRUE_GOTO_FLAG`
|