RouteBase.php 4.4 KB

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