Browse Source

Fix issue #8 : ajoute le nombre de non lus pour les catégories (mérite amélioration ?)

Marien Fressinaud 13 years ago
parent
commit
0f2891f432
4 changed files with 32 additions and 24 deletions
  1. 13 5
      app/layout/aside.phtml
  2. 14 0
      app/models/Category.php
  3. 4 18
      app/views/javascript/main.phtml
  4. 1 1
      public/theme/base.css

+ 13 - 5
app/layout/aside.phtml

@@ -8,9 +8,7 @@
 	
 	<ul id="menu">
 		<li <?php echo Request::controllerName () == 'index' ? 'class="active"' : ''; ?>>
-			<a href="<?php echo Url::display (array ()); ?>">
-				Flux RSS <span class="nb_not_read"><?php if ($this->nb_not_read > 0) { ?>(<?php echo $this->nb_not_read; ?> non lu<?php echo $this->nb_not_read > 1 ? 's' : ''; ?>)<?php } ?></span>
-			</a>
+			<a href="<?php echo Url::display (array ()); ?>">Flux RSS</a>
 		</li>
 		
 		<?php if (!login_is_conf ($this->conf) || is_logged ()) { ?>
@@ -36,12 +34,22 @@
 	
 	<?php if (isset ($this->cat_aside)) { ?>
 	<ul id="categories">
-		<li class="all<?php echo !$this->get ? ' active' : ''; ?>"><a href="<?php echo Url::display (array ()); ?>">Tous <span><?php echo $this->nb_total; ?> article<?php echo $this->nb_total > 1 ? 's' : ''; ?></span></a></li>
+		<li class="all<?php echo !$this->get ? ' active' : ''; ?>">
+			<a href="<?php echo Url::display (array ()); ?>">
+				Tous
+				<span><?php echo $this->nb_total; ?> article<?php echo $this->nb_total > 1 ? 's' : ''; ?> (<span class="nb_not_read"><?php echo $this->nb_not_read; ?></span>)</span>
+			</a>
+		</li>
 		
 		<li class="favorites<?php echo $this->get == 'favoris' ? ' active' : ''; ?>"><a href="<?php echo Url::display (array ('params' => array ('get' => 'favoris'))); ?>">Favoris <span><?php echo $this->nb_favorites; ?> article<?php echo $this->nb_favorites > 1 ? 's' : ''; ?></span></a></li>
 		
 		<?php foreach ($this->cat_aside as $cat) { ?>
-		<li class="category<?php echo $this->get == $cat->id () ? ' active' : ''; ?>"><a href="<?php echo Url::display (array ('params' => array ('get' => $cat->id ()))); ?>"><?php echo $cat->name (); ?> <span><?php echo $cat->nbFeed (); ?> flux</span></a></li>
+		<li class="category<?php echo $this->get == $cat->id () ? ' active' : ''; ?>">
+			<a href="<?php echo Url::display (array ('params' => array ('get' => $cat->id ()))); ?>">
+				<?php echo $cat->name (); ?>
+				<span><?php echo $cat->nbFeed (); ?> flux (<?php echo $cat->nbNotRead (); ?>)</span>
+			</a>
+		</li>
 		<?php } ?>
 	</ul>
 	<?php } ?>

+ 14 - 0
app/models/Category.php

@@ -27,6 +27,10 @@ class Category extends Model {
 		$catDAO = new CategoryDAO ();
 		return $catDAO->countFeed ($this->id ());
 	}
+	public function nbNotRead () {
+		$catDAO = new CategoryDAO ();
+		return $catDAO->countNotRead ($this->id ());
+	}
 	
 	public function _id ($value) {
 		$this->id = $value;
@@ -134,6 +138,16 @@ class CategoryDAO extends Model_pdo {
 
 		return $res[0]['count'];
 	}
+	
+	public function countNotRead ($id) {
+		$sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE category=? AND e.is_read=0';
+		$stm = $this->bd->prepare ($sql);
+		$values = array ($id);
+		$stm->execute ($values);
+		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
+		return $res[0]['count'];
+	}
 }
 
 class HelperCategory {

+ 4 - 18
app/views/javascript/main.phtml

@@ -35,28 +35,14 @@ function slide (new_active, old_active) {
 }
 
 function add_not_read (nb) {
-	span_not_read = $("#main_aside #menu a span.nb_not_read");
+	span_not_read = $("#categories li.all span.nb_not_read");
 	
 	html = span_not_read.html ();
-	if (html == "" && nb > 0) {
-		nb_not_read = nb;
-	} else if (html != "") {
-		regex = /\((\d+) non lus?\)/;
-		nb_not_read = parseInt (regex.exec (html)[1]) + nb;
-	} else {
-		nb_not_read = 0;
-	}
 	
-	pluriel = "";
-	if (nb_not_read > 1) {
-		pluriel = "s";
-	}
+	regex = /(\d+)/;
+	nb_not_read = parseInt (regex.exec (html)[1]) + nb;
 	
-	if (nb_not_read > 0) {
-		span_not_read.html ("(" + nb_not_read + " non lu" + pluriel + ")");
-	} else {
-		span_not_read.html ("");
-	}
+	span_not_read.html (nb_not_read);
 }
 
 function mark_read (active) {

+ 1 - 1
public/theme/base.css

@@ -130,7 +130,7 @@ form {
 					.aside li.disable > span {
 						background: #fff;
 					}
-					.aside li > a span {
+					.aside li > a > span {
 						float: right;
 						padding: 0 5px;
 						font-size: 80%;