Tag.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_Tag extends Minz_Model {
  4. use FreshRSS_AttributesTrait, FreshRSS_FilterActionsTrait;
  5. private int $id = 0;
  6. private string $name;
  7. private int $nbEntries = -1;
  8. private int $nbUnread = -1;
  9. public function __construct(string $name = '') {
  10. $this->_name($name);
  11. }
  12. public function id(): int {
  13. return $this->id;
  14. }
  15. /**
  16. * @param int|string $value
  17. */
  18. public function _id($value): void {
  19. $this->id = (int)$value;
  20. }
  21. public function name(): string {
  22. return $this->name;
  23. }
  24. public function _name(string $value): void {
  25. $this->name = trim($value);
  26. }
  27. public function nbEntries(): int {
  28. if ($this->nbEntries < 0) {
  29. $tagDAO = FreshRSS_Factory::createTagDao();
  30. $this->nbEntries = $tagDAO->countEntries($this->id()) ?: 0;
  31. }
  32. return $this->nbEntries;
  33. }
  34. /**
  35. * @param string|int $value
  36. */
  37. public function _nbEntries($value): void {
  38. $this->nbEntries = (int)$value;
  39. }
  40. public function nbUnread(): int {
  41. if ($this->nbUnread < 0) {
  42. $tagDAO = FreshRSS_Factory::createTagDao();
  43. $this->nbUnread = $tagDAO->countNotRead($this->id()) ?: 0;
  44. }
  45. return $this->nbUnread;
  46. }
  47. /**
  48. * @param string|int $value
  49. */
  50. public function _nbUnread($value): void {
  51. $this->nbUnread = (int)$value;
  52. }
  53. }