Category.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. public function __construct ($name = '', $feeds = null) {
  9. $this->_name ($name);
  10. if (isset ($feeds)) {
  11. $this->_feeds ($feeds);
  12. $this->nbFeed = 0;
  13. $this->nbNotRead = 0;
  14. foreach ($feeds as $feed) {
  15. $this->nbFeed++;
  16. $this->nbNotRead += $feed->nbNotRead ();
  17. }
  18. }
  19. }
  20. public function id () {
  21. return $this->id;
  22. }
  23. public function name () {
  24. return $this->name;
  25. }
  26. public function nbFeed () {
  27. if ($this->nbFeed < 0) {
  28. $catDAO = new FreshRSS_CategoryDAO ();
  29. $this->nbFeed = $catDAO->countFeed ($this->id ());
  30. }
  31. return $this->nbFeed;
  32. }
  33. public function nbNotRead () {
  34. if ($this->nbNotRead < 0) {
  35. $catDAO = new FreshRSS_CategoryDAO ();
  36. $this->nbNotRead = $catDAO->countNotRead ($this->id ());
  37. }
  38. return $this->nbNotRead;
  39. }
  40. public function feeds () {
  41. if ($this->feeds === null) {
  42. $feedDAO = new FreshRSS_FeedDAO ();
  43. $this->feeds = $feedDAO->listByCategory ($this->id ());
  44. $this->nbFeed = 0;
  45. $this->nbNotRead = 0;
  46. foreach ($this->feeds as $feed) {
  47. $this->nbFeed++;
  48. $this->nbNotRead += $feed->nbNotRead ();
  49. }
  50. }
  51. return $this->feeds;
  52. }
  53. public function _id ($value) {
  54. $this->id = $value;
  55. }
  56. public function _name ($value) {
  57. $this->name = $value;
  58. }
  59. public function _feeds ($values) {
  60. if (!is_array ($values)) {
  61. $values = array ($values);
  62. }
  63. $this->feeds = $values;
  64. }
  65. }