Browse Source

Fix issue #44 : affichage du nombre d'entrées non lues dans la sidebar

Marien Fressinaud 13 years ago
parent
commit
204761a810
2 changed files with 18 additions and 0 deletions
  1. 5 0
      app/layout/aside_flux.phtml
  2. 13 0
      app/models/Feed.php

+ 5 - 0
app/layout/aside_flux.phtml

@@ -58,10 +58,15 @@
 						</ul>
 					</div>
 
+					<?php $not_read = $feed->nbNotRead (); ?>
+
 					<img class="favicon" src="http://g.etfv.co/<?php echo $feed->website (); ?>" alt="favicon <?php echo $feed->name (); ?>" />
+					<?php echo $not_read > 0 ? '<b>' : ''; ?>
 					<a class="feed" href="<?php echo _url ('index', 'index', 'get', 'f_' . $feed->id ()); ?>">
+						<?php echo $not_read > 0 ? '(' . $not_read . ') ' : ''; ?>
 						<?php echo $feed->name(); ?>
 					</a>
+					<?php echo $not_read > 0 ? '</b>' : ''; ?>
 				</li>
 				<?php } ?>
 			</ul>

+ 13 - 0
app/models/Feed.php

@@ -58,6 +58,10 @@ class Feed extends Model {
 		$feedDAO = new FeedDAO ();
 		return $feedDAO->countEntries ($this->id ());
 	}
+	public function nbNotRead () {
+		$feedDAO = new FeedDAO ();
+		return $feedDAO->countNotRead ($this->id ());
+	}
 
 	public function _id ($value) {
 		$this->id = $value;
@@ -311,6 +315,15 @@ class FeedDAO extends Model_pdo {
 		$stm->execute ($values);
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 
+		return $res[0]['count'];
+	}
+	public function countNotRead ($id) {
+		$sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read=0 AND id_feed=?';
+		$stm = $this->bd->prepare ($sql);
+		$values = array ($id);
+		$stm->execute ($values);
+		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
 		return $res[0]['count'];
 	}
 }