Selaa lähdekoodia

ajouts graphique + ajout suppression vieux articles

Marien Fressinaud 13 vuotta sitten
vanhempi
commit
6723babdd6

+ 3 - 0
app/App_FrontController.php

@@ -37,5 +37,8 @@ class App_FrontController extends FrontController {
 	
 	private function loadParamsView () {
 		View::_param ('conf', Session::param ('conf', new RSSConfiguration ()));
+		
+		$entryDAO = new EntryDAO ();
+		View::_param ('nb_not_read', $entryDAO->countNotRead ());
 	}
 }

+ 4 - 1
app/controllers/configureController.php

@@ -68,17 +68,20 @@ class configureController extends ActionController {
 			$view = Request::param ('default_view', 'all');
 			$display = Request::param ('display_posts', 'no');
 			$sort = Request::param ('sort_order', 'low_to_high');
+			$old = Request::param ('old_entries', 3);
 		
 			$this->view->conf->_postsPerPage (intval ($nb));
 			$this->view->conf->_defaultView ($view);
 			$this->view->conf->_displayPosts ($display);
 			$this->view->conf->_sortOrder ($sort);
+			$this->view->conf->_oldEntries ($old);
 		
 			$values = array (
 				'posts_per_page' => $this->view->conf->postsPerPage (),
 				'default_view' => $this->view->conf->defaultView (),
 				'display_posts' => $this->view->conf->displayPosts (),
-				'sort_order' => $this->view->conf->sortOrder ()
+				'sort_order' => $this->view->conf->sortOrder (),
+				'old_entries' => $this->view->conf->oldEntries (),
 			);
 		
 			$confDAO = new RSSConfigurationDAO ();

+ 2 - 2
app/controllers/feedController.php

@@ -70,11 +70,11 @@ class feedController extends ActionController {
 					'id_feed' => $feed->id ()
 				);
 				$entryDAO->addEntry ($values);
-				
-				// TODO gérer suppression des articles trop vieux (à paramétrer)
 			}
 		}
 		
+		$entryDAO->cleanOldEntries ($this->view->conf->oldEntries ());
+		
 		Request::forward (array (), true);
 	}
 	

+ 5 - 2
app/layout/aside.phtml

@@ -6,12 +6,15 @@
 	
 	<ul id="menu">
 		<li <?php echo Request::controllerName () == 'index' ? 'class="active"' : ''; ?>>
-			<a href="<?php echo Url::display (array ()); ?>">Flux RSS</a>
+			<a href="<?php echo Url::display (array ()); ?>">
+				Flux RSS <?php if ($this->nb_not_read > 0) { ?><span>(<?php echo $this->nb_not_read; ?> non lu<?php echo $this->nb_not_read > 1 ? 's' : ''; ?>)</span><?php } ?>
+			</a>
+			
 			<?php if (isset ($this->cat_aside)) { ?>
 			<ul id="flux_menu">
 				<li><a href="<?php echo Url::display (array ('params' => array ('get' => 'favoris'))); ?>">Favoris</a></li>
 				<?php foreach ($this->cat_aside as $cat) { ?>
-				<li><a href="<?php echo Url::display (array ('params' => array ('get' => $cat->id ()))); ?>"><?php echo $cat->name (); ?></a></li>
+				<li><a href="<?php echo Url::display (array ('params' => array ('get' => $cat->id ()))); ?>"><?php echo $cat->name (); ?> <span><?php echo $cat->nbFlux (); ?> flux</span></a></li>
 				<?php } ?>
 			</ul>
 			<?php } ?>

+ 18 - 4
app/models/Category.php

