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

Fix issue #37 : possibilité de sortir un site du flux principal (utile pour les sites qui publient beaucoup)

Marien Fressinaud 13 лет назад
Родитель
Сommit
e2171de4e6

+ 3 - 1
app/controllers/configureController.php

@@ -88,10 +88,12 @@ class configureController extends ActionController {
 				if (Request::isPost () && $this->view->flux) {
 					$cat = Request::param ('category', 0);
 					$path = Request::param ('path_entries', '');
+					$priority = Request::param ('priority', 0);
 
 					$values = array (
 						'category' => $cat,
-						'pathEntries' => $path
+						'pathEntries' => $path,
+						'priority' => $priority
 					);
 
 					if ($feedDAO->updateFeed ($id, $values)) {

+ 1 - 3
app/controllers/indexController.php

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

+ 10 - 13
app/models/Entry.php

@@ -272,7 +272,7 @@ class EntryDAO extends Model_pdo {
 	}
 
 	public function markReadEntries ($read, $dateMax) {
-		$sql = 'UPDATE entry SET is_read = ? WHERE date < ?';
+		$sql = 'UPDATE entry e INNER JOIN feed f ON e.id_feed = f.id SET is_read = ? WHERE date < ? AND priority > 0';
 		$stm = $this->bd->prepare ($sql);
 
 		$values = array ($read, $dateMax);
@@ -377,19 +377,15 @@ class EntryDAO extends Model_pdo {
 	}
 
 	public function listEntries ($mode, $search = false, $order = 'high_to_low') {
-		$where = '';
+		$where = ' WHERE priority > 0';
 		if ($mode == 'not_read') {
-			$where = ' WHERE is_read=0';
+			$where .= ' AND is_read=0';
 		}
 
 		$values = array();
 		if ($search) {
 			$values[] = '%'.$search.'%';
-			if ($mode == 'not_read') {
-				$where = ' AND title LIKE ?';
-			} else {
-				$where = ' WHERE title LIKE ?';
-			}
+			$where .= ' AND title LIKE ?';
 		}
 
 		if ($order == 'low_to_high') {
@@ -398,7 +394,7 @@ class EntryDAO extends Model_pdo {
 			$order = '';
 		}
 
-		$sql = 'SELECT COUNT(*) AS count FROM entry' . $where;
+		$sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where;
 		$stm = $this->bd->prepare ($sql);
 		$stm->execute ($values);
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
@@ -407,7 +403,8 @@ class EntryDAO extends Model_pdo {
 		$deb = ($this->currentPage () - 1) * $this->nbItemsPerPage;
 		$fin = $this->nbItemsPerPage;
 
-		$sql = 'SELECT * FROM entry' . $where
+		$sql = 'SELECT * FROM entry e'
+		     . ' INNER JOIN feed f ON e.id_feed = f.id' . $where
 		     . ' ORDER BY date' . $order
 		     . ' LIMIT ' . $deb . ', ' . $fin;
 		$stm = $this->bd->prepare ($sql);
@@ -553,7 +550,7 @@ class EntryDAO extends Model_pdo {
 	}
 
 	public function count () {
-		$sql = 'SELECT COUNT(*) AS count FROM entry';
+		$sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE priority > 0';
 		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
@@ -562,11 +559,11 @@ class EntryDAO extends Model_pdo {
 	}
 
 	public function countNotRead () {
-		$sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read=0';
+		$sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE is_read=0 AND priority > 0';
 		$stm = $this->bd->prepare ($sql);
 		$stm->execute ();
 		$res = $stm->fetchAll (PDO::FETCH_ASSOC);
-
+		Log::record ('not read : ' . $res[0]['count'], Log::NOTICE);
 		return $res[0]['count'];
 	}
 

+ 11 - 0
app/models/Feed.php

@@ -9,6 +9,7 @@ class Feed extends Model {
 	private $website = '';
 	private $description = '';
 	private $lastUpdate = 0;
+	private $priority = 10;
 	private $pathEntries = '';
 	private $httpAuth = '';
 
@@ -48,6 +49,9 @@ class Feed extends Model {
 	public function lastUpdate () {
 		return $this->lastUpdate;
 	}
+	public function priority () {
+		return $this->priority;
+	}
 	public function pathEntries () {
 		return $this->pathEntries;
 	}
@@ -108,6 +112,12 @@ class Feed extends Model {
 	public function _lastUpdate ($value) {
 		$this->lastUpdate = $value;
 	}
+	public function _priority ($value) {
+		if (!is_int (intval ($value))) {
+			$value = 10;
+		}
+		$this->priority = $value;
+	}
 	public function _pathEntries ($value) {
 		$this->pathEntries = $value;
 	}
@@ -382,6 +392,7 @@ class HelperFeed {
 			$list[$key]->_website ($dao['website']);
 			$list[$key]->_description ($dao['description']);
 			$list[$key]->_lastUpdate ($dao['lastUpdate']);
+			$list[$key]->_priority ($dao['priority']);
 			$list[$key]->_pathEntries ($dao['pathEntries']);
 			$list[$key]->_httpAuth ($dao['httpAuth']);
 

+ 10 - 5
app/views/configure/feed.phtml

@@ -9,28 +9,25 @@
 
 	<form method="post" action="<?php echo _url ('configure', 'feed', 'id', $this->flux->id ()); ?>">
 		<legend>Informations</legend>
-
 		<div class="form-group">
 			<label class="group-name">URL du site</label>
 			<div class="group-controls">
 				<span class="control"><a target="_blank" href="<?php echo $this->flux->website (); ?>"><?php echo $this->flux->website (); ?></a></span>
 			</div>
 		</div>
-
 		<div class="form-group">
 			<label class="group-name">URL du flux</label>
 			<div class="group-controls">
 				<span class="control"><a target="_blank" href="<?php echo $this->flux->url (); ?>"><?php echo $this->flux->url (); ?></a></span>
 			</div>
 		</div>
-	
 		<div class="form-group">
 			<label class="group-name">Nombre d'articles</label>
 			<div class="group-controls">
 				<span class="control"><?php echo $this->flux->nbEntries (); ?></span>
 			</div>
 		</div>
-	
+
 		<legend>Catégorie - <a href="<?php echo _url ('configure', 'categorize'); ?>">gestion</a></legend>
 		<div class="form-group">
 			<label class="group-name">Ranger dans une catégorie</label>
@@ -45,6 +42,15 @@
 		</div>
 
 		<legend>Avancé</legend>
+		<div class="form-group">
+			<label class="group-name" for="priority">Afficher dans le flux principal</label>
+			<div class="group-controls">
+				<label class="checkbox" for="priority">
+					<input type="checkbox" name="priority" id="priority" value="10"<?php echo $this->flux->priority () > 0 ? ' checked="checked"' : ''; ?> />
+					Oui
+				</label>
+			</div>
+		</div>
 		<div class="form-group">
 			<label class="group-name" for="path_entries">Chemin CSS des articles sur le site d'origine</label>
 			<div class="group-controls">
@@ -52,7 +58,6 @@
 				<i class="icon i_help"></i> Permet de récupérer les flux tronqués (attention, demande plus de temps !)
 			</div>
 		</div>
-
 <!--
 		<div class="form-group">
 			<label class="group-name" for="http_user">Username HTTP</label>