Tag.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class FreshRSS_Tag extends Minz_Model {
  3. private $id = 0;
  4. private $name;
  5. private $attributes = [];
  6. private $nbEntries = -1;
  7. private $nbUnread = -1;
  8. public function __construct($name = '') {
  9. $this->_name($name);
  10. }
  11. public function id() {
  12. return $this->id;
  13. }
  14. public function _id($value) {
  15. $this->id = (int)$value;
  16. }
  17. public function name() {
  18. return $this->name;
  19. }
  20. public function _name($value) {
  21. $this->name = trim($value);
  22. }
  23. public function attributes($key = '') {
  24. if ($key == '') {
  25. return $this->attributes;
  26. } else {
  27. return isset($this->attributes[$key]) ? $this->attributes[$key] : null;
  28. }
  29. }
  30. public function _attributes($key, $value) {
  31. if ($key == '') {
  32. if (is_string($value)) {
  33. $value = json_decode($value, true);
  34. }
  35. if (is_array($value)) {
  36. $this->attributes = $value;
  37. }
  38. } elseif ($value === null) {
  39. unset($this->attributes[$key]);
  40. } else {
  41. $this->attributes[$key] = $value;
  42. }
  43. }
  44. public function nbEntries() {
  45. if ($this->nbEntries < 0) {
  46. $tagDAO = FreshRSS_Factory::createTagDao();
  47. $this->nbEntries = $tagDAO->countEntries($this->id());
  48. }
  49. return $this->nbFeed;
  50. }
  51. public function _nbEntries($value) {
  52. $this->nbEntries = (int)$value;
  53. }
  54. public function nbUnread() {
  55. if ($this->nbUnread < 0) {
  56. $tagDAO = FreshRSS_Factory::createTagDao();
  57. $this->nbUnread = $tagDAO->countNotRead($this->id());
  58. }
  59. return $this->nbUnread;
  60. }
  61. public function _nbUnread($value) {
  62. $this->nbUnread = (int)$value;
  63. }
  64. }