@@ -23,6 +23,10 @@ class Category extends Model {
 	public function color () {
 		return $this->color;
 	}
+	public function nbFlux () {
+		$catDAO = new CategoryDAO ();
+		return $catDAO->countFlux ($this->id ());
+	}
 	
 	public function _id ($value) {
 		$this->id = $value;
@@ -76,7 +80,7 @@ class CategoryDAO extends Model_pdo {
 	
 	public function deleteCategory ($id) {
 		$sql = 'DELETE FROM category WHERE id=?';
-		$stm = $this->bd->prepare ($sql); 
+		$stm = $this->bd->prepare ($sql);
 
 		$values = array ($id);
 
@@ -106,20 +110,30 @@ class CategoryDAO extends Model_pdo {
 	
 	public function listCategories () {
 		$sql = 'SELECT * FROM category';
-		$stm = $this->bd->prepare ($sql); 
+		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 
 		return HelperCategory::daoToCategory ($stm->fetchAll (PDO::FETCH_ASSOC));
 	}
 	
 	public function count () {
-		$sql = 'SELECT COUNT (*) AS count FROM category';
-		$stm = $this->bd->prepare ($sql); 
+		$sql = 'SELECT COUNT(*) AS count FROM category';
+		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 
 		return $res[0]['count'];
 	}
+	
+	public function countFlux ($id) {
+		$sql = 'SELECT COUNT(*) AS count FROM feed WHERE category=?';
+		$stm = $this->bd->prepare ($sql);
+		$values = array ($id);
+		$stm->execute ($values);
+		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
+
+		return $res[0]['count'];
+	}
 }
 
 class HelperCategory {

+ 28 - 3
app/models/Entry.php

@@ -161,6 +161,22 @@ class EntryDAO extends Model_pdo {
 		}
 	}
 	
+	public function cleanOldEntries ($nb_month) {
+		$date = 60 * 60 * 24 * 30 * $nb_month;
+		$sql = 'DELETE FROM entry WHERE date <= ? AND is_favorite = 0';
+		$stm = $this->bd->prepare ($sql);
+
+		$values = array (
+			time () - $date
+		);
+		
+		if ($stm && $stm->execute ($values)) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
 	public function searchById ($id) {
 		$sql = 'SELECT * FROM entry WHERE id=?';
 		$stm = $this->bd->prepare ($sql);
@@ -191,7 +207,7 @@ class EntryDAO extends Model_pdo {
 		}
 		
 		$sql = 'SELECT * FROM entry' . $where . ' ORDER BY date' . $order;
-		$stm = $this->bd->prepare ($sql); 
+		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 
 		return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
@@ -241,13 +257,22 @@ class EntryDAO extends Model_pdo {
 	}
 	
 	public function count () {
-		$sql = 'SELECT COUNT (*) AS count FROM entry';
-		$stm = $this->bd->prepare ($sql); 
+		$sql = 'SELECT COUNT(*) AS count FROM entry';
+		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 
 		return $res[0]['count'];
 	}
+	
+	public function countNotRead () {
+		$sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read=0';
+		$stm = $this->bd->prepare ($sql);
+		$stm->execute ();
+		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
+		
+		return $res[0]['count'];
+	}
 }
 
 class HelperEntry {

+ 3 - 3
app/models/Feed.php

@@ -161,7 +161,7 @@ class FeedDAO extends Model_pdo {
 	
 	public function listFeeds () {
 		$sql = 'SELECT * FROM feed';
-		$stm = $this->bd->prepare ($sql); 
+		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 
 		return HelperFeed::daoToFeed ($stm->fetchAll (PDO::FETCH_ASSOC));
@@ -179,8 +179,8 @@ class FeedDAO extends Model_pdo {
 	}
 	
 	public function count () {
-		$sql = 'SELECT COUNT (*) AS count FROM feed';
-		$stm = $this->bd->prepare ($sql); 
+		$sql = 'SELECT COUNT(*) AS count FROM feed';
+		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
 

+ 16 - 0
app/models/RSSConfiguration.php

@@ -5,6 +5,7 @@ class RSSConfiguration extends Model {
 	private $default_view;
 	private $display_posts;
 	private $sort_order;
+	private $old_entries;
 	
 	public function __construct () {
 		$confDAO = new RSSConfigurationDAO ();
@@ -12,6 +13,7 @@ class RSSConfiguration extends Model {
 		$this->_defaultView ($confDAO->default_view);
 		$this->_displayPosts ($confDAO->display_posts);
 		$this->_sortOrder ($confDAO->sort_order);
+		$this->_oldEntries ($confDAO->old_entries);
 	}
 	
 	public function postsPerPage () {
@@ -26,6 +28,9 @@ class RSSConfiguration extends Model {
 	public function sortOrder () {
 		return $this->sort_order;
 	}
+	public function oldEntries () {
+		return $this->old_entries;
+	}
 	
 	public function _postsPerPage ($value) {
 		if (is_int ($value)) {
@@ -55,6 +60,13 @@ class RSSConfiguration extends Model {
 			$this->sort_order = 'low_to_high';
 		}
 	}
+	public function _oldEntries ($value) {
+		if (is_int (intval ($value))) {
+			$this->old_entries = $value;
+		} else {
+			$this->old_entries = 3;
+		}
+	}
 }
 
 class RSSConfigurationDAO extends Model_array {
@@ -62,6 +74,7 @@ class RSSConfigurationDAO extends Model_array {
 	public $default_view = 'all';
 	public $display_posts = 'no';
 	public $sort_order = 'low_to_high';
+	public $old_entries = 3;
 
 	public function __construct () {
 		parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php');
@@ -78,6 +91,9 @@ class RSSConfigurationDAO extends Model_array {
 		if (isset ($this->array['sort_order'])) {
 			$this->sort_order = $this->array['sort_order'];
 		}
+		if (isset ($this->array['old_entries'])) {
+			$this->old_entries = $this->array['old_entries'];
+		}
 	}
 	
 	public function save ($values) {

+ 3 - 0
app/views/configure/display.phtml

@@ -4,6 +4,9 @@
 	<label for="posts_per_page">Nombre d'articles par page</label>
 	<input type="number" id="posts_per_page" name="posts_per_page" value="<?php echo $this->conf->postsPerPage (); ?>" />
 	
+	<label for="old_entries">Supprimer les articles au bout de (mois)</label>
+	<input type="number" id="old_entries" name="old_entries" value="<?php echo $this->conf->oldEntries (); ?>" />
+	
 	<label>Vue par défaut</label>
 	<div class="radio_group">
 		<input type="radio" name="default_view" id="radio_all" value="all"<?php echo $this->conf->defaultView () == 'all' ? ' checked="checked"' : ''; ?> />

+ 9 - 5
public/theme/base.css

@@ -115,23 +115,27 @@ form {
 				overflow: hidden;
 				line-height: 50px;
 			}
-				.aside li a, .aside li span {
+				.aside li > a, .aside li > span {
 					display: block;
 					width: 230px;
 					padding: 0 10px;
 				}
-					.aside li a:hover, .aside li span:hover {
+					.aside li > a:hover, .aside li > span:hover {
 						text-decoration: none;
 						background: #f0f0f0;
 					}
-					.aside li.disable span {
+					.aside li.disable > span {
 						background: #fff;
 					}
-				.aside li.active a {
+					.aside li > a span {
+						font-size: 90%;
+						float: right;
+					}
+				.aside li.active > a {
 					background: #0062BE;
 					color: #fff;
 				}
-				.aside li h2 {
+				.aside li > h2 {
 					height: 50px;
 					padding: 0;
 					text-align: center;