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

Fix bug #30 : lorsque articles non lus dans une catégorie, les autres catégories affichent désormais tous leurs articles

Marien Fressinaud 13 лет назад
Родитель
Сommit
d2f0451eb3
3 измененных файлов с 133 добавлено и 52 удалено
  1. 106 50
      app/controllers/indexController.php
  2. 27 0
      app/models/Entry.php
  3. 0 2
      public/scripts/smoothscroll.js

+ 106 - 50
app/controllers/indexController.php

@@ -1,8 +1,11 @@
 <?php
 
 class indexController extends ActionController {
+	private $get = false;
+	private $nb_not_read = 0;
+	private $mode = 'all';
+
 	public function indexAction () {
-		View::appendScript (Url::display ('/scripts/smoothscroll.js'));
 		View::appendScript (Url::display ('/scripts/shortcut.js'));
 		View::appendScript (Url::display (array ('c' => 'javascript', 'a' => 'main')));
 
@@ -17,53 +20,39 @@ class indexController extends ActionController {
 		$entryDAO->_nbItemsPerPage ($this->view->conf->postsPerPage ());
 		$entryDAO->_currentPage ($page);
 
+		// récupération de la catégorie/flux à filtrer
+		$this->initFilter ();
+		// Compte le nombre d'articles non lus en prenant en compte le filtre
+		$this->countNotRead ();
 		// mode de vue (tout ou seulement non lus)
-		$default_view = $this->view->conf->defaultView ();
-		$mode = Session::param ('mode');
-		if ($mode == false) {
-			if ($default_view == 'not_read' && $this->view->nb_not_read < 1) {
-				$mode = 'all';
-			} else {
-				$mode = $default_view;
-			}
-		}
-
+		$this->initCurrentMode ();
 		// ordre de listage des flux
 		$order = Session::param ('order', $this->view->conf->sortOrder ());
-
 		// recherche sur les titres (pour le moment)
 		$search = Request::param ('search');
 
-		// récupération de la catégorie/flux à filtrer
-		$get = Request::param ('get');
-		$this->view->get_c = false;
-		$this->view->get_f = false;
-
 		// Récupère les flux par catégorie, favoris ou tous
-		if ($get == 'favoris') {
-			$entries = $entryDAO->listFavorites ($mode, $search, $order);
-			$this->view->get_c = $get;
+		if ($this->get['type'] == 'all') {
+			$entries = $entryDAO->listEntries ($this->mode, $search, $order);
+			View::prependTitle ('Vos flux RSS - ');
+		} elseif ($this->get['type'] == 'favoris') {
+			$entries = $entryDAO->listFavorites ($this->mode, $search, $order);
 			View::prependTitle ('Vos favoris - ');
-		} elseif ($get != false) {
-			$typeGet = $get[0];
-			$get = substr ($get, 2);
-
-			if ($typeGet == 'c') {
-				$entries = $entryDAO->listByCategory ($get, $mode, $search, $order);
-				$cat = $catDAO->searchById ($get);
+		} elseif ($this->get != false) {
+			if ($this->get['type'] == 'c') {
+				$cat = $catDAO->searchById ($this->get['filter']);
 
 				if ($cat) {
-					$this->view->get_c = $get;
+					$entries = $entryDAO->listByCategory ($this->get['filter'], $this->mode, $search, $order);
 					View::prependTitle ($cat->name () . ' - ');
 				} else {
 					$error = true;
 				}
-			} elseif ($typeGet == 'f') {
-				$entries = $entryDAO->listByFeed ($get, $mode, $search, $order);
-				$feed = $feedDAO->searchById ($get);
+			} elseif ($this->get['type'] == 'f') {
+				$feed = $feedDAO->searchById ($this->get['filter']);
 
 				if ($feed) {
-					$this->view->get_f = $get;
+					$entries = $entryDAO->listByFeed ($this->get['filter'], $this->mode, $search, $order);
 					$this->view->get_c = $feed->category ();
 					View::prependTitle ($feed->name () . ' - ');
 				} else {
@@ -73,31 +62,27 @@ class indexController extends ActionController {
 				$error = true;
 			}
 		} else {
-			View::prependTitle ('Vos flux RSS - ');
-		}
-
-		$this->view->mode = $mode;
-		$this->view->order = $order;
-
-		// Cas où on ne choisie ni catégorie ni les favoris
-		// ou si la catégorie ne correspond à aucune
-		if (!isset ($entries)) {
-			$entries = $entryDAO->listEntries ($mode, $search, $order);
+			$error = true;
 		}
 
-		try {
-			$this->view->entryPaginator = $entryDAO->getPaginator ($entries);
-		} catch (CurrentPagePaginationException $e) { }
-
-		$this->view->cat_aside = $catDAO->listCategories ();
-		$this->view->nb_favorites = $entryDAO->countFavorites ();
-		$this->view->nb_total = $entryDAO->count ();
-
 		if ($error) {
 			Error::error (
 				404,
 				array ('error' => array ('La page que vous cherchez n\'existe pas'))
 			);
+		} else {
+			$this->view->mode = $this->mode;
+			$this->view->order = $order;
+
+			try {
+				$this->view->entryPaginator = $entryDAO->getPaginator ($entries);
+			} catch (CurrentPagePaginationException $e) {
+
+			}
+
+			$this->view->cat_aside = $catDAO->listCategories ();
+			$this->view->nb_favorites = $entryDAO->countFavorites ();
+			$this->view->nb_total = $entryDAO->count ();
 		}
 	}
 
@@ -162,4 +147,75 @@ class indexController extends ActionController {
 		$this->view->_useLayout (false);
 		Session::_param ('mail');
 	}
+
+	private function initFilter () {
+		$get = Request::param ('get');
+		$this->view->get_c = false;
+		$this->view->get_f = false;
+
+		$typeGet = $get[0];
+		$filter = substr ($get, 2);
+
+		if ($get == 'favoris') {
+			$this->view->get_c = $get;
+
+			$this->get = array (
+				'type' => $get,
+				'filter' => $get
+			);
+		} elseif ($get == false) {
+			$this->get = array (
+				'type' => 'all',
+				'filter' => 'all'
+			);
+		} else {
+			if ($typeGet == 'f') {
+				$this->view->get_f = $filter;
+
+				$this->get = array (
+					'type' => $typeGet,
+					'filter' => $filter
+				);
+			} elseif ($typeGet == 'c') {
+				$this->view->get_c = $filter;
+
+				$this->get = array (
+					'type' => $typeGet,
+					'filter' => $filter
+				);
+			} else {
+				$this->get = false;
+			}
+		}
+	}
+
+	private function countNotRead () {
+		$entryDAO = new EntryDAO ();
+
+		if ($this->get != false) {
+			if ($this->get['type'] == 'all') {
+				$this->nb_not_read = $this->view->nb_not_read;
+			} elseif ($this->get['type'] == 'favoris') {
+				$this->nb_not_read = $entryDAO->countNotReadFavorites ();
+			} elseif ($this->get['type'] == 'c') {
+				$this->nb_not_read = $entryDAO->countNotReadByCat ($this->get['filter']);
+			} elseif ($this->get['type'] == 'f') {
+				$this->nb_not_read = $entryDAO->countNotReadByFeed ($this->get['filter']);
+			}
+		}
+	}
+
+	private function initCurrentMode () {
+		$default_view = $this->view->conf->defaultView ();
+		$mode = Session::param ('mode');
+		if ($mode == false) {
+			if ($default_view == 'not_read' && $this->nb_not_read < 1) {
+				$mode = 'all';
+			} else {
+				$mode = $default_view;
+			}
+		}
+
+		$this->mode = $mode;
+	}
 }

+ 27 - 0
app/models/Entry.php

@@ -443,6 +443,33 @@ class EntryDAO extends Model_pdo {
 		return $res[0]['count'];
 	}
 
+	public function countNotReadByFeed ($id) {
+		$sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read = 0 AND id_feed = ?';
+		$stm = $this->bd->prepare ($sql);
+		$stm->execute (array ($id));
+		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
+		return $res[0]['count'];
+	}
+
+	public function countNotReadByCat ($id) {
+		$sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE is_read=0 AND category = ?';
+		$stm = $this->bd->prepare ($sql);
+		$stm->execute (array ($id));
+		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
+		return $res[0]['count'];
+	}
+
+	public function countNotReadFavorites () {
+		$sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read=0 AND is_favorite=1';
+		$stm = $this->bd->prepare ($sql);
+		$stm->execute ();
+		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
+		return $res[0]['count'];
+	}
+
 	public function countFavorites () {
 		$sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_favorite=1';
 		$stm = $this->bd->prepare ($sql);

Разница между файлами не показана из-за своего большого размера
+ 0 - 2
public/scripts/smoothscroll.js


Некоторые файлы не были показаны из-за большого количества измененных файлов