Overview

Namespaces

  • App
    • Components
    • Interfaces
    • Lib
      • Files
      • Forms
        • Controls
      • Html
      • Repair
      • Statics
    • Model
    • Modules
      • BaseModule
        • Presenters
      • PartnersModule
        • Presenters
      • ProductModule
        • Presenters
      • SaleModule
        • Model
        • Presenters
      • SettingsModule
        • Model
        • Presenters
      • StoreModule
        • Model
        • Presenters
    • Presenters
    • Router
  • PHP

Classes

  • DateTime
  • SplFileInfo

Interfaces

  • ArrayAccess
  • Countable
  • Exception
  • Iterator
  • Traversable
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Download
 1: <?php
 2: 
 3: /**
 4:  * Project sberp
 5:  *
 6:  * @file RouterFactory 
 7:  * @author Jaromír Polášek
 8:  * @version 0.5.1
 9:  * Encoding UTF-8
10:  */
11: 
12: namespace App\Router;
13: 
14: use Nette,
15:     Nette\Application\Routers\RouteList,
16:     Nette\Application\Routers\Route,
17:     App\Lib\Table,
18:     App\Model\Database,
19:     App\Lib\Statics\Cons;
20: 
21: /**
22:  * Router pro základní operace s routami
23:  */
24: class RouterFactory {
25: 
26:     /** !!! (neimplementováno - ceká se na module raider)
27:      * Získá seznam aktivních modulú z tabulky Core_module 
28:      * @return Nette\Database\Table\Selection
29:      */
30:     public static function getModules(Database $database) {
31:     $modules = new Table(Cons::TABLE_MODULE, $database);
32:     return $modules->getData()->where(Cons::COLUMN_ACTIVE, true);
33:     }
34: 
35:     /**
36:      * Vrací routu z tabulky action
37:      * @param \Nette\Database\Table\ActiveRow\ $row
38:      * @return string
39:      */
40:     public static function getRouteString(\Nette\Database\Table\ActiveRow $row) {
41:     return (string)
42:         ':' . $row[Cons::TABLE_PRESENTER][Cons::TABLE_MODULE][Cons::COLUMN_DIR] .
43:         ':' . $row[Cons::TABLE_PRESENTER][Cons::COLUMN_NAME] .
44:         ':' . $row[Cons::COLUMN_ACTION];
45:     }
46: 
47:     /**
48:      * Vrací routu z tabulky action
49:      * @param \Nette\Database\Table\ActiveRow $row
50:      * @return array
51:      */
52:     public static function getRouteArray($row) {
53:     return array(
54:         'module' => $row[Cons::TABLE_PRESENTER][Cons::TABLE_MODULE][Cons::COLUMN_DIR],
55:         'presenter' => $row[Cons::TABLE_PRESENTER][Cons::COLUMN_NAME],
56:         'action' => $row[Cons::COLUMN_ACTION],
57:         'source' => NULL, //$row[Cons::COLUMN_ID],
58:         'id' => NULL);
59:     }
60: 
61:     /**
62:      * Vytvoří Router. (Nezamezuje duplicitě rout)
63:      * @return \Nette\Application\IRouter
64:      */
65:     public static function createRouter(Database $database) {
66:     $table = (new Table(Cons::TABLE_SOURCE, $database))->data;  
67:     $router = new RouteList();
68:     $router[] = new Route('<module>/<presenter>/<action>[/<source>[/<id>]]', RouterFactory::getLoginLink());
69:     foreach ($table as $row) {
70:         $router[] = new Route('<module>/<presenter>/<action>[/<source>[/<id>]]', RouterFactory::getRouteArray($row));
71:     }
72:     return $router;
73:     }
74: 
75:     /**
76:      * Vrací Přihlašovací routu
77:      * @return array
78:      */
79:     private static function getLoginLink() {
80:     return array(
81:         'module' => 'Base',
82:         'presenter' => 'Sign',
83:         'action' => 'in',
84:         'source' => 0,
85:         'id' => NULL);
86:     }
87: }
88: 
sberp API API documentation generated by ApiGen