| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- <?php
- Lib::loadClass('RouteBase');
- /*
- ## Url Actions (to replace Typespecial's):
- - new Zasob type: 'URL_ACTION'
- ## Config in Zasoby tree (TODO: upload from gui xml file or php):
- [100] - TYPESPECIALS
- [110] - URL_ACTION ProjektyKosztyWstepnychRobot
- [111] - PARAM_IN ID_PROJECT
- [200] - TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty
- [210] - KOMORKA ID
- [220] - (ALIAS to [110]) URL_ACTION action name/label
- [221] - (ALIAS to [210]) PARAM_IN ID_PROJECT
- class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {
- public function defaultAction() {
- $args = array();
- $args['ID_PROJECT'] = V::get('ID_PROJECT', '', $_REQUEST);// [111]
- }
- }
- ## Process - Create:
- - 1. define action name in Zasoby tree (URL_ACTION) and expected args (PARAM_IN) - `ActionDefinition`
- - 2. create action alias inside TABLE - `ActionInstance`
- - 3. set perms for `ActionInstance`
- ## Process - Install ActionDefinitio's:
- - class UrlActionBase :: installZasobAction
- - create required Zasoby in Zasob Tree if not exists
- */
- class Route_UrlAction extends RouteBase {// TODO: UrlActionBase
- public function handleAuth() {
- if (!User::logged()) {
- throw new HttpException('Unauthorized', 401);
- }
- }
- public function defaultAction() {
- SE_Layout::gora();
- ?>
- <div class="container">
- <h1>UrlActions system</h1>
- ...
- </div>
- <?php
- SE_Layout::dol();
- }
- public function getArgsList() {
- $args = array();
- return $args;
- }
- public function reinstallAction() {
- $jsonData = new stdClass();
- $jsonData->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;
- }
- }
|