# HG changeset patch # User clebeaupin # Date 1271266068 -7200 # Node ID 34b333f92573694a9514c7fd927de7213b46779d # Parent 0851f98246af84cc19e004a0c11b5b92dface7da Add pager diff -r 0851f98246af -r 34b333f92573 web/thdProject/apps/frontend/config/routing.yml --- a/web/thdProject/apps/frontend/config/routing.yml Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/apps/frontend/config/routing.yml Wed Apr 14 19:27:48 2010 +0200 @@ -61,13 +61,13 @@ ######## viewFilmList: - url: /films/:sort_by/:sort_order/:page_nb - param: { module: films, action: viewFilmList, sort_by: date, sort_order: desc, page_nb: 1} + url: /films/:page/:page_nb + param: { module: films, action: viewFilmList, page: page, page_nb: 1 } requirements: { page_nb: \d+ } viewTopFilmList: - url: /top-des-films - param: { module: films, action: viewTopFilmList } + url: /top-des-films/:page/:page_nb + param: { module: films, action: viewTopFilmList, page: page, page_nb: 1 } diff -r 0851f98246af -r 34b333f92573 web/thdProject/apps/frontend/modules/films/actions/viewFilmListAction.class.php --- a/web/thdProject/apps/frontend/modules/films/actions/viewFilmListAction.class.php Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/apps/frontend/modules/films/actions/viewFilmListAction.class.php Wed Apr 14 19:27:48 2010 +0200 @@ -7,14 +7,26 @@ { public function execute($request) { + // Get pager information + $pageNb = (int) $this->getRequestParameter('page_nb', 1); + $this->pageIndex = $pageNb -1; + $this->pageNbItems = 10; + $this->routeUri = '@viewFilmList'; + + // Initialize query $query = Doctrine_Query::create() ->from('ThdFilm F') ->leftJoin('F.images I ') ->leftJoin('F.videos V') //->where("cu.code='{$culture}' AND mo.code='{$module}' AND ms.code='{$section}'") - ->orderBy('F.id DESC') - ->limit(10); - $this->films = $query->execute(); + ->orderBy('F.id DESC'); + $this->itemCount = $query->count(); + $this->pageCount = (int) ceil($this->itemCount/$this->pageNbItems); + $this->films = $query->offset($this->pageIndex*$this->pageNbItems)->limit($this->pageNbItems)->execute(); + + if ($this->pageIndex*$this->pageNbItems > $this->itemCount) { + $this->forward404(); } + } } ?> \ No newline at end of file diff -r 0851f98246af -r 34b333f92573 web/thdProject/apps/frontend/modules/films/actions/viewTopFilmListAction.class.php --- a/web/thdProject/apps/frontend/modules/films/actions/viewTopFilmListAction.class.php Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/apps/frontend/modules/films/actions/viewTopFilmListAction.class.php Wed Apr 14 19:27:48 2010 +0200 @@ -3,16 +3,25 @@ class viewTopFilmListAction extends sfAction { public function execute($request) { - // FIXME: Dummy value - $this->tag = Array('score' => 3); - $query = Doctrine_Query::create() + // Get pager information + $pageNb = (int) $this->getRequestParameter('page_nb', 1); + $this->pageIndex = $pageNb -1; + $this->pageNbItems = 10; + $this->routeUri = '@viewFilmList'; + + // Initialize query + $query = Doctrine_Query::create() ->from('ThdFilm F') ->leftJoin('F.images I ') ->leftJoin('F.videos V') //->where("cu.code='{$culture}' AND mo.code='{$module}' AND ms.code='{$section}'") - ->orderBy('F.ref ASC') - ->limit(0,10); - $this->mostTaggedFilms = $query->execute(); - $this->videoPath = sfConfig::get('app_player_videoPath'); + ->orderBy('F.ref ASC'); + $this->itemCount = $query->count(); + $this->pageCount = (int) ceil($this->itemCount/$this->pageNbItems); + $this->films = $query->offset($this->pageIndex*$this->pageNbItems)->limit($this->pageNbItems)->execute(); + + if ($this->pageIndex*$this->pageNbItems > $this->itemCount) { + $this->forward404(); + } } } \ No newline at end of file diff -r 0851f98246af -r 34b333f92573 web/thdProject/apps/frontend/modules/films/templates/_filmList.php --- a/web/thdProject/apps/frontend/modules/films/templates/_filmList.php Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/apps/frontend/modules/films/templates/_filmList.php Wed Apr 14 19:27:48 2010 +0200 @@ -1,51 +1,15 @@ -
- +
+ + +
\ No newline at end of file diff -r 0851f98246af -r 34b333f92573 web/thdProject/apps/frontend/modules/films/templates/viewFilmListSuccess.php --- a/web/thdProject/apps/frontend/modules/films/templates/viewFilmListSuccess.php Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/apps/frontend/modules/films/templates/viewFilmListSuccess.php Wed Apr 14 19:27:48 2010 +0200 @@ -1,16 +1,2 @@ -
-
-

Tous les films

-
    - getRef().'&film_slug='.$item->getSlugUrl()); - ?> -
  • - $item, 'actionUri' => $tagFilmUri)); ?> - -
  • - -
-
-
+

Tous les films ()

+ $films, 'pageIndex' => $pageIndex, 'pageCount' => $pageCount, 'itemCount' => $itemCount, 'routeUri' => $routeUri)); ?> diff -r 0851f98246af -r 34b333f92573 web/thdProject/apps/frontend/modules/films/templates/viewTopFilmListSuccess.php --- a/web/thdProject/apps/frontend/modules/films/templates/viewTopFilmListSuccess.php Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/apps/frontend/modules/films/templates/viewTopFilmListSuccess.php Wed Apr 14 19:27:48 2010 +0200 @@ -1,16 +1,2 @@ -
-
-

