| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- class RouteBase {
- public function route() {
- $task = V::get('_task', '', $_REQUEST);
- if (empty($task)) {
- $this->defaultAction();
- return;
- }
- $methodName = "{$task}Action";
- if (method_exists($this, $methodName)) {
- $this->{$methodName}();
- } else {
- die("Task '{$task}' not exists");
- }
- }
- public function defaultAction() {
- die("default task not implemented");
- }
- public function getLink($task = '', $args = null) {
- $clsName = get_class($this);
- if ('Route_' != substr($clsName, 0, strlen('Route_'))) throw new Exception("Wrong route class name '{$clsName}'");
- $routeName = substr($clsName, strlen('Route_'));
- if (empty($args)) return Request::getPathUri() . "index.php?_route={$routeName}" . (!empty($task) ? "&_task={$task}" : "");
- if (is_string($args)) {
- return Request::getPathUri() . "index.php?_route={$routeName}" . (!empty($task) ? "&_task={$task}" : "") . ltrim($args, '&');
- }
- if (is_array($args)) {
- $urlArgs = [];
- $uniqArgs = [];
- if (!empty($task)) $uniqArgs['_task'] = $task;
- foreach ($args as $name => $val) $uniqArgs[$name] = $val;
- foreach ($uniqArgs as $name => $val) $urlArgs[] = "{$name}={$val}";
- return Request::getPathUri() . "index.php?_route={$routeName}" . (!empty($urlArgs) ? '&' . implode('&', $urlArgs) : '');
- }
- throw new Exception("Not Implemented args type", 501);
- }
- public function runTask($task) {
- if (empty($task)) throw new Exception("Empty method name");
- $methodName = "{$task}Action";
- if (!method_exists($this, $methodName)) {
- throw new Exception("Task '{$task}' not exists");
- }
- $this->{$methodName}();
- }
- public function runMethod($methodName) {
- if (empty($methodName)) throw new Exception("Empty method name");
- if (!method_exists($this, $methodName)) {
- throw new Exception("Task '{$methodName}' not exists");
- }
- $this->{$methodName}();
- }
- public function parseMessageFromStorageTestAction() {
- $msgs = V::get('msgs', '', $_GET);
- //echo $this->parseMessageFromStorage($msg);
- Lib::loadClass('StorageException');
- if (is_array($msgs)) {
- foreach ($msgs as $vMsg) {
- try {
- throw new StorageException($vMsg);
- } catch (Exception $e) {
- $vParsedMsg = $e->getMessage();
- echo " MSG: {$vMsg}\n";
- echo "PARSED: {$vParsedMsg}\n";
- echo "isMsgParsed(" . ($vMsg != $vParsedMsg) . ")\n\n";
- }
- }
- } else {
- throw new StorageException($msgs);
- }
- echo "\n\n";
- die("parseMessageFromStorage end");
- }
- public function parseMessageFromStorage($msg) {
- return $msg;
- }
- public function parseMessageFromMsgsSystem($msg) {
- return $msg;
- }
- public function runByMessageFromMsgsSystem($msg, & $execNotes) {
- }
- public function handleAuth() {
- User::authByRequest();
- }
- public function menu() {
- $getLink = array($this, 'getLink');
- echo UI::h('ul', [], array_map(
- function ($method) use ($getLink) {
- $action = substr($method, 0, -6);
- return UI::h('li', [],
- UI::h('a', [
- 'href' => $getLink($action)
- ], $action)
- );
- }
- , array_filter(
- get_class_methods($this)
- , function ($method) {
- if ('Action' != substr($method, -6)) return false;
- if ('parseMessageFromStorageTestAction' == $method) return false;
- return true;
- }
- )
- ));
- }
- public function reinstall() {
- $clsName = get_class($this);
- if ('Route_UrlAction' == substr($clsName, 0, strlen('Route_UrlAction'))) {
- $actionName = substr($clsName, strlen('Route_UrlAction_'));
- DBG::log(['msg'=>"\$actionName", '$actionName'=>$actionName]);
- $idTypespecial = DB::getPDO()->fetchValue("
- select z.ID
- from CRM_LISTA_ZASOBOW z
- where z.`TYPE` = 'TYPESPECIALS'
- ");
- if (!$idTypespecial) {
- $idTypespecial = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
- 'TYPE' => 'TYPESPECIALS',
- 'DESC' => 'TYPESPECIALS',
- 'DESC_PL' => 'Powiązania tabel',
- 'OPIS' => 'Powiązania i relacje tabel do wyświetlania w funkcjach systemowych',
- ]);
- }
- DBG::log(['msg'=>"\$idTypespecial", '$idTypespecial'=>$idTypespecial]);
- if (!$idTypespecial) throw new Exception("Wystąpił błąd podczas tworzenia zasobu 'Powiązania tabel' (TYPESPECIALS)");
- $idAction = DB::getPDO()->fetchValue("
- select z.ID
- from CRM_LISTA_ZASOBOW z
- where z.`PARENT_ID` = {$idTypespecial}
- and z.`DESC` = '{$actionName}'
- ");
- if (!$idAction) {
- $idAction = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
- 'PARENT_ID' => $idTypespecial,
- 'TYPE' => 'URL_ACTION',
- 'DESC' => $actionName,
- 'DESC_PL' => $this->getActionLabel(),
- 'OPIS' => $this->getActionDescription(),
- ]);
- }
- DBG::log(['msg'=>"\$idAction", '$idAction'=>$idAction]);
- if (!$idAction) throw new Exception("Wystąpił błąd podczas tworzenia zasobu funkcji '{$actionName}' (URL_ACTION)");
- $args = $this->getActionArgs();
- foreach ($args as $argName => $argDesc) {
- $idArg = DB::getPDO()->fetchValue("
- select z.ID
- from CRM_LISTA_ZASOBOW z
- where z.`PARENT_ID` = {$idAction}
- and z.`TYPE` = 'PARAM_IN'
- and z.`DESC` = '{$argName}'
- ");
- if (!$idArg) {
- $idArg = DB::getPDO()->insert('CRM_LISTA_ZASOBOW', [
- 'PARENT_ID' => $idAction,
- 'TYPE' => 'PARAM_IN',
- 'DESC' => $argName,
- 'OPIS' => $argDesc,
- ]);
- }
- DBG::log(['msg'=>"\$idArg ('{$argName}')", '$idArg'=>$idArg]);
- if (!$idArg) throw new Exception("Wystąpił błąd podczas tworzenia zasobu dla argumentu funkcji '{$actionName}' '{$argName}' (PARAM_IN)");
- }
- }
- }
- public function getActionLabel() { return ""; }
- public function getActionDescription() { return ""; }
- public function getActionArgs() { return []; }
- }
|