Category.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. class FreshRSS_Category extends Minz_Model {
  3. private $id = 0;
  4. private $name;
  5. private $nbFeed = -1;
  6. private $nbNotRead = -1;
  7. private $feeds = null;
  8. private $hasFeedsWithError = false;
  9. public function __construct($name = '', $feeds = null) {
  10. $this->_name($name);
  11. if (isset($feeds)) {
  12. $this->_feeds($feeds);
  13. $this->nbFeed = 0;
  14. $this->nbNotRead = 0;
  15. foreach ($feeds as $feed) {
  16. $this->nbFeed++;
  17. $this->nbNotRead += $feed->nbNotRead();
  18. $this->hasFeedsWithError |= $feed->inError();
  19. }
  20. }
  21. }
  22. public function id() {
  23. return $this->id;
  24. }
  25. public function name() {
  26. return $this->name;
  27. }
  28. public function nbFeed() {
  29. if ($this->nbFeed < 0) {
  30. $catDAO = new FreshRSS_CategoryDAO();
  31. $this->nbFeed = $catDAO->countFeed($this->id());
  32. }
  33. return $this->nbFeed;
  34. }
  35. public function nbNotRead() {
  36. if ($this->nbNotRead < 0) {
  37. $catDAO = new FreshRSS_CategoryDAO();
  38. $this->nbNotRead = $catDAO->countNotRead($this->id());
  39. }
  40. return $this->nbNotRead;
  41. }
  42. public function feeds() {
  43. if ($this->feeds === null) {
  44. $feedDAO = FreshRSS_Factory::createFeedDao();
  45. $this->feeds = $feedDAO->listByCategory($this->id());
  46. $this->nbFeed = 0;
  47. $this->nbNotRead = 0;
  48. foreach ($this->feeds as $feed) {
  49. $this->nbFeed++;
  50. $this->nbNotRead += $feed->nbNotRead();
  51. $this->hasFeedsWithError |= $feed->inError();
  52. }
  53. }
  54. return $this->feeds;
  55. }
  56. public function hasFeedsWithError() {
  57. return $this->hasFeedsWithError;
  58. }
  59. public function _id($value) {
  60. $this->id = $value;
  61. }
  62. public function _name($value) {
  63. $this->name = substr(trim($value), 0, 255);
  64. }
  65. public function _feeds($values) {
  66. if (!is_array($values)) {
  67. $values = array($values);
  68. }
  69. $this->feeds = $values;
  70. }
  71. }