HosipLan

Untitled

Aug 30th, 2013
109
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.                     return $params;
  34.                 },
  35.                 Route::FILTER_OUT => function($params) use ($db) {
  36.                     if (!empty($params['id']) && is_numeric($params['id'])){
  37.                         /** @var $pages \Nette\Database\Table\Selection */
  38.                         $pages = $db->table('cardCategories')->get($params['id']);
  39.                         if ($pages === false) {
  40.                             $params['id'] = 1;
  41.                         } else {
  42.                             $params['id'] = $params['id'] . ';'. Strings::webalize($pages->{'name_'.$params['locale']});
  43.                         }
  44.                     }
  45.  
  46.                     if ($params['locale'] === 'en') {
  47.                         $params['action'] = 'virtual-postcards';
  48.                     } else {
  49.                         $params['action'] = 'virtualne-pohladnice';
  50.                     }
  51.  
  52.                     return $params;
  53.                 }
  54.             ),
  55.             'presenter' => 'Virtualnepohladnice',
  56.             'action' => 'show'
  57.         ));
  58.  
  59.         $router[] = new Route('[<locale [a-z]{2}>/]<presenter>/<action>[/<id>]', 'Homepage:default');
  60.  
  61.         return $router;
  62.  
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment