Category.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. class FreshRSS_Category extends Minz_Model {
  3. private $id = 0;
  4. private $name;
  5. private $color;
  6. private $nbFeed = -1;
  7. private $nbNotRead = -1;
  8. private $feeds = null;
  9. public function __construct ($name = '', $color = '#0062BE', $feeds = null) {
  10. $this->_name ($name);
  11. $this->_color ($color);
  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. }
  20. }
  21. }
  22. public function id () {
  23. return $this->id;
  24. }
  25. public function name () {
  26. return $this->name;
  27. }
  28. public function color () {
  29. return $this->color;
  30. }
  31. public function nbFeed () {
  32. if ($this->nbFeed < 0) {
  33. $catDAO = new FreshRSS_CategoryDAO ();
  34. $this->nbFeed = $catDAO->countFeed ($this->id ());
  35. }
  36. return $this->nbFeed;
  37. }
  38. public function nbNotRead () {
  39. if ($this->nbNotRead < 0) {
  40. $catDAO = new FreshRSS_CategoryDAO ();
  41. $this->nbNotRead = $catDAO->countNotRead ($this->id ());
  42. }
  43. return $this->nbNotRead;
  44. }
  45. public function feeds () {
  46. if ($this->feeds === null) {
  47. $feedDAO = new FreshRSS_FeedDAO ();
  48. $this->feeds = $feedDAO->listByCategory ($this->id ());
  49. $this->nbFeed = 0;
  50. $this->nbNotRead = 0;
  51. foreach ($this->feeds as $feed) {
  52. $this->nbFeed++;
  53. $this->nbNotRead += $feed->nbNotRead ();
  54. }
  55. }
  56. return $this->feeds;
  57. }
  58. public function _id ($value) {
  59. $this->id = $value;
  60. }
  61. public function _name ($value) {
  62. $this->name = $value;
  63. }
  64. public function _color ($value) {
  65. if (preg_match ('/^#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
  66. $this->color = $value;
  67. } else {
  68. $this->color = '#0062BE';
  69. }
  70. }
  71. public function _feeds ($values) {
  72. if (!is_array ($values)) {
  73. $values = array ($values);
  74. }
  75. $this->feeds = $values;
  76. }
  77. }