--- 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 }
--- 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
--- 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
--- 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 @@
-<div id="suggestionFilm-list">
- <ul>
- <?php
- foreach($films as $item):
- $ref = $item->getRef();
- $slug = $item->getSlugUrl();
- $title = $item->getTitle();
-
- // image file
- $image_file = $item->getImages();
- // image file
- $video_file = $item->getVideos();
-
- ?>
- <li>
- <div id="playerMostTagged-<?php echo $ref; ?>" class="player-item" style="background:transparent url('<?php echo image_path('posters/'.$image_file[0]['file'].'.jpg'); ?>') no-repeat;" href="<?php echo video_path($video_file[0]['file']);?>">
- <div class="infos">
- <a href="<?php echo url_for('@editor?ref='.$ref.'&film_slug='.$slug); ?>" class="title"><?php echo $title; ?></a> <span class="film-infos">De <?php echo thd_render_flat_list($item->getDirectorsArray(), 'name'); ?></span>
- </div>
- <img src="<?php echo image_path('buttons/btn_play.png'); ?>"/ id="play"></a>
- <div class="tags">
- <ul class="item-list tag-list">
- <li><span class="head">
- <i>Tags liƩs au film :</i>
- </span></li>
- <li class="tag-score-<?php echo $tag['score']; ?>">
- <a href="">anna</a>
- </li><li class="tag-score-5">
- <a href="">Jalousie</a>
- </li><li class="tag-score-3">
- <a href="">erotomanie</a>
- </li><li class="tag-score-2">
- <a href="">violence</a>
- </li>
- <li class="tag-score-<?php echo $tag['score']; ?>">
- <a href="">anna</a>
- </li><li class="tag-score-5">
- <a href="">Jalousie</a>
- </li><li class="tag-score-3">
- <a href="">erotomanie</a>
- </li><li class="tag-score-2">
- <a href="">violence</a>
- </li>
- </ul>
- </div>
- </div>
- <div class="tag-action"><a href="<?php echo url_for('@editor?ref='.$ref.'&film_slug='.$slug); ?>" class="link-button">Tagger le film</a></div>
- </li>
- <?php endforeach; ?>
- </ul>
+<div class="film-list-2-columns">
+ <?php echo thd_render_pager_navigation($pageIndex, $pageCount, $itemCount, $routeUri); ?>
+ <ul class="film-list">
+ <?php
+ foreach($films as $item):
+ $tagFilmUri = url_for('@editor?ref='.$item->getRef().'&film_slug='.$item->getSlugUrl());
+ ?>
+ <li>
+ <?php include_component('partials', 'filmItem', Array('film' => $item, 'actionUri' => $tagFilmUri)); ?>
+ <div class="tag-action"><a href="<?php echo $tagFilmUri ?>" class="link-button">Tagger le film</a></div>
+ </li>
+ <?php endforeach; ?>
+ </ul>
+ <?php echo thd_render_pager_navigation($pageIndex, $pageCount, $itemCount, $routeUri); ?>
</div>
\ No newline at end of file
--- 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 @@
-<div id="content">
- <div id="film-list">
- <h3>Tous les films</h3>
- <ul>
- <?php
- foreach($films as $item):
- $tagFilmUri = url_for('@editor?ref='.$item->getRef().'&film_slug='.$item->getSlugUrl());
- ?>
- <li>
- <?php include_component('partials', 'filmItem', Array('film' => $item, 'actionUri' => $tagFilmUri)); ?>
- <div class="tag-action"><a href="<?php echo $tagFilmUri ?>" class="link-button">Tagger le film</a></div>
- </li>
- <?php endforeach; ?>
- </ul>
-</div>
-</div>
+<h3>Tous les films (<?php echo $itemCount; ?>)</h3>
+<?php include_partial('films/filmList', Array('films' => $films, 'pageIndex' => $pageIndex, 'pageCount' => $pageCount, 'itemCount' => $itemCount, 'routeUri' => $routeUri)); ?>
--- 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 @@
-<div id="content">
- <div id="film-list">
- <h3>Top des films</h3>
- <ul>
- <?php
- foreach($mostTaggedFilms as $item):
- $tagFilmUri = url_for('@editor?ref='.$item->getRef().'&film_slug='.$item->getSlugUrl());
- ?>
- <li>
- <?php include_component('partials', 'filmItem', Array('film' => $item, 'actionUri' => $tagFilmUri)); ?>
- <div class="tag-action"><a href="<?php echo $tagFilmUri ?>" class="link-button">Tagger le film</a></div>
- </li>
- <?php endforeach; ?>
- </ul>
-</div>
-</div>
+<h3>Top des films (<?php echo $itemCount; ?>)</h3>
+<?php include_partial('films/filmList', Array('films' => $films, 'pageIndex' => $pageIndex, 'pageCount' => $pageCount, 'itemCount' => $itemCount, 'routeUri' => $routeUri)); ?>
--- 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[] = '<li class="rewind-first"><a href="'.url_for($routeUri.'1').'"><<</a></li>';
+ $itemsHtml[] = '<li class="rewind"><a href="'.url_for($routeUri.''.$pageIndex). '"><</a></li>';
+ } else {
+ $itemsHtml[] = '<li class="rewind-first disabled"><span><<</span></li>';
+ $itemsHtml[] = '<li class="rewind-first disabled"><span><</span></li>';
+ }
+
+ foreach ($displayedPages as $setIndex=>$pages) {
+ foreach ($pages as $index) {
+ $pageNb = $index + 1;
+ if ($index == $pageIndex) {
+ $itemsHtml[] = '<li class="selected"><span>'.$pageNb.'</span></li>';
+ } else {
+ $pageUri = url_for($routeUri.''.$pageNb);
+ $itemsHtml[] = '<li><a href="'.$pageUri. '">'.$pageNb.'</a></li>';
+ }
+ }
+
+ // add separator
+ if ($setIndex < count($displayedPages)-1) {
+ $itemsHtml[] = '<li class="separator"><span>...</span></li>';
+ }
+ }
+
+ // Add forward actions
+ if ($pageIndex < ($nbPages-1)) {
+ $itemsHtml[] = '<li class="forward"><a href="'.url_for($routeUri.''.($pageIndex+2)).'">>></a></li>';
+ $itemsHtml[] = '<li class="forward-last"><a href="'.url_for($routeUri.''.$nbPages).'">></a></li>';
+ } else {
+ $itemsHtml[] = '<li class="forward disabled"><span>>></span></li>';
+ $itemsHtml[] = '<li class="forward-last disabled"><span>></span></li>';
+ }
+
+ $classes = ($classes) ? 'pager-navigation '.$classes : 'pager-navigation';
+ return '<div class="'.$classes.'"><ul class="item-list pager-list">'.implode('', $itemsHtml).'</ul></div>';
+}
+
function poster_path($source, $absolute = false) {
return sfConfig::get('app_poster_root_uri').'/'.$source;
}
--- 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
--- 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;