RSSConfiguration.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. public function __construct () {
  8. $confDAO = new RSSConfigurationDAO ();
  9. $this->_postsPerPage ($confDAO->posts_per_page);
  10. $this->_defaultView ($confDAO->default_view);
  11. $this->_displayPosts ($confDAO->display_posts);
  12. $this->_sortOrder ($confDAO->sort_order);
  13. }
  14. public function postsPerPage () {
  15. return $this->posts_per_page;
  16. }
  17. public function defaultView () {
  18. return $this->default_view;
  19. }
  20. public function displayPosts () {
  21. return $this->display_posts;
  22. }
  23. public function sortOrder () {
  24. return $this->sort_order;
  25. }
  26. public function _postsPerPage ($value) {
  27. if (is_int ($value)) {
  28. $this->posts_per_page = $value;
  29. } else {
  30. $this->posts_per_page = 10;
  31. }
  32. }
  33. public function _defaultView ($value) {
  34. if ($value == 'not_read') {
  35. $this->default_view = 'not_read';
  36. } else {
  37. $this->default_view = 'all';
  38. }
  39. }
  40. public function _displayPosts ($value) {
  41. if ($value == 'yes') {
  42. $this->display_posts = 'yes';
  43. } else {
  44. $this->display_posts = 'no';
  45. }
  46. }
  47. public function _sortOrder ($value) {
  48. if ($value == 'high_to_low') {
  49. $this->sort_order = 'high_to_low';
  50. } else {
  51. $this->sort_order = 'low_to_high';
  52. }
  53. }
  54. }
  55. class RSSConfigurationDAO extends Model_array {
  56. public $posts_per_page = 10;
  57. public $default_view = 'all';
  58. public $display_posts = 'no';
  59. public $sort_order = 'low_to_high';
  60. public function __construct () {
  61. parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php');
  62. if (isset ($this->array['posts_per_page'])) {
  63. $this->posts_per_page = $this->array['posts_per_page'];
  64. }
  65. if (isset ($this->array['default_view'])) {
  66. $this->default_view = $this->array['default_view'];
  67. }
  68. if (isset ($this->array['display_posts'])) {
  69. $this->display_posts = $this->array['display_posts'];
  70. }
  71. if (isset ($this->array['sort_order'])) {
  72. $this->sort_order = $this->array['sort_order'];
  73. }
  74. }
  75. public function save ($values) {
  76. $this->array[0] = array ();
  77. foreach ($values as $key => $value) {
  78. $this->array[0][$key] = $value;
  79. }
  80. $this->writeFile($this->array);
  81. }
  82. }