HosipLan

Untitled

Aug 30th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. use Nette\Application\Routers\RouteList,
  4.     Nette\Application\Routers\Route,
  5.     Nette\Application\Routers\SimpleRouter;
  6. use Nette\Utils\Strings;
  7.  
  8.  
  9. /**
  10.  * Router factory.
  11.  */
  12. class RouterFactory
  13. {
  14.  
  15.     /**
  16.      * @return Nette\Application\IRouter
  17.      */
  18.     public function createRouter(\Nette\Database\SelectionFactory $db)
  19.     {
  20.         $router = new RouteList();
  21.         $router[] = new Route('index.php', 'Homepage:default', Route::ONE_WAY);
  22.         //$router[] = new Route('[<locale=sk sk|en>/]<presenter>/<action>[/<id>]', 'Homepage:default');
  23.  
  24.         $router[] = new Route('[<locale [a-z]{2}>/]virtualne-pohladnice', 'Virtualnepohladnice:default');
  25.         $router[] = new Route('[<locale [a-z]{2}>/][!<action virtualne-pohladnice|virtual-postcards>]/<id>', array(
  26.             NULL => array (
  27.                 Route::FILTER_IN => function ($params) use ($db) {
  28.                     if (!is_numeric($params['id'])) {
  29.                         @list($id, $name) = explode(';', $params['id']);
  30.                         $params['id'] = intval($id);
  31.                     }
  32.  
  33.                     $params['action'] = 'show';
  34.  
  35.                     return $params;
  36.                 },
  37.                 Route::FILTER_OUT => function($params) use ($db) {
  38.                     if (is_numeric($params['id'])){
  39.                         /** @var $pages \Nette\Database\Table\Selection */
  40.                         $pages = $db->table('cardCategories')->get($params['id']);
  41.                         if ($pages === false) {
  42.                             $params['id'] = 1;
  43.                         } else {
  44.                             $params['id'] = $id . ';'. Strings::webalize($pages->name_sk);
  45.                         }
  46.                     }
  47.  
  48.                     if ($params['locale'] === 'en') {
  49.                         $params['action'] = 'virtual-postcards';
  50.                     } else {
  51.                         $params['action'] = 'virtualne-pohladnice';
  52.                     }
  53.  
  54.                     return $params;
  55.                 }
  56.             ),
  57.             'presenter' => 'Virtualnepohladnice',
  58.             'action' => 'show'
  59.         ));
  60.  
  61.         $router[] = new Route('[<locale [a-z]{2}>/]<presenter>/<action>[/<id>]', 'Homepage:default');
  62.  
  63.         return $router;
  64.  
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment