|
|
- <?php
- /**
- * @package uForum2
- * @file inc/models/PostsModel.php
- * @copyright 2007-2015 (c) PioDer
- * @link http://www.pioder.pl/
- * @license see LICENSE.txt
- **/
-
- class PostsModel extends Model
- {
- private $topic_info = null;
- private $post_info = null;
-
- public function getTopic($topic_id)
- {
- if ($this->topic_info == null)
- {
- $query = '
- SELECT
- t.topic_id as topic_id, t.title as topic_title, t.sticky as topic_sticky, t.locked as topic_locked, t.forum_id as forum_id, f.name as forum_name, f.locked as forum_locked, pc.post_count as post_count
- FROM '.TOPICS_TABLE.' t
- LEFT JOIN '.FORUMS_TABLE.' f ON f.forum_id = t.forum_id
- LEFT JOIN '.TOPICS_PC_VIEW.' pc ON pc.topic_id = t.topic_id
- WHERE t.topic_id=\''.$topic_id.'\'';
- $out = $this->select_query($query);
- if (count($out) > 0)
- $this->topic_info = $out[0];
- }
-
- return $this->topic_info;
- }
-
- public function getPosts($topic_id)
- {
- $out = $this->select (POSTS_VIEW, '*', 'topic_id=\''.$topic_id.'\'', 'post_id ASC');
-
- if ($out != null)
- return $out;
- else
- return null;
- }
-
- public function getPost($post_id)
- {
- $out = $this->select (POSTS_VIEW, '*', 'post_id=\''.$post_id.'\'');
-
- if (count($out) > 0)
- return $out[0];
- else
- return null;
- }
-
- public function getFirstPost($topic_id)
- {
- $out = $this->select (POSTS_VIEW, 'post_id', 'topic_id=\''.$topic_id.'\'', 'post_id ASC', 1);
-
- if (count($out) > 0)
- return $out[0];
- else
- return null;
- }
-
- //mod options
- public function deletePost($post_id)
- {
- $query = 'DELETE FROM '.POSTS_TABLE.' WHERE post_id=\''.$post_id.'\';';
-
- $this->db->query($query);
- }
-
- public function deleteTopic($topic_id)
- {
- $query = 'call delete_topic(\''.$topic_id.'\');';
- $this->db->query($query);
- }
-
- public function lockTopic($topic_id, $locked = true)
- {
- $query = 'UPDATE '.TOPICS_TABLE.' SET locked=\''.$locked.'\' WHERE topic_id=\''.$topic_id.'\';';
-
- $this->db->query($query);
- }
-
- public function stickTopic($topic_id, $sticky = true)
- {
- $query = 'UPDATE '.TOPICS_TABLE.' SET sticky=\''.$sticky.'\' WHERE topic_id=\''.$topic_id.'\';';
-
- $this->db->query($query);
- }
-
- public function moveTopic($topic_id, $forum_id)
- {
- $query = 'UPDATE '.TOPICS_TABLE.' SET forum_id=\''.$forum_id.'\' WHERE topic_id=\''.$topic_id.'\';';
-
- $this->db->query($query);
- }
-
- public function addTopic($title, $content, $forum_id, $user_id)
- {
- $query = 'call add_topic(\''.$title.'\',
- \''.$content.'\',
- \''.$forum_id.'\',
- \''.$user_id.'\',
- \''.$_SERVER['HTTP_USER_AGENT'].'\',
- @out);';
- $this->db->query($query);
- $result = $this->db->query('select @out as topic_id');
-
- if ($result != null)
- return $result->fetch_assoc()['topic_id'];
- else
- return null;
- }
-
- public function changePost($post_id, $content)
- {
- $query = 'UPDATE '.POSTS_TABLE.' SET `content`=\''.$content.'\' WHERE `post_id`=\''.$post_id.'\'';
- $this->db->query($query);
- }
-
- public function changeTopic($topic_id, $title)
- {
- $query = 'UPDATE '.TOPICS_TABLE.' SET `title`=\''.$title.'\' WHERE `topic_id`=\''.$topic_id.'\'';
- $this->db->query($query);
- }
-
- public function addPost($topic_id, $user_id, $content)
- {
- $query = 'INSERT INTO '.POSTS_TABLE.'
- (post_id, topic_id, user_id, content, date, user_agent)
- VALUES
- (NULL, \''.$topic_id.'\', \''.$user_id.'\', \''.$content.'\', NOW(), \''.$_SERVER['HTTP_USER_AGENT'].'\')';
- $this->db->query($query);
- }
- }
- ?>
|