From 4ee4f16ffe06e247d2cb79a2054ab5d5315d82b2 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 15 Dec 2013 11:24:14 +0100 Subject: Problème de casse renommage répertoire MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Category.php | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 app/Models/Category.php (limited to 'app/Models/Category.php') diff --git a/app/Models/Category.php b/app/Models/Category.php new file mode 100644 index 000000000..e70d1303f --- /dev/null +++ b/app/Models/Category.php @@ -0,0 +1,85 @@ +_name ($name); + $this->_color ($color); + if (isset ($feeds)) { + $this->_feeds ($feeds); + $this->nbFeed = 0; + $this->nbNotRead = 0; + foreach ($feeds as $feed) { + $this->nbFeed++; + $this->nbNotRead += $feed->nbNotRead (); + } + } + } + + public function id () { + return $this->id; + } + public function name () { + return $this->name; + } + public function color () { + return $this->color; + } + public function nbFeed () { + if ($this->nbFeed < 0) { + $catDAO = new FreshRSS_CategoryDAO (); + $this->nbFeed = $catDAO->countFeed ($this->id ()); + } + + return $this->nbFeed; + } + public function nbNotRead () { + if ($this->nbNotRead < 0) { + $catDAO = new FreshRSS_CategoryDAO (); + $this->nbNotRead = $catDAO->countNotRead ($this->id ()); + } + + return $this->nbNotRead; + } + public function feeds () { + if (is_null ($this->feeds)) { + $feedDAO = new FreshRSS_FeedDAO (); + $this->feeds = $feedDAO->listByCategory ($this->id ()); + $this->nbFeed = 0; + $this->nbNotRead = 0; + foreach ($this->feeds as $feed) { + $this->nbFeed++; + $this->nbNotRead += $feed->nbNotRead (); + } + } + + return $this->feeds; + } + + public function _id ($value) { + $this->id = $value; + } + 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'; + } + } + public function _feeds ($values) { + if (!is_array ($values)) { + $values = array ($values); + } + + $this->feeds = $values; + } +} -- cgit v1.2.3 From 4d6ab45b03031e1c13ac2d3589364a43a0fe5578 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 30 Dec 2013 12:43:39 +0100 Subject: Micro-optimisation : évite is_null et quelques if/else MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contribue à https://github.com/marienfressinaud/FreshRSS/issues/303 --- app/Models/Category.php | 2 +- app/Models/Entry.php | 6 +----- app/Models/Feed.php | 32 +++++++++++--------------------- lib/Minz/Dispatcher.php | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) (limited to 'app/Models/Category.php') diff --git a/app/Models/Category.php b/app/Models/Category.php index e70d1303f..8e1e44ef8 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -48,7 +48,7 @@ class FreshRSS_Category extends Minz_Model { return $this->nbNotRead; } public function feeds () { - if (is_null ($this->feeds)) { + if ($this->feeds === null) { $feedDAO = new FreshRSS_FeedDAO (); $this->feeds = $feedDAO->listByCategory ($this->id ()); $this->nbFeed = 0; diff --git a/app/Models/Entry.php b/app/Models/Entry.php index ab9605eb1..83f68ce78 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -38,11 +38,7 @@ class FreshRSS_Entry extends Minz_Model { return $this->title; } public function author () { - if (is_null ($this->author)) { - return ''; - } else { - return $this->author; - } + return $this->author === null ? '' : $this->author; } public function content () { return $this->content; diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 32f8546dd..f38828a42 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -44,11 +44,7 @@ class FreshRSS_Feed extends Minz_Model { return $this->category; } public function entries () { - if (!is_null ($this->entries)) { - return $this->entries; - } else { - return array (); - } + return $this->entries === null ? array() : $this->entries; } public function name () { return $this->name; @@ -140,10 +136,7 @@ class FreshRSS_Feed extends Minz_Model { $this->category = $value >= 0 ? $value : 0; } public function _name ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->name = $value; + $this->name = $value === null ? '' : $value; } public function _website ($value, $validate=true) { if ($validate) { @@ -155,10 +148,7 @@ class FreshRSS_Feed extends Minz_Model { $this->website = $value; } public function _description ($value) { - if (is_null ($value)) { - $value = ''; - } - $this->description = $value; + $this->description = $value === null ? '' : $value; } public function _lastUpdate ($value) { $this->lastUpdate = $value; @@ -190,7 +180,7 @@ class FreshRSS_Feed extends Minz_Model { } public function load ($loadDetails = false) { - if (!is_null ($this->url)) { + if ($this->url !== null) { if (CACHE_PATH === false) { throw new Minz_FileNotExistException ( 'CACHE_PATH', @@ -253,7 +243,7 @@ class FreshRSS_Feed extends Minz_Model { // si on a utilisé l'auto-discover, notre url va avoir changé $subscribe_url = $feed->subscribe_url (); - if (!is_null ($subscribe_url) && $subscribe_url != $this->url) { + if ($subscribe_url !== null && $subscribe_url !== $this->url) { if ($this->httpAuth != '') { // on enlève les id si authentification HTTP $subscribe_url = preg_replace ('#((.+)://)((.+)@)(.+)#', '${1}${5}', $subscribe_url); @@ -263,7 +253,7 @@ class FreshRSS_Feed extends Minz_Model { if ($loadDetails) { $title = htmlspecialchars(html_only_entity_decode($feed->get_title()), ENT_COMPAT, 'UTF-8'); - $this->_name (!is_null ($title) ? $title : $this->url); + $this->_name ($title === null ? $this->url : $title); $this->_website(html_only_entity_decode($feed->get_link())); $this->_description(html_only_entity_decode($feed->get_description())); @@ -286,7 +276,7 @@ class FreshRSS_Feed extends Minz_Model { // gestion des tags (catégorie == tag) $tags_tmp = $item->get_categories (); $tags = array (); - if (!is_null ($tags_tmp)) { + if ($tags_tmp !== null) { foreach ($tags_tmp as $tag) { $tags[] = html_only_entity_decode ($tag->get_label ()); } @@ -308,10 +298,10 @@ class FreshRSS_Feed extends Minz_Model { $entry = new FreshRSS_Entry ( $this->id (), $item->get_id (), - !is_null ($title) ? $title : '', - !is_null ($author) ? html_only_entity_decode ($author->name) : '', - !is_null ($content) ? $content : '', - !is_null ($link) ? $link : '', + $title === null ? '' : $title, + $author === null ? '' : html_only_entity_decode ($author->name), + $content === null ? '' : $content, + $link === null ? '' : $link, $date ? $date : time () ); $entry->_tags ($tags); diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php index 2898b5f00..c2c5e7f65 100644 --- a/lib/Minz/Dispatcher.php +++ b/lib/Minz/Dispatcher.php @@ -22,7 +22,7 @@ class Minz_Dispatcher { * Récupère l'instance du Dispatcher */ public static function getInstance ($router) { - if (is_null (self::$instance)) { + if (self::$instance === null) { self::$instance = new Minz_Dispatcher ($router); } return self::$instance; -- cgit v1.2.3