Tag.php 1.5 KB

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