Category.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. private $isDefault = false;
  10. public function __construct($name = '', $feeds = null) {
  11. $this->_name($name);
  12. if (isset($feeds)) {
  13. $this->_feeds($feeds);
  14. $this->nbFeed = 0;
  15. $this->nbNotRead = 0;
  16. foreach ($feeds as $feed) {
  17. $this->nbFeed++;
  18. $this->nbNotRead += $feed->nbNotRead();
  19. $this->hasFeedsWithError |= $feed->inError();
  20. }
  21. }
  22. }
  23. public function id() {
  24. return $this->id;
  25. }
  26. public function name() {
  27. return $this->name;
  28. }
  29. public function isDefault() {
  30. return $this->isDefault;
  31. }
  32. public function nbFeed() {
  33. if ($this->nbFeed < 0) {
  34. $catDAO = FreshRSS_Factory::createCategoryDao();
  35. $this->nbFeed = $catDAO->countFeed($this->id());
  36. }
  37. return $this->nbFeed;
  38. }
  39. public function nbNotRead() {
  40. if ($this->nbNotRead < 0) {
  41. $catDAO = FreshRSS_Factory::createCategoryDao();
  42. $this->nbNotRead = $catDAO->countNotRead($this->id());
  43. }
  44. return $this->nbNotRead;
  45. }
  46. public function feeds() {
  47. if ($this->feeds === null) {
  48. $feedDAO = FreshRSS_Factory::createFeedDao();
  49. $this->feeds = $feedDAO->listByCategory($this->id());
  50. $this->nbFeed = 0;
  51. $this->nbNotRead = 0;
  52. foreach ($this->feeds as $feed) {
  53. $this->nbFeed++;
  54. $this->nbNotRead += $feed->nbNotRead();
  55. $this->hasFeedsWithError |= $feed->inError();
  56. }
  57. }
  58. return $this->feeds;
  59. }
  60. public function hasFeedsWithError() {
  61. return $this->hasFeedsWithError;
  62. }
  63. public function _id($id) {
  64. $this->id = $id;
  65. if ($id == FreshRSS_CategoryDAO::DEFAULTCATEGORYID) {
  66. $this->_name(_t('gen.short.default_category'));
  67. }
  68. }
  69. public function _name($value) {
  70. $this->name = trim($value);
  71. }
  72. public function _isDefault($value) {
  73. $this->isDefault = $value;
  74. }
  75. public function _feeds($values) {
  76. if (!is_array($values)) {
  77. $values = array($values);
  78. }
  79. $this->feeds = $values;
  80. }
  81. }