Procházet zdrojové kódy

Ajout de 2 champs pour entry (is_public et lastUpdate) + gestion des nouveaux champs dans la classe Entry

Marien Fressinaud před 13 roky
rodič
revize
76b071a560
3 změnil soubory, kde provedl 108 přidání a 30 odebrání
  1. 2 24
      app/controllers/feedController.php
  2. 103 5
      app/models/Entry.php
  3. 3 1
      freshrss.sql

+ 2 - 24
app/controllers/feedController.php

@@ -35,18 +35,7 @@ class feedController extends ActionController {
 						$entryDAO = new EntryDAO ();
 						$entries = $feed->entries ();
 						foreach ($entries as $entry) {
-							$values = array (
-								'id' => $entry->id (),
-								'guid' => $entry->guid (),
-								'title' => $entry->title (),
-								'author' => $entry->author (),
-								'content' => $entry->content (),
-								'link' => $entry->link (),
-								'date' => $entry->date (true),
-								'is_read' => $entry->isRead (),
-								'is_favorite' => $entry->isFavorite (),
-								'id_feed' => $feed->id ()
-							);
+							$values = $entry->toArray ();
 							$entryDAO->addEntry ($values);
 						}
 
@@ -104,18 +93,7 @@ class feedController extends ActionController {
 
 			foreach ($entries as $entry) {
 				if ($entry->date (true) >= $date_min) {
-					$values = array (
-						'id' => $entry->id (),
-						'guid' => $entry->guid (),
-						'title' => $entry->title (),
-						'author' => $entry->author (),
-						'content' => $entry->content (),
-						'link' => $entry->link (),
-						'date' => $entry->date (true),
-						'is_read' => $entry->isRead (),
-						'is_favorite' => $entry->isFavorite (),
-						'id_feed' => $feed->id ()
-					);
+					$values = $entry->toArray ();
 					$entryDAO->addEntry ($values);
 				}
 			}

+ 103 - 5
app/models/Entry.php

@@ -11,10 +11,15 @@ class Entry extends Model {
 	private $date;
 	private $is_read;
 	private $is_favorite;
+	private $is_public;
 	private $feed;
+	private $tags;
+	private $notes;
+	private $lastUpdate;
 
 	public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '',
-	                             $link = '', $pubdate = 0, $is_read = false, $is_favorite = false) {
+	                             $link = '', $pubdate = 0, $is_read = false, $is_favorite = false,
+	                             $is_public = false) {
 		$this->_guid ($guid);
 		$this->_title ($title);
 		$this->_author ($author);
@@ -23,7 +28,11 @@ class Entry extends Model {
 		$this->_date ($pubdate);
 		$this->_isRead ($is_read);
 		$this->_isFavorite ($is_favorite);
+		$this->_isPublic ($is_public);
 		$this->_feed ($feed);
+		$this->_lastUpdate ($pubdate);
+		$this->_notes ('');
+		$this->_tags (array ());
 	}
 
 	public function id () {
@@ -61,6 +70,9 @@ class Entry extends Model {
 	public function isFavorite () {
 		return $this->is_favorite;
 	}
+	public function isPublic () {
+		return $this->is_public;
+	}
 	public function feed ($object = false) {
 		if ($object) {
 			$feedDAO = new FeedDAO ();
@@ -69,6 +81,35 @@ class Entry extends Model {
 			return $this->feed;
 		}
 	}
+	public function tags ($inString = false) {
+		if ($inString) {
+			if (!empty ($this->tags)) {
+				return '#' . implode(' #', $this->tags);
+			} else {
+				return '';
+			}
+		} else {
+			return $this->tags;
+		}
+	}
+	public function notes ($raw = true, $parse_tags = true) {
+		if ($raw) {
+			return $this->notes;
+		} else {
+			if($parse_tags) {
+				return parse_tags (bbdecode ($this->notes));
+			} else {
+				return bbdecode ($this->notes);
+			}
+		}
+	}
+	public function lastUpdate ($raw = false) {
+		if ($raw) {
+			return $this->lastUpdate;
+		} else {
+			return timestamptodate ($this->lastUpdate);
+		}
+	}
 
 	public function _id ($value) {
 		$this->id = $value;
@@ -89,7 +130,11 @@ class Entry extends Model {
 		$this->link = $value;
 	}
 	public function _date ($value) {
-		$this->date = $value;
+		if (is_int (intval ($value))) {
+			$this->date = $value;
+		} else {
+			$this->date = time ();
+		}
 	}
 	public function _isRead ($value) {
 		$this->is_read = $value;
@@ -97,9 +142,35 @@ class Entry extends Model {
 	public function _isFavorite ($value) {
 		$this->is_favorite = $value;
 	}
+	public function _isPublic ($value) {
+		$this->is_public = $value;
+	}
 	public function _feed ($value) {
 		$this->feed = $value;
 	}
+	public function _tags ($value) {
+		if (!is_array ($value)) {
+			$value = array ($value);
+		}
+
+		foreach ($value as $key => $t) {
+			if (!$t) {
+				unset ($value[$key]);
+			}
+		}
+
+		$this->tags = $value;
+	}
+	public function _notes ($value) {
+		$this->notes = $value;
+	}
+	public function _lastUpdate ($value) {
+		if (is_int (intval ($value))) {
+			$this->lastUpdate = $value;
+		} else {
+			$this->lastUpdate = $this->date (true);
+		}
+	}
 
 	public function isDay ($day) {
 		$date = getdate ();
@@ -118,11 +189,30 @@ class Entry extends Model {
 			return false;
 		}
 	}
+
+	public function toArray () {
+		return array (
+			'id' => $this->id (),
+			'guid' => $this->guid (),
+			'title' => $this->title (),
+			'author' => $this->author (),
+			'content' => $this->content (),
+			'link' => $this->link (),
+			'date' => $this->date (true),
+			'is_read' => $this->isRead (),
+			'is_favorite' => $this->isFavorite (),
+			'is_public' => $this->isPublic (),
+			'id_feed' => $this->feed (),
+			'lastUpdate' => $this->lastUpdate (true),
+			'tags' => $this->tags (true),
+			'annotation' => $this->notes ()
+		);
+	}
 }
 
 class EntryDAO extends Model_pdo {
 	public function addEntry ($valuesTmp) {
-		$sql = 'INSERT INTO entry (id, guid, title, author, content, link, date, is_read, is_favorite, id_feed) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
+		$sql = 'INSERT INTO entry(id, guid, title, author, content, link, date, is_read, is_favorite, is_public, id_feed, lastUpdate) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
 		$stm = $this->bd->prepare ($sql);
 
 		$values = array (
@@ -135,7 +225,9 @@ class EntryDAO extends Model_pdo {
 			$valuesTmp['date'],
 			$valuesTmp['is_read'],
 			$valuesTmp['is_favorite'],
+			$valuesTmp['is_public'],
 			$valuesTmp['id_feed'],
+			$valuesTmp['lastUpdate'],
 		);
 
 		if ($stm && $stm->execute ($values)) {
@@ -235,7 +327,7 @@ 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';
+		$sql = 'DELETE FROM entry WHERE date <= ? AND is_favorite = 0 AND notes != ""';
 		$stm = $this->bd->prepare ($sql);
 
 		$values = array (
@@ -531,9 +623,15 @@ class HelperEntry {
 				$dao['link'],
 				$dao['date'],
 				$dao['is_read'],
-				$dao['is_favorite']
+				$dao['is_favorite'],
+				$dao['is_public']
 			);
 
+			$tags = preg_split('/[\s#]/', $dao['tags']);
+			$list[$key]->_notes ($dao['annotation']);
+			$list[$key]->_lastUpdate ($dao['lastUpdate']);
+			$list[$key]->_tags ($tags);
+
 			if (isset ($dao['id'])) {
 				$list[$key]->_id ($dao['id']);
 			}

+ 3 - 1
freshrss.sql

@@ -3,7 +3,7 @@
 -- http://www.phpmyadmin.net
 --
 -- Client: localhost
--- Généré le: Dim 17 Mars 2013 à 14:08
+-- Généré le: Dim 17 Mars 2013 à 15:21
 -- Version du serveur: 5.5.30
 -- Version de PHP: 5.4.12
 
@@ -49,9 +49,11 @@ CREATE TABLE IF NOT EXISTS `entry` (
   `date` int(11) NOT NULL,
   `is_read` int(11) NOT NULL,
   `is_favorite` int(11) NOT NULL,
+  `is_public` int(1) NOT NULL,
   `id_feed` varchar(6) NOT NULL,
   `annotation` text NOT NULL,
   `tags` text NOT NULL,
+  `lastUpdate` int(11) NOT NULL,
   PRIMARY KEY (`id`),
   KEY `id_feed` (`id_feed`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;