Top des films

-
    - getRef().'&film_slug='.$item->getSlugUrl()); - ?> -
  • - $item, 'actionUri' => $tagFilmUri)); ?> - -
  • - -
-
-
+

Top des films ()

+ $films, 'pageIndex' => $pageIndex, 'pageCount' => $pageCount, 'itemCount' => $itemCount, 'routeUri' => $routeUri)); ?> diff -r 0851f98246af -r 34b333f92573 web/thdProject/lib/helper/ThdHtmlHelper.php --- a/web/thdProject/lib/helper/ThdHtmlHelper.php Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/lib/helper/ThdHtmlHelper.php Wed Apr 14 19:27:48 2010 +0200 @@ -45,6 +45,74 @@ return implode($glue, $itemsHtml); } +/** + * Helper used to render a pager navigation + * + * @param UcDbPager $pager + * @param int $pageIndex + * @param string $routeUri + */ + +function thd_render_pager_navigation($pageIndex, $pageCount, $itemCount, $routeUri, $classes='') { + $words = explode('?', $routeUri); + $routeUri .= (count($words) == 2) ? '&page_nb=' : '?page_nb='; + $nbPages = $pageCount; + if ($nbPages < 2) return ''; + $itemsHtml = Array(); + $pageLimit = 5; + $pageMiddleLimit = (int) ($pageLimit/2); + $pageMaxLimit = $pageLimit + $pageMiddleLimit; + $displayedPages = Array(); + + if ($nbPages < ($pageMaxLimit*2)) { + $displayedPages = Array(range(0, $nbPages-1)); + } else if ($pageIndex >= $pageMaxLimit-1 && $pageIndex <= ($nbPages-$pageMaxLimit)) { + $displayedPages = Array(range(0, $pageMiddleLimit), range($pageIndex-$pageMiddleLimit, $pageIndex+$pageMiddleLimit), range($nbPages-$pageMiddleLimit-1, $nbPages-1)); + } else if ($pageIndex < $pageMaxLimit) { + $displayedPages = Array(range(0, ($pageIndex < $pageLimit-$pageMiddleLimit) ? $pageLimit-1 : $pageIndex+$pageMiddleLimit), range($nbPages-$pageMiddleLimit-1, $nbPages-1)); + } else { + $displayedPages = Array(range(0, $pageMiddleLimit-1), range(($pageIndex > ($nbPages-$pageLimit+1)) ? $nbPages-$pageLimit : $pageIndex-$pageMiddleLimit, $nbPages-1)); + } + + // Add rewind actions + if ($pageIndex > 0) { + $itemsHtml[] = '
  • <<
  • '; + $itemsHtml[] = '
  • <
  • '; + } else { + $itemsHtml[] = '
  • <<
  • '; + $itemsHtml[] = '
  • <
  • '; + } + + foreach ($displayedPages as $setIndex=>$pages) { + foreach ($pages as $index) { + $pageNb = $index + 1; + if ($index == $pageIndex) { + $itemsHtml[] = '
  • '.$pageNb.'
  • '; + } else { + $pageUri = url_for($routeUri.''.$pageNb); + $itemsHtml[] = '
  • '.$pageNb.'
  • '; + } + } + + // add separator + if ($setIndex < count($displayedPages)-1) { + $itemsHtml[] = '
  • ...
  • '; + } + } + + // Add forward actions + if ($pageIndex < ($nbPages-1)) { + $itemsHtml[] = '
  • >>
  • '; + $itemsHtml[] = '
  • >
  • '; + } else { + $itemsHtml[] = '
  • >>
  • '; + $itemsHtml[] = '
  • >
  • '; + } + + $classes = ($classes) ? 'pager-navigation '.$classes : 'pager-navigation'; + return '
    '; +} + function poster_path($source, $absolute = false) { return sfConfig::get('app_poster_root_uri').'/'.$source; } diff -r 0851f98246af -r 34b333f92573 web/thdProject/web/css/base.css --- a/web/thdProject/web/css/base.css Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/web/css/base.css Wed Apr 14 19:27:48 2010 +0200 @@ -528,12 +528,49 @@ } -/*Film list*/ -#film-list ul, li { - margin: 0; - padding: 0; +/* Pager navigation */ +.pager-navigation { + clear: both; + z-index: 100; +} + +.pager-navigation ul { + list-style: none; + display: block; + float: right; } -#film-list li { + +.pager-navigation ul li { + display: block; + float: left; + margin: 5px; +} + +/* Film list */ +.film-list-2-columns { + width: 720px; +} + +.film-list-2-columns ul.film-list { + clear: both; + display: block; + list-style: none; + margin: 20px 0; +} + +.film-list-2-columns ul.film-list li { + display: block; float: left; margin: 0 10px 0 10px; +} + +/* Clear items */ +.pager-navigation:after, +.film-list-2-columns ul.film-list:after { + content: "."; + display: block; + height: 0; + overflow: hidden; + clear: both; + visibility: hidden; } \ No newline at end of file diff -r 0851f98246af -r 34b333f92573 web/thdProject/web/css/layout.css --- a/web/thdProject/web/css/layout.css Wed Apr 14 18:53:02 2010 +0200 +++ b/web/thdProject/web/css/layout.css Wed Apr 14 19:27:48 2010 +0200 @@ -61,10 +61,7 @@ #header-user { position: absolute; top: 7px; - right: 100px; - width: 380px; - height: 240px; - + right: 100px; } #header-user .main { @@ -318,16 +315,6 @@ -/*FILMS LIST*/ - -#film-list { - width: 780px; - margin: 20px 0; -} - - - - /* FOOTER============= */ #footer { clear:both;