aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Tag.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-10-28 09:49:10 +0100
committerGravatar GitHub <noreply@github.com> 2018-10-28 09:49:10 +0100
commite04804d0f67dd43fd3f072b9a127768ee7b7b56c (patch)
treea49023ed25aab7fb1c1aafe749f7d462de0027b2 /app/Models/Tag.php
parent44bd07e506ade204151c276fdc05994d51efdd7a (diff)
parent4234dfe0d72b61fe931d2c76a1d8a335ce65a209 (diff)
Merge pull request #2049 from FreshRSS/dev1.12.0
FreshRSS 1.12.0
Diffstat (limited to 'app/Models/Tag.php')
-rw-r--r--app/Models/Tag.php76
1 files changed, 76 insertions, 0 deletions
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
new file mode 100644
index 000000000..3eb989cc1
--- /dev/null
+++ b/app/Models/Tag.php
@@ -0,0 +1,76 @@
+<?php
+
+class FreshRSS_Tag extends Minz_Model {
+ private $id = 0;
+ private $name;
+ private $attributes = array();
+ private $nbEntries = -1;
+ private $nbUnread = -1;
+
+ public function __construct($name = '') {
+ $this->_name($name);
+ }
+
+ public function id() {
+ return $this->id;
+ }
+
+ public function _id($value) {
+ $this->id = (int)$value;
+ }
+
+ public function name() {
+ return $this->name;
+ }
+
+ public function _name($value) {
+ $this->name = trim($value);
+ }
+
+ public function attributes($key = '') {
+ if ($key == '') {
+ return $this->attributes;
+ } else {
+ return isset($this->attributes[$key]) ? $this->attributes[$key] : null;
+ }
+ }
+
+ public function _attributes($key, $value) {
+ if ($key == '') {
+ if (is_string($value)) {
+ $value = json_decode($value, true);
+ }
+ if (is_array($value)) {
+ $this->attributes = $value;
+ }
+ } elseif ($value === null) {
+ unset($this->attributes[$key]);
+ } else {
+ $this->attributes[$key] = $value;
+ }
+ }
+
+ public function nbEntries() {
+ if ($this->nbEntries < 0) {
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ $this->nbEntries = $tagDAO->countEntries($this->id());
+ }
+ return $this->nbFeed;
+ }
+
+ public function _nbEntries($value) {
+ $this->nbEntries = (int)$value;
+ }
+
+ public function nbUnread() {
+ if ($this->nbUnread < 0) {
+ $tagDAO = FreshRSS_Factory::createTagDao();
+ $this->nbUnread = $tagDAO->countNotRead($this->id());
+ }
+ return $this->nbUnread;
+ }
+
+ public function _nbUnread($value) {
+ $this->nbUnread = (int)$value;
+ }
+}