aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-03-30 19:17:27 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-03-30 19:17:27 +0200
commit5f974c2567091412f4e98cad2a31e882e14cac9b (patch)
tree0561137e90c9d03d4e318ea8847dd82444d9b9f4 /app/Models
parent19517baf13dba7ebd7d41dbbacceaea3ed75af8e (diff)
parent34b17b748efb996f0202815dcf095a45d28e38da (diff)
Merge branch '163-export' into dev
Conflicts: app/layout/aside_feed.phtml
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/CategoryDAO.php13
-rw-r--r--app/Models/EntryDAO.php30
-rw-r--r--app/Models/FeedDAO.php30
3 files changed, 73 insertions, 0 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index f3c02e3e4..6a9b839b9 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -18,6 +18,19 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo {
}
}
+ public function addCategoryObject($category) {
+ $cat = $this->searchByName($category->name());
+ if (!$cat) {
+ // Category does not exist yet in DB so we add it before continue
+ $values = array(
+ 'name' => $category->name(),
+ );
+ return $this->addCategory($values);
+ }
+
+ return $cat->id();
+ }
+
public function updateCategory ($id, $valuesTmp) {
$sql = 'UPDATE `' . $this->prefix . 'category` SET name=? WHERE id=?';
$stm = $this->bd->prepare ($sql);
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index e4cf128ea..6d00967fc 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -35,6 +35,36 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo {
}
}
+ public function addEntryObject($entry, $conf, $feedHistory) {
+ $existingGuids = array_fill_keys(
+ $this->listLastGuidsByFeed($entry->feed(), 20), 1
+ );
+
+ $nb_month_old = max($conf->old_entries, 1);
+ $date_min = time() - (3600 * 24 * 30 * $nb_month_old);
+
+ $eDate = $entry->date(true);
+
+ if ($feedHistory == -2) {
+ $feedHistory = $conf->keep_history_default;
+ }
+
+ if (!isset($existingGuids[$entry->guid()]) &&
+ ($feedHistory != 0 || $eDate >= $date_min)) {
+ $values = $entry->toArray();
+
+ $useDeclaredDate = empty($existingGuids);
+ $values['id'] = ($useDeclaredDate || $eDate < $date_min) ?
+ min(time(), $eDate) . uSecString() :
+ uTimeString();
+
+ return $this->addEntry($values);
+ }
+
+ // We don't return Entry object to avoid a research in DB
+ return -1;
+ }
+
public function markFavorite($ids, $is_favorite = true) {
if (!is_array($ids)) {
$ids = array($ids);
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index ca25c3aeb..b65ff4af0 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -24,6 +24,36 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo {
}
}
+ public function addFeedObject($feed) {
+ // TODO: not sure if we should write this method in DAO since DAO
+ // should not be aware about feed class
+
+ // Add feed only if we don't find it in DB
+ $feed_search = $this->searchByUrl($feed->url());
+ if (!$feed_search) {
+ $values = array(
+ 'id' => $feed->id(),
+ 'url' => $feed->url(),
+ 'category' => $feed->category(),
+ 'name' => $feed->name(),
+ 'website' => $feed->website(),
+ 'description' => $feed->description(),
+ 'lastUpdate' => 0,
+ 'httpAuth' => $feed->httpAuth()
+ );
+
+ $id = $this->addFeed($values);
+ if ($id) {
+ $feed->_id($id);
+ $feed->faviconPrepare();
+ }
+
+ return $id;
+ }
+
+ return $feed_search->id();
+ }
+
public function updateFeed ($id, $valuesTmp) {
$set = '';
foreach ($valuesTmp as $key => $v) {