RSSConfiguration.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. class RSSConfiguration extends Model {
  3. private $posts_per_page;
  4. private $default_view;
  5. private $display_posts;
  6. public function __construct () {
  7. $confDAO = new RSSConfigurationDAO ();
  8. $this->_postsPerPage ($confDAO->posts_per_page);
  9. $this->_defaultView ($confDAO->default_view);
  10. $this->_displayPosts ($confDAO->display_posts);
  11. }
  12. public function postsPerPage () {
  13. return $this->posts_per_page;
  14. }
  15. public function defaultView () {
  16. return $this->default_view;
  17. }
  18. public function displayPosts () {
  19. return $this->display_posts;
  20. }
  21. public function _postsPerPage ($value) {
  22. if (is_int ($value)) {
  23. $this->posts_per_page = $value;
  24. } else {
  25. $this->posts_per_page = 10;
  26. }
  27. }
  28. public function _defaultView ($value) {
  29. if ($value == 'not_read') {
  30. $this->default_view = 'not_read';
  31. } else {
  32. $this->default_view = 'all';
  33. }
  34. }
  35. public function _displayPosts ($value) {
  36. if ($value == 'yes') {
  37. $this->display_posts = 'yes';
  38. } else {
  39. $this->display_posts = 'no';
  40. }
  41. }
  42. }
  43. class RSSConfigurationDAO extends Model_array {
  44. public $posts_per_page = 10;
  45. public $default_view = 'all';
  46. public $display_posts = 'no';
  47. public function __construct () {
  48. parent::__construct (PUBLIC_PATH . '/data/db/Configuration.array.php');
  49. if (isset ($this->array['posts_per_page'])) {
  50. $this->posts_per_page = $this->array['posts_per_page'];
  51. }
  52. if (isset ($this->array['default_view'])) {
  53. $this->default_view = $this->array['default_view'];
  54. }
  55. if (isset ($this->array['display_posts'])) {
  56. $this->display_posts = $this->array['display_posts'];
  57. }
  58. }
  59. public function save ($values) {
  60. $this->array[0] = array ();
  61. foreach ($values as $key => $value) {
  62. $this->array[0][$key] = $value;
  63. }
  64. $this->writeFile($this->array);
  65. }
  66. }