Tag.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. public function _id(int $value): void {
  16. $this->id = $value;
  17. }
  18. public function name(): string {
  19. return $this->name;
  20. }
  21. public function _name(string $value): void {
  22. $this->name = trim($value);
  23. }
  24. public function nbEntries(): int {
  25. if ($this->nbEntries < 0) {
  26. $tagDAO = FreshRSS_Factory::createTagDao();
  27. $this->nbEntries = $tagDAO->countEntries($this->id()) ?: 0;
  28. }
  29. return $this->nbEntries;
  30. }
  31. public function _nbEntries(int $value): void {
  32. $this->nbEntries = $value;
  33. }
  34. public function nbUnread(): int {
  35. if ($this->nbUnread < 0) {
  36. $tagDAO = FreshRSS_Factory::createTagDao();
  37. $this->nbUnread = $tagDAO->countNotRead($this->id()) ?: 0;
  38. }
  39. return $this->nbUnread;
  40. }
  41. /** @param int|numeric-string $value */
  42. public function _nbUnread(int|string $value): void {
  43. $this->nbUnread = (int)$value;
  44. }
  45. }