RouteBase.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. class RouteBase {
  3. public function route() {
  4. $task = V::get('_task', '', $_REQUEST);
  5. if (empty($task)) {
  6. $this->defaultAction();
  7. return;
  8. }
  9. $methodName = "{$task}Action";
  10. if (method_exists($this, $methodName)) {
  11. $this->{$methodName}();
  12. } else {
  13. die("Task '{$task}' not exists");
  14. }
  15. }
  16. public function defaultAction() {
  17. die("default task not implemented");
  18. }
  19. public function runTask($task) {
  20. if (empty($task)) throw new Exception("Empty method name");
  21. $methodName = "{$task}Action";
  22. if (!method_exists($this, $methodName)) {
  23. throw new Exception("Task '{$task}' not exists");
  24. }
  25. $this->{$methodName}();
  26. }
  27. public function runMethod($methodName) {
  28. if (empty($methodName)) throw new Exception("Empty method name");
  29. if (!method_exists($this, $methodName)) {
  30. throw new Exception("Task '{$methodName}' not exists");
  31. }
  32. $this->{$methodName}();
  33. }
  34. public function parseMessageFromStorageTestAction() {
  35. $msgs = V::get('msgs', '', $_GET);
  36. //echo $this->parseMessageFromStorage($msg);
  37. Lib::loadClass('StorageException');
  38. if (is_array($msgs)) {
  39. foreach ($msgs as $vMsg) {
  40. try {
  41. throw new StorageException($vMsg);
  42. } catch (Exception $e) {
  43. $vParsedMsg = $e->getMessage();
  44. echo " MSG: {$vMsg}\n";
  45. echo "PARSED: {$vParsedMsg}\n";
  46. echo "isMsgParsed(" . ($vMsg != $vParsedMsg) . ")\n\n";
  47. }
  48. }
  49. } else {
  50. throw new StorageException($msgs);
  51. }
  52. echo "\n\n";
  53. die("parseMessageFromStorage end");
  54. }
  55. public function parseMessageFromStorage($msg) {
  56. return $msg;
  57. }
  58. public function parseMessageFromMsgsSystem($msg) {
  59. return $msg;
  60. }
  61. public function runByMessageFromMsgsSystem($msg, & $execNotes) {
  62. }
  63. public function handleAuth() {
  64. User::authByRequest();
  65. }
  66. public function reinstall() {
  67. $clsName = get_class($this);
  68. if ('Route_UrlAction' == substr($clsName, 0, strlen('Route_UrlAction'))) {
  69. $actionName = substr($clsName, strlen('Route_UrlAction_'));
  70. DBG::log(['msg'=>"\$actionName", '$actionName'=>$actionName]);
  71. $idTypespecial = DB::getPDO()->fetchValue("
  72. select z.ID
  73. from CRM_LISTA_ZASOBOW z
  74. where z.`TYPE` = 'TYPESPECIALS'
  75. ");
  76. if (!$idTypespecial) {
  77. $idTypespecial = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
  78. 'TYPE' => 'TYPESPECIALS',
  79. 'DESC' => 'TYPESPECIALS',
  80. 'DESC_PL' => 'Powiązania tabel',
  81. 'OPIS' => 'Powiązania i relacje tabel do wyświetlania w funkcjach systemowych',
  82. ]);
  83. }
  84. DBG::log(['msg'=>"\$idTypespecial", '$idTypespecial'=>$idTypespecial]);
  85. if (!$idTypespecial) throw new Exception("Wystąpił błąd podczas tworzenia zasobu 'Powiązania tabel' (TYPESPECIALS)");
  86. $idAction = DB::getPDO()->fetchValue("
  87. select z.ID
  88. from CRM_LISTA_ZASOBOW z
  89. where z.`PARENT_ID` = {$idTypespecial}
  90. and z.`DESC` = '{$actionName}'
  91. ");
  92. if (!$idAction) {
  93. $idAction = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
  94. 'PARENT_ID' => $idTypespecial,
  95. 'TYPE' => 'URL_ACTION',
  96. 'DESC' => $actionName,
  97. 'DESC_PL' => $this->getActionLabel(),
  98. 'OPIS' => $this->getActionDescription(),
  99. ]);
  100. }
  101. DBG::log(['msg'=>"\$idAction", '$idAction'=>$idAction]);
  102. if (!$idAction) throw new Exception("Wystąpił błąd podczas tworzenia zasobu funkcji '{$actionName}' (URL_ACTION)");
  103. $args = $this->getActionArgs();
  104. foreach ($args as $argName => $argDesc) {
  105. $idArg = DB::getPDO()->fetchValue("
  106. select z.ID
  107. from CRM_LISTA_ZASOBOW z
  108. where z.`PARENT_ID` = {$idAction}
  109. and z.`TYPE` = 'PARAM_IN'
  110. and z.`DESC` = '{$argName}'
  111. ");
  112. if (!$idArg) {
  113. $idArg = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
  114. 'PARENT_ID' => $idAction,
  115. 'TYPE' => 'PARAM_IN',
  116. 'DESC' => $argName,
  117. 'OPIS' => $argDesc,
  118. ]);
  119. }
  120. DBG::log(['msg'=>"\$idArg ('{$argName}')", '$idArg'=>$idArg]);
  121. if (!$idArg) throw new Exception("Wystąpił błąd podczas tworzenia zasobu dla argumentu funkcji '{$actionName}' '{$argName}' (PARAM_IN)");
  122. }
  123. }
  124. }
  125. public function getActionLabel() { return ""; }
  126. public function getActionDescription() { return ""; }
  127. public function getActionArgs() { return []; }
  128. }