A new, object-oriented, better vesion of μForum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.5 KiB

  1. <?php
  2. require_once('./inc/model.class.php');
  3. class ForumsModel extends Model
  4. {
  5. private $forum_info = null;
  6. private $cat_info = null;
  7. public function getForums()
  8. {
  9. return $this->select (FORUMS_VIEW);
  10. }
  11. public function getCats()
  12. {
  13. return $this->select (CATS_TABLE);
  14. }
  15. public function getForumsNames()
  16. {
  17. $out = $this->select (FORUMS_TABLE, 'forum_id, name', '', 'forum_id ASC');
  18. if (count($out) > 0)
  19. return $out;
  20. else
  21. return array();
  22. }
  23. public function getForum($forum_id)
  24. {
  25. if ($this->forum_info == null)
  26. {
  27. $out = $this->select(FORUMS_TABLE, '*', 'forum_id=\''.$forum_id.'\'');
  28. if (count($out) > 0)
  29. $this->forum_info = $out[0];
  30. }
  31. return $this->forum_info;
  32. }
  33. public function getTopics($forum_id)
  34. {
  35. $out = $this->select(TOPICS_VIEW, '*', 'forum_id=\''.$forum_id.'\'', 'lastpost_post_id DESC');
  36. if (count($out) > 0)
  37. return $out;
  38. else
  39. return array();
  40. }
  41. public function getCat($cat_id)
  42. {
  43. if ($this->cat_info == null)
  44. {
  45. $out = $this->select(CATS_TABLE, '*', 'category_id=\''.$cat_id.'\'');
  46. if (count($out) > 0)
  47. $this->cat_info = $out[0];
  48. }
  49. return $this->cat_info;
  50. }
  51. public function changeCat($cat_id, $cat_name)
  52. {
  53. $query = 'UPDATE '.CATS_TABLE.'
  54. SET `name`=\''.$cat_name.'\'
  55. WHERE `category_id`=\''.$cat_id.'\'';
  56. $this->db->query($query);
  57. }
  58. public function addCat($cat_name)
  59. {
  60. $query = 'INSERT INTO '.CATS_TABLE.'
  61. (category_id, name)
  62. VALUES (NULL, \''.$cat_name.'\')';
  63. $this->db->query($query);
  64. }
  65. public function deleteCat($cat_id)
  66. {
  67. $query = 'DELETE FROM '.CATS_TABLE.'
  68. WHERE `category_id`=\''.$cat_id.'\'';
  69. $this->db->query($query);
  70. }
  71. public function changeForum($forum_id, $forum_name, $forum_desc, $forum_category_id, $forum_locked)
  72. {
  73. $query = 'UPDATE '.FORUMS_TABLE.'
  74. SET `name`=\''.$forum_name.'\',
  75. `desc`=\''.$forum_desc.'\',
  76. `category_id`=\''.$forum_category_id.'\',
  77. `locked`=\''.$forum_locked.'\'
  78. WHERE `forum_id`=\''.$forum_id.'\'';
  79. $this->db->query($query);
  80. }
  81. public function addForum($forum_name, $forum_desc, $forum_category_id, $forum_locked)
  82. {
  83. $query = 'INSERT INTO '.FORUMS_TABLE.'
  84. (`forum_id`, `name`, `desc`, `category_id`, `locked`)
  85. VALUES (NULL, \''.$forum_name.'\', \''.$forum_desc.'\', \''.$forum_category_id.'\', \''.$forum_locked.'\')';
  86. $this->db->query($query);
  87. }
  88. public function deleteForum($forum_id)
  89. {
  90. $query = 'DELETE FROM '.FORUMS_TABLE.'
  91. WHERE `forum_id`=\''.$forum_id.'\'';
  92. $this->db->query($query);
  93. }
  94. }
  95. ?>