RSSConfiguration.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. class RSSConfiguration extends Model {
  3. private $posts_per_page;
  4. private $default_view;
  5. private $display_posts;
  6. private $sort_order;
  7. private $old_entries;
  8. public function __construct () {
  9. $confDAO = new RSSConfigurationDAO ();
  10. $this->_postsPerPage ($confDAO->posts_per_page);
  11. $this->_defaultView ($confDAO->default_view);
  12. $this->_displayPosts ($confDAO->display_posts);
  13. $this->_sortOrder ($confDAO->sort_order);
  14. $this->_oldEntries ($confDAO->old_entries);
  15. }
  16. public function postsPerPage () {
  17. return $this->posts_per_page;
  18. }
  19. public function defaultView () {
  20. return $this->default_view;
  21. }
  22. public function displayPosts () {
  23. return $this->display_posts;
  24. }
  25. public function sortOrder () {
  26. return $this->sort_order;
  27. }
  28. public function oldEntries () {
  29. return $this->old_entries;
  30. }
  31. public function _postsPerPage ($value) {
  32. if (is_int ($value)) {
  33. $this->posts_per_page = $value;
  34. } else {
  35. $this->posts_per_page = 10;
  36. }
  37. }
  38. public function _defaultView ($value) {
  39. if ($value == 'not_read') {
  40. $this->default_view = 'not_read';
  41. } else {
  42. $this->default_view = 'all';
  43. }
  44. }
  45. public function _displayPosts ($value) {
  46. if ($value == 'yes') {
  47. $this->display_posts = 'yes';
  48. } else {
  49. $this->display_posts = 'no';
  50. }
  51. }
  52. public function _sortOrder ($value) {
  53. if ($value == 'high_to_low') {
  54. $this->sort_order = 'high_to_low';
  55. } else {
  56. $this->sort_order = 'low_to_high';
  57. }
  58. }
  59. public function _oldEntries ($value) {
  60. if (is_int (intval ($value))) {
  61. $this->old_entries = $value;
  62. } else {
  63. $this->old_entries = 3;
  64. }
  65. }
  66. }
  67. class RSSConfigurationDAO extends Model_array {
  68. public $posts_per_page = 10;
  69. public $default_view = 'all';
  70. public $display_posts = 'no';
  71. public $sort_order = 'low_to_high';
  72. public $old_entries = 3;
  73. public function __construct () {
  74. parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php');
  75. if (isset ($this->array['posts_per_page'])) {
  76. $this->posts_per_page = $this->array['posts_per_page'];
  77. }
  78. if (isset ($this->array['default_view'])) {
  79. $this->default_view = $this->array['default_view'];
  80. }
  81. if (isset ($this->array['display_posts'])) {
  82. $this->display_posts = $this->array['display_posts'];
  83. }
  84. if (isset ($this->array['sort_order'])) {
  85. $this->sort_order = $this->array['sort_order'];
  86. }
  87. if (isset ($this->array['old_entries'])) {
  88. $this->old_entries = $this->array['old_entries'];
  89. }
  90. }
  91. public function save ($values) {
  92. $this->array[0] = array ();
  93. foreach ($values as $key => $value) {
  94. $this->array[0][$key] = $value;
  95. }
  96. $this->writeFile($this->array);
  97. }
  98. }