UrlAction.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. Lib::loadClass('RouteBase');
  3. /*
  4. ## Url Actions (to replace Typespecial's):
  5. - new Zasob type: 'URL_ACTION'
  6. ## Config in Zasoby tree (TODO: upload from gui xml file or php):
  7. [100] - TYPESPECIALS
  8. [110] - URL_ACTION ProjektyKosztyWstepnychRobot
  9. [111] - PARAM_IN ID_PROJECT
  10. [200] - TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty
  11. [210] - KOMORKA ID
  12. [220] - (ALIAS to [110]) URL_ACTION action name/label
  13. [221] - (ALIAS to [210]) PARAM_IN ID_PROJECT
  14. class Route_UrlAction_ProjektyKosztyWstepnychRobot extends RouteBase {
  15. public function defaultAction() {
  16. $args = array();
  17. $args['ID_PROJECT'] = V::get('ID_PROJECT', '', $_REQUEST);// [111]
  18. }
  19. }
  20. ## Process - Create:
  21. - 1. define action name in Zasoby tree (URL_ACTION) and expected args (PARAM_IN) - `ActionDefinition`
  22. - 2. create action alias inside TABLE - `ActionInstance`
  23. - 3. set perms for `ActionInstance`
  24. ## Process - Install ActionDefinitio's:
  25. - class UrlActionBase :: installZasobAction
  26. - create required Zasoby in Zasob Tree if not exists
  27. */
  28. class Route_UrlAction extends RouteBase {// TODO: UrlActionBase
  29. public function handleAuth() {
  30. if (!User::logged()) {
  31. throw new HttpException('Unauthorized', 401);
  32. }
  33. }
  34. public function defaultAction() {
  35. SE_Layout::gora();
  36. ?>
  37. <div class="container">
  38. <h1>UrlActions system</h1>
  39. ...
  40. </div>
  41. <?php
  42. SE_Layout::dol();
  43. }
  44. public function getArgsList() {
  45. $args = array();
  46. return $args;
  47. }
  48. public function reinstallAction() {
  49. $jsonData = new stdClass();
  50. $jsonData->type = 'success';
  51. $jsonData->msg = 'Gotowe';
  52. try {
  53. $this->reinstall();
  54. } catch (Exception $e) {
  55. $jsonData->type = 'danger';
  56. $jsonData->msg = $e->getMessage();
  57. }
  58. echo json_encode($jsonData);
  59. }
  60. public function reinstall() {
  61. $sqlList = array();
  62. // alter table enum add URL_ACTION
  63. //$sqlList['RemoveTable'] = "DROP TABLE IF EXISTS `CRM_UI_MSGS`";
  64. $pdo = DB::getPDO();
  65. foreach ($sqlList as $sqlName => $sql) {
  66. $pdo->exec($sql);
  67. }
  68. }
  69. public static function getTableFunctions($idTbl, $idRecord, $tblName = '') {
  70. $pdo = DB::getPDO();
  71. /*
  72. 636 TABELA IN7_MK_BAZA_DYSTRYBUCJI Projekty
  73. 763 KOMORKA ID Nr
  74. 22332 22317 URL_ACTION ProjektyKosztyWstepnychRobot
  75. 22335 763 PARAM_IN ID_PROJECT
  76. 25 TYPESPECIALS TYPESPECIALS Powiązania tabel
  77. 22317 URL_ACTION ProjektyKosztyWstepnychRobot
  78. 22324 PARAM_IN ID_PROJECT
  79. */
  80. $sth = $pdo->prepare("
  81. select z.ID as ID
  82. , z.`DESC_PL` as fun_label
  83. , za.`DESC` as fun_name
  84. , zp.ALIAS_ID as param_in_to_cell_id
  85. , zp.DESC as param_in_name
  86. from CRM_LISTA_ZASOBOW z
  87. join CRM_LISTA_ZASOBOW za on(za.ID = z.ALIAS_ID)
  88. left join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = z.ID and zp.`TYPE` = 'PARAM_IN')
  89. left join CRM_LISTA_ZASOBOW zpa on(zpa.ID = zp.ALIAS_ID and zpa.`TYPE` = 'PARAM_IN' and zpa.`DESC` = zp.`DESC`)
  90. where z.PARENT_ID = :id_zasob
  91. and z.`TYPE` = 'URL_ACTION'
  92. ");
  93. $sth->bindValue(':id_zasob', $idTbl, PDO::PARAM_STR);
  94. $sth->execute();
  95. $rows = $sth->fetchAll();
  96. $functions = array();
  97. foreach ($rows as $row) {
  98. if (!array_key_exists($row['ID'], $functions)) {
  99. $fun = array();
  100. $fun['label'] = $row['fun_label'];
  101. $fun['name'] = $row['fun_name'];
  102. $fun['baseLink'] = "index.php?_route=UrlAction_{$row['fun_name']}";
  103. $fun['ico'] = "glyphicon glyphicon-share";
  104. $fun['cell_id_params'] = array();
  105. $functions[$row['ID']] = $fun;
  106. }
  107. $funParams = $functions[$row['ID']]['cell_id_params'];
  108. if ($row['param_in_to_cell_id'] > 0 && !empty($row['param_in_name'])) {
  109. $funParams[$row['param_in_to_cell_id']] = $row['param_in_name'];
  110. $functions[$row['ID']]['cell_id_params'] = $funParams;
  111. }
  112. }
  113. return $functions;
  114. }
  115. }