Просмотр исходного кода

Fix bug #25 mais le code ne me convient pas. Le bug #28 devra corriger ce soucis

Marien Fressinaud 13 лет назад
Родитель
Сommit
47196182e5
3 измененных файлов с 23 добавлено и 11 удалено
  1. 1 3
      app/controllers/indexController.php
  2. 18 5
      app/models/Entry.php
  3. 4 3
      app/views/index/index.phtml

+ 1 - 3
app/controllers/indexController.php

@@ -74,9 +74,7 @@ class indexController extends ActionController {
 
 		try {
 			$this->view->entryPaginator = $entryDAO->getPaginator ($entries);
-		} catch (CurrentPagePaginationException $e) {
-			$error = true;
-		}
+		} catch (CurrentPagePaginationException $e) { }
 
 		$this->view->cat_aside = $catDAO->listCategories ();
 		$this->view->nb_favorites = $entryDAO->countFavorites ();

+ 18 - 5
app/models/Entry.php

@@ -247,7 +247,7 @@ class EntryDAO extends Model_pdo {
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 		$this->nbItems = $res[0]['count'];
 
-		$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
+		$deb = ($this->currentPage () - 1) * $this->nbItemsPerPage;
 		$fin = $this->nbItemsPerPage;
 
 		$sql = 'SELECT * FROM entry' . $where
@@ -281,7 +281,7 @@ class EntryDAO extends Model_pdo {
 			$sql = 'SELECT * FROM entry' . $where
 			     . ' ORDER BY date' . $order;
 		} else {
-			$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
+			$deb = ($this->currentPage () - 1) * $this->nbItemsPerPage;
 			$fin = $this->nbItemsPerPage;
 
 			$sql = 'SELECT * FROM entry' . $where
@@ -314,7 +314,7 @@ class EntryDAO extends Model_pdo {
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 		$this->nbItems = $res[0]['count'];
 
-		$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
+		$deb = ($this->currentPage () - 1) * $this->nbItemsPerPage;
 		$fin = $this->nbItemsPerPage;
 		$sql = 'SELECT e.* FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where
 		     . ' ORDER BY date' . $order
@@ -348,7 +348,7 @@ class EntryDAO extends Model_pdo {
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 		$this->nbItems = $res[0]['count'];
 
-		$deb = ($this->currentPage - 1) * $this->nbItemsPerPage;
+		$deb = ($this->currentPage () - 1) * $this->nbItemsPerPage;
 		$fin = $this->nbItemsPerPage;
 		$sql = 'SELECT * FROM entry e' . $where
 		     . ' ORDER BY date' . $order
@@ -400,12 +400,25 @@ class EntryDAO extends Model_pdo {
 	public function _currentPage ($value) {
 		$this->currentPage = $value;
 	}
+	public function currentPage () {
+		if ($this->currentPage < 1) {
+			return 1;
+		}
+
+		$maxPage = ceil ($this->nbItems / $this->nbItemsPerPage);
+		if ($this->currentPage > $maxPage) {
+			return $maxPage;
+		}
+
+		return $this->currentPage;
+
+	}
 
 	public function getPaginator ($entries) {
 		$paginator = new Paginator ($entries);
 		$paginator->_nbItems ($this->nbItems);
 		$paginator->_nbItemsPerPage ($this->nbItemsPerPage);
-		$paginator->_currentPage ($this->currentPage);
+		$paginator->_currentPage ($this->currentPage ());
 
 		return $paginator;
 	}

+ 4 - 3
app/views/index/index.phtml

@@ -1,6 +1,5 @@
 <?php $this->partial ('aside_flux'); ?>
 
-<?php $items = $this->entryPaginator->items (true); ?>
 <div class="nav_menu">
 	<a class="btn" href="<?php echo Url::display (array ('c' => 'feed', 'a' => 'actualize')); ?>"><i class="icon refresh"></i></a>
 
@@ -13,8 +12,10 @@
 	<?php } ?>
 </div>
 
-<?php if (!empty ($items)) { ?>
-
+<?php
+if (isset ($this->entryPaginator)) {
+	$items = $this->entryPaginator->items (true);
+?>
 <div id="stream">
 	<?php
 		$display_today = true;