summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-22 18:00:13 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2012-10-22 18:00:13 +0200
commit0426541acbeb44d240e6dbf7a93f3a104bea61b4 (patch)
tree209a425c5afee9e627d11023b262326812be1fbc /app/models
parentfb57be5a5af3a2fb46b2dbf2b503ffe78eb5cf49 (diff)
Grosse màj : ajout de la configuration + ajouts divers fonctionnalités
Diffstat (limited to 'app/models')
-rwxr-xr-xapp/models/Category.php113
-rwxr-xr-xapp/models/Entry.php16
-rw-r--r--app/models/Feed.php126
-rwxr-xr-xapp/models/RSSConfiguration.php16
4 files changed, 226 insertions, 45 deletions
diff --git a/app/models/Category.php b/app/models/Category.php
new file mode 100755
index 000000000..5b5d45b15
--- /dev/null
+++ b/app/models/Category.php
@@ -0,0 +1,113 @@
+<?php
+
+class Category extends Model {
+ private $id;
+ private $name;
+ private $color;
+
+ public function __construct ($name = '', $color = '#0062BE') {
+ $this->_name ($name);
+ $this->_color ($color);
+ }
+
+ public function id () {
+ return small_hash ($this->name . Configuration::selApplication ());
+ }
+ public function name () {
+ return $this->name;
+ }
+ public function color () {
+ return $this->color;
+ }
+
+ public function _name ($value) {
+ $this->name = $value;
+ }
+ public function _color ($value) {
+ if (preg_match ('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
+ $this->color = $value;
+ } else {
+ $this->color = '#0062BE';
+ }
+ }
+}
+
+class CategoryDAO extends Model_array {
+ public function __construct () {
+ parent::__construct (PUBLIC_PATH . '/data/db/Categories.array.php');
+ }
+
+ public function addCategory ($values) {
+ $id = $values['id'];
+ unset ($values['id']);
+
+ if (!isset ($this->array[$id])) {
+ $this->array[$id] = array ();
+
+ foreach ($values as $key => $value) {
+ $this->array[$id][$key] = $value;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public function updateCategory ($id, $values) {
+ foreach ($values as $key => $value) {
+ $this->array[$id][$key] = $value;
+ }
+ }
+
+ public function deleteCategory ($id) {
+ if (isset ($this->array[$id])) {
+ unset ($this->array[$id]);
+ }
+ }
+
+ public function searchById ($id) {
+ $list = HelperCategory::daoToCategory ($this->array);
+
+ if (isset ($list[$id])) {
+ return $list[$id];
+ } else {
+ return false;
+ }
+ }
+
+ public function listCategories () {
+ $list = $this->array;
+
+ if (!is_array ($list)) {
+ $list = array ();
+ }
+
+ return HelperCategory::daoToCategory ($list);
+ }
+
+ public function count () {
+ return count ($this->array);
+ }
+
+ public function save () {
+ $this->writeFile ($this->array);
+ }
+}
+
+class HelperCategory {
+ public static function daoToCategory ($listDAO) {
+ $list = array ();
+
+ if (!is_array ($listDAO)) {
+ $listDAO = array ($listDAO);
+ }
+
+ foreach ($listDAO as $key => $dao) {
+ $list[$key] = new Category (
+ $dao['name'],
+ $dao['color']
+ );
+ }
+
+ return $list;
+ }
+}
diff --git a/app/models/Entry.php b/app/models/Entry.php
index 85e04cb4e..67d255c55 100755
--- a/app/models/Entry.php
+++ b/app/models/Entry.php
@@ -9,8 +9,9 @@ class Entry extends Model {
private $date;
private $is_read;
private $is_favorite;
+ private $feed;
- public function __construct ($guid = '', $title = '', $author = '', $content = '',
+ public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '',
$link = '', $pubdate = 0, $is_read = false, $is_favorite = false) {
$this->_guid ($guid);
$this->_title ($title);
@@ -20,6 +21,7 @@ class Entry extends Model {
$this->_date ($pubdate);
$this->_isRead ($is_read);
$this->_isFavorite ($is_favorite);
+ $this->_feed ($feed);
}
public function id () {
@@ -53,6 +55,14 @@ class Entry extends Model {
public function isFavorite () {
return $this->is_favorite;
}
+ public function feed ($object = false) {
+ if ($object) {
+ $feedDAO = new FeedDAO ();
+ return $feedDAO->searchById ($this->feed);
+ } else {
+ return $this->feed;
+ }
+ }
public function _guid ($value) {
$this->guid = $value;
@@ -78,6 +88,9 @@ class Entry extends Model {
public function _isFavorite ($value) {
$this->is_favorite = $value;
}
+ public function _feed ($value) {
+ $this->feed = $value;
+ }
}
class EntryDAO extends Model_array {
@@ -162,6 +175,7 @@ class HelperEntry {
foreach ($listDAO as $key => $dao) {
$list[$key] = new Entry (
+ $dao['feed'],
$dao['guid'],
$dao['title'],
$dao['author'],
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 583a7fef5..57696f64d 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -2,13 +2,15 @@
class Feed extends Model {
private $url;
- private $categories;
- private $entries_list;
+ private $category = '';
+ private $entries_list = array ();
+ private $entries = null;
+ private $name = '';
+ private $website = '';
+ private $description = '';
- public function __construct ($url = null) {
+ public function __construct ($url) {
$this->_url ($url);
- $this->_categories (array ());
- $this->_entries (array ());
}
public function id () {
@@ -17,11 +19,26 @@ class Feed extends Model {
public function url () {
return $this->url;
}
- public function categories () {
- return $this->categories;
+ public function category () {
+ return $this->category;
}
- public function entries () {
- return $this->entries_list;
+ public function entries ($list = true) {
+ if ($list) {
+ return $this->entries_list;
+ } elseif (!is_null ($this->entries)) {
+ return $this->entries;
+ } else {
+ return false;
+ }
+ }
+ public function name () {
+ return $this->name;
+ }
+ public function website () {
+ return $this->website;
+ }
+ public function description () {
+ return $this->description;
}
public function _url ($value) {
@@ -31,12 +48,8 @@ class Feed extends Model {
throw new Exception ();
}
}
- public function _categories ($value) {
- if (!is_array ($value)) {
- $value = array ($value);
- }
-
- $this->categories = $value;
+ public function _category ($value) {
+ $this->category = $value;
}
public function _entries ($value) {
if (!is_array ($value)) {
@@ -45,42 +58,54 @@ class Feed extends Model {
$this->entries_list = $value;
}
+ public function _name ($value) {
+ $this->name = $value;
+ }
+ public function _website ($value) {
+ $this->website = $value;
+ }
+ public function _description ($value) {
+ $this->description = $value;
+ }
- public function loadEntries () {
+ public function load () {
if (!is_null ($this->url)) {
$feed = new SimplePie ();
$feed->set_feed_url ($this->url);
$feed->set_cache_location (CACHE_PATH);
$feed->init ();
- $entries = array ();
- if ($feed->data) {
- foreach ($feed->get_items () as $item) {
- $title = $item->get_title ();
- $author = $item->get_author ();
- $content = $item->get_content ();
- $link = $item->get_permalink ();
- $date = strtotime ($item->get_date ());
-
- $entry = new Entry (
- $item->get_id (),
- !is_null ($title) ? $title : '',
- !is_null ($author) ? $author->name : '',
- !is_null ($content) ? $content : '',
- !is_null ($link) ? $link : '',
- $date ? $date : time ()
- );
-
- $entries[$entry->id ()] = $entry;
- }
-
- return $entries;
- } else {
- return false;
- }
- } else {
- return false;
+ $title = $feed->get_title ();
+ $this->loadEntries ($feed);
+ $this->_name (!is_null ($title) ? $title : $this->url);
+ $this->_website ($feed->get_link ());
+ $this->_description ($feed->get_description ());
+ }
+ }
+ private function loadEntries ($feed) {
+ $entries = array ();
+
+ foreach ($feed->get_items () as $item) {
+ $title = $item->get_title ();
+ $author = $item->get_author ();
+ $content = $item->get_content ();
+ $link = $item->get_permalink ();
+ $date = strtotime ($item->get_date ());
+
+ $entry = new Entry (
+ $this->id (),
+ $item->get_id (),
+ !is_null ($title) ? $title : '',
+ !is_null ($author) ? $author->name : '',
+ !is_null ($content) ? $content : '',
+ !is_null ($link) ? $link : '',
+ $date ? $date : time ()
+ );
+
+ $entries[$entry->id ()] = $entry;
}
+
+ $this->entries = $entries;
}
}
@@ -114,6 +139,16 @@ class FeedDAO extends Model_array {
$this->writeFile($this->array);
}
+ public function searchById ($id) {
+ $list = HelperFeed::daoToFeed ($this->array);
+
+ if (isset ($list[$id])) {
+ return $list[$id];
+ } else {
+ return false;
+ }
+ }
+
public function listFeeds () {
$list = $this->array;
@@ -139,8 +174,11 @@ class HelperFeed {
foreach ($listDAO as $key => $dao) {
$list[$key] = new Feed ($dao['url']);
- $list[$key]->_categories ($dao['categories']);
+ $list[$key]->_category ($dao['category']);
$list[$key]->_entries ($dao['entries']);
+ $list[$key]->_name ($dao['name']);
+ $list[$key]->_website ($dao['website']);
+ $list[$key]->_description ($dao['description']);
}
return $list;
diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php
index f42f1283c..da5028da3 100755
--- a/app/models/RSSConfiguration.php
+++ b/app/models/RSSConfiguration.php
@@ -4,12 +4,14 @@ class RSSConfiguration extends Model {
private $posts_per_page;
private $default_view;
private $display_posts;
+ private $sort_order;
public function __construct () {
$confDAO = new RSSConfigurationDAO ();
$this->_postsPerPage ($confDAO->posts_per_page);
$this->_defaultView ($confDAO->default_view);
$this->_displayPosts ($confDAO->display_posts);
+ $this->_sortOrder ($confDAO->sort_order);
}
public function postsPerPage () {
@@ -21,6 +23,9 @@ class RSSConfiguration extends Model {
public function displayPosts () {
return $this->display_posts;
}
+ public function sortOrder () {
+ return $this->sort_order;
+ }
public function _postsPerPage ($value) {
if (is_int ($value)) {
@@ -43,12 +48,20 @@ class RSSConfiguration extends Model {
$this->display_posts = 'no';
}
}
+ public function _sortOrder ($value) {
+ if ($value == 'high_to_low') {
+ $this->sort_order = 'high_to_low';
+ } else {
+ $this->sort_order = 'low_to_high';
+ }
+ }
}
class RSSConfigurationDAO extends Model_array {
public $posts_per_page = 10;
public $default_view = 'all';
public $display_posts = 'no';
+ public $sort_order = 'low_to_high';
public function __construct () {
parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php');
@@ -62,6 +75,9 @@ class RSSConfigurationDAO extends Model_array {
if (isset ($this->array['display_posts'])) {
$this->display_posts = $this->array['display_posts'];
}
+ if (isset ($this->array['sort_order'])) {
+ $this->sort_order = $this->array['sort_order'];
+ }
}
public function save ($values) {