UrlActions system

...
type = 'success'; $jsonData->msg = 'Gotowe'; try { $this->reinstall(); } catch (Exception $e) { $jsonData->type = 'danger'; $jsonData->msg = $e->getMessage(); } echo json_encode($jsonData); } public function reinstall() { $sqlList = array(); // alter table enum add URL_ACTION //$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS`"; $pdo = DB::getPDO(); foreach ($sqlList as $sqlName => $sql) { $pdo->exec($sql); } } /* 636 TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty 763 KOMORKA ID Nr 22332 22317 URL_ACTION ProjektyKosztyWstepnychRobot 22335 763 PARAM_IN ID_PROJECT 25 TYPESPECIALS TYPESPECIALS PowiÄ…zania tabel 22317 URL_ACTION ProjektyKosztyWstepnychRobot 22324 PARAM_IN ID_PROJECT */ static function fetchTableFunctions($idTbl) { return DB::getPDO()->fetchAll(" select z.ID as ID , IF(z.DESC_PL != '', z.DESC_PL, IF(za.DESC_PL != '', za.DESC_PL, z.`DESC`)) as fun_label , za.`DESC` as fun_name , zp.ALIAS_ID as param_in_to_cell_id , zp.DESC as param_in_name from CRM_LISTA_ZASOBOW z join CRM_LISTA_ZASOBOW za on(za.ID = z.ALIAS_ID) left join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = z.ID and zp.`TYPE` = 'PARAM_IN') left join CRM_LISTA_ZASOBOW zpa on(zpa.ID = zp.ALIAS_ID and zpa.`TYPE` = 'PARAM_IN' and zpa.`DESC` = zp.`DESC`) where z.PARENT_ID = :id_table and z.`TYPE` = 'URL_ACTION' ", [ ':id_table' => $idTbl, ]); } static function fetchTableFunctionsForUser($idTbl, $usrLogin) { return DB::getPDO()->fetchAll(" select z.ID as ID , IF(z.DESC_PL != '', z.DESC_PL, IF(za.DESC_PL != '', za.DESC_PL, z.`DESC`)) as fun_label , za.`DESC` as fun_name , zp.ALIAS_ID as param_in_to_cell_id , zp.DESC as param_in_name , param.`DESC` as link_param -- TODO find LINK_TARGET_SELF under za.ID - link target defined globally from CRM_LISTA_ZASOBOW z join CRM_LISTA_ZASOBOW za on(za.ID = z.ALIAS_ID) left join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = z.ID and zp.`TYPE` = 'PARAM_IN') left join CRM_LISTA_ZASOBOW zpa on(zpa.ID = zp.ALIAS_ID and zpa.`TYPE` = 'PARAM_IN' and zpa.`DESC` = zp.`DESC`) join CRM_WSKAZNIK w on(w.ID_ZASOB = z.ID and w.A_STATUS not in('DELETED')) -- join CRM_PROCES p on(p.ID = w.ID_PROCES) join CRM_PROCES_idx_USER_to_PROCES_VIEW upv on(upv.ID_PROCES = w.ID_PROCES) left join CRM_LISTA_ZASOBOW param on(param.PARENT_ID = z.ID and param.`TYPE` = 'DANE') where z.PARENT_ID = :id_table and z.`TYPE` = 'URL_ACTION' and upv.ADM_ACCOUNT = :user_login -- group by z.ID ", [ ':id_table' => $idTbl, ':user_login' => $usrLogin, ]); } static function getFeatureTools($idTable, $idFeature, $usrLogin = null) { return array_filter( self::_fetchAllTools($idTable, $usrLogin), function ($func) use ($idFeature) { return ("rowFunction" === $func['type']); } ); } static function getObjectTools($idTable, $usrLogin = null) { return array_filter( self::_fetchAllTools($idTable, $usrLogin), function ($func) use ($idFeature) { return ("table" === $func['type']); } ); } static function getSelectedFeatureTools($idTable, $usrLogin = null) { return array_filter( self::_fetchAllTools($idTable, $usrLogin), function ($func) use ($idFeature) { return ("@selected" === $func['type']); } ); } static function _fetchAllTools($idTable, $usrLogin = null) { $rows = (!empty($usrLogin)) ? self::fetchTableFunctionsForUser($idTable, $usrLogin) : $rows = self::fetchTableFunctions($idTable) ; DBG::log($rows, 'array', "_fetchAllTools({$idTbl}, {$idRecord}, ...) :: rows"); $functions = array_reduce($rows, function ($ret, $item) { if (!array_key_exists($item['ID'], $ret)) { $fun = array(); $fun['type'] = "table"; // default type - 'table', may be: '@selected' or 'rowFunction' $fun['label'] = $item['fun_label']; $fun['name'] = $item['fun_name']; $fun['baseLink'] = "index.php?_route=UrlAction_{$item['fun_name']}"; $fun['ico'] = "glyphicon glyphicon-share"; $fun['cell_id_params'] = array(); $fun['link_target'] = '_blank'; // LINK_TARGET_SELF $fun['url_args'] = []; // Zasob `TYPE` = 'DANE' whhere `DESC` != 'LINK_TARGET_SELF' $ret[ $item['ID'] ] = $fun; } $funParams = $ret[ $item['ID'] ]['cell_id_params']; if ("@selected" === $item['param_in_name']) { $ret[ $item['ID'] ]['type'] = "@selected"; } else if (!empty($item['param_in_name'])) { if ($item['param_in_to_cell_id'] > 0) {// ALIAS to field - get field value from item $funParams[ $item['param_in_to_cell_id'] ] = $item['param_in_name']; $ret[ $item['ID'] ]['cell_id_params'] = $funParams; $ret[ $item['ID'] ]['type'] = "rowFunction"; } else if (false !== strpos($item['param_in_name'], '=')) {// "{arg_name}={value}" - add to url $ret[ $item['ID'] ][ 'baseLink' ] .= "&" . $item['param_in_name']; } } if ('LINK_TARGET_SELF' == $item['link_param']) { unset($ret[ $item['ID'] ]['link_target']); } else if (!empty($item['link_param'])) { $ret[ $item['ID'] ]['url_args'][] = ( strpos($item['link_param'], '=') ? $item['link_param'] : $item['link_param'] . "=1" ); } return $ret; }, []); $functions = array_map(function ($fun) { // fix url_args $urlArgs = array_unique($fun['url_args']); unset($fun['url_args']); if (!empty($urlArgs)) { $fun['baseLink'] .= "&" . implode("&", $urlArgs); } return $fun; }, $functions); DBG::log($functions, 'array', "_fetchAllTools({$idTbl}, {$idRecord}, ...) :: all functions"); return $functions; } }