Sfoglia il codice sorgente

Minor syntax changes for: New toggle buttons to filter articles

See
http://programmers.stackexchange.com/questions/23852/bitwise-or-vs-adding-flags
https://github.com/marienfressinaud/FreshRSS/pull/486
https://github.com/marienfressinaud/FreshRSS/issues/376
Alexandre Alapetite 12 anni fa
parent
commit
f25783ef5d
2 ha cambiato i file con 17 aggiunte e 22 eliminazioni
  1. 9 14
      app/Models/EntryDAO.php
  2. 8 8
      app/layout/nav_menu.phtml

+ 9 - 14
app/Models/EntryDAO.php

@@ -406,7 +406,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 		return isset ($entries[0]) ? $entries[0] : null;
 	}
 
-	private function sqlListWhere($type = 'a', $id = '', $state = null , $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {
+	private function sqlListWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {
 		if (!$state) {
 			$state = FreshRSS_Entry::STATE_ALL;
 		}
@@ -418,8 +418,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 				$where .= 'f.priority > 0 ';
 				$joinFeed = true;
 				break;
-			case 's':
-				// This is deprecated. The favorite button does not exist anymore
+			case 's':	//Deprecated: use $state instead
 				$where .= 'e1.is_favorite = 1 ';
 				break;
 			case 'c':
@@ -443,21 +442,17 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 				$where .= 'AND e1.is_read = 0 ';
 			}
 		}
-		if ($state & FreshRSS_Entry::STATE_READ) {
-			if (!($state & FreshRSS_Entry::STATE_NOT_READ)) {
-				$where .= 'AND e1.is_read = 1 ';
-			}
-		}
-		if ($state & FreshRSS_Entry::STATE_NOT_FAVORITE) {
-			if (!($state & FreshRSS_Entry::STATE_FAVORITE)) {
-				$where .= 'AND e1.is_favorite = 0 ';
-			}
+		elseif ($state & FreshRSS_Entry::STATE_READ) {
+			$where .= 'AND e1.is_read = 1 ';
 		}
 		if ($state & FreshRSS_Entry::STATE_FAVORITE) {
 			if (!($state & FreshRSS_Entry::STATE_NOT_FAVORITE)) {
 				$where .= 'AND e1.is_favorite = 1 ';
 			}
 		}
+		elseif ($state & FreshRSS_Entry::STATE_NOT_FAVORITE) {
+			$where .= 'AND e1.is_favorite = 0 ';
+		}
 
 		switch ($order) {
 			case 'DESC':
@@ -539,7 +534,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 			. ($limit > 0 ? ' LIMIT ' . $limit : ''));	//TODO: See http://explainextended.com/2009/10/23/mysql-order-by-limit-performance-late-row-lookups/
 	}
 
-	public function listWhere($type = 'a', $id = '', $state = null, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {
+	public function listWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {
 		list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min, $showOlderUnreadsorFavorites, $keepHistoryDefault);
 
 		$sql = 'SELECT e.id, e.guid, e.title, e.author, UNCOMPRESS(e.content_bin) AS content, e.link, e.date, e.is_read, e.is_favorite, e.id_feed, e.tags '
@@ -555,7 +550,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
 		return self::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
 	}
 
-	public function listIdsWhere($type = 'a', $id = '', $state = null, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {	//For API
+	public function listIdsWhere($type = 'a', $id = '', $state = FreshRSS_Entry::STATE_ALL, $order = 'DESC', $limit = 1, $firstId = '', $filter = '', $date_min = 0, $showOlderUnreadsorFavorites = false, $keepHistoryDefault = 0) {	//For API
 		list($values, $sql) = $this->sqlListWhere($type, $id, $state, $order, $limit, $firstId, $filter, $date_min, $showOlderUnreadsorFavorites, $keepHistoryDefault);
 
 		$stm = $this->bd->prepare($sql);

+ 8 - 8
app/layout/nav_menu.phtml

@@ -9,11 +9,11 @@
 	<?php if ($this->loginOk) { ?>
 	<?php $url_state = $this->url;
 		if ($this->state & FreshRSS_Entry::STATE_READ) {
-			$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_READ;
+			$url_state['params']['state'] = $this->state & ~FreshRSS_Entry::STATE_READ;
 			$checked = 'true';
 			$class = 'active';
 		} else {
-			$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_READ;
+			$url_state['params']['state'] = $this->state | FreshRSS_Entry::STATE_READ;
 			$checked = 'false';
 			$class = '';
 		}
@@ -28,11 +28,11 @@
 		</a>
 		<?php
 			if ($this->state & FreshRSS_Entry::STATE_NOT_READ) {
-				$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_NOT_READ;
+				$url_state['params']['state'] = $this->state & ~FreshRSS_Entry::STATE_NOT_READ;
 				$checked = 'true';
 				$class = 'active';
 			} else {
-				$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_NOT_READ;
+				$url_state['params']['state'] = $this->state | FreshRSS_Entry::STATE_NOT_READ;
 				$checked = 'false';
 				$class = '';
 			}
@@ -46,11 +46,11 @@
 		</a>
 		<?php
 			if ($this->state & FreshRSS_Entry::STATE_FAVORITE) {
-				$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_FAVORITE;
+				$url_state['params']['state'] = $this->state & ~FreshRSS_Entry::STATE_FAVORITE;
 				$checked = 'true';
 				$class = 'active';
 			} else {
-				$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_FAVORITE;
+				$url_state['params']['state'] = $this->state | FreshRSS_Entry::STATE_FAVORITE;
 				$checked = 'false';
 				$class = '';
 			}
@@ -64,11 +64,11 @@
 		</a>
 		<?php
 			if ($this->state & FreshRSS_Entry::STATE_NOT_FAVORITE) {
-				$url_state['params']['state'] = $this->state - FreshRSS_Entry::STATE_NOT_FAVORITE;
+				$url_state['params']['state'] = $this->state & ~FreshRSS_Entry::STATE_NOT_FAVORITE;
 				$checked = 'true';
 				$class = 'active';
 			} else {
-				$url_state['params']['state'] = $this->state + FreshRSS_Entry::STATE_NOT_FAVORITE;
+				$url_state['params']['state'] = $this->state | FreshRSS_Entry::STATE_NOT_FAVORITE;
 				$checked = 'false';
 				$class = '';
 			}