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.

122 lines
2.6 KiB

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