Exemplo n.º 1
0
 function getTheme()
 {
     if (!$this->theme_id) {
         return;
     }
     $query = 'SELECT uid as user_id,title,body FROM `node_revisions` WHERE `nid`=' . $this->theme_id . ' LIMIT 1';
     $theme = Database::sql2row($query);
     if (!$theme) {
         throw new Exception('Мы проебали эту тему форума');
     }
     $theme['body'] = _bbcode_filter_process($theme['body']);
     $this->data['theme'] = $theme;
     Request::pass('theme-title', $theme['title']);
     $cond = new Conditions();
     $per_page = 0;
     if (isset($this->params['per_page'])) {
         $per_page = (int) $this->params['per_page'];
     }
     $per_page = $per_page > 0 ? $per_page : 5;
     $query = 'SELECT pid=0 as pid, COUNT(1) as cnt FROM `comments_v2` WHERE `nid` = ' . $this->theme_id . ' GROUP BY (pid=0)';
     $count_arr = Database::sql2array($query, 'pid');
     $count = isset($count_arr[0]['cnt']) ? $count_arr[0]['cnt'] : 0;
     $count_arr[0] = array('cnt' => $count);
     $count_with_answers = isset($count_arr[1]['cnt']) ? $count_arr[1]['cnt'] + $count_arr[0]['cnt'] : $count_arr[0]['cnt'];
     $cond->setPaging($count, $per_page);
     $limit = $cond->getLimit();
     $query = 'SELECT rid,cid,pid,subject,comment,timestamp,uid FROM `comments_v2` WHERE `nid` = ' . $this->theme_id . ' AND `pid`=0 ORDER BY `timestamp` LIMIT ' . $limit;
     $comments = Database::sql2array($query, 'cid');
     // childs?
     if (count($comments)) {
         $query = 'SELECT * FROM `comments_v2` WHERE `pid` IN(' . implode(',', array_keys($comments)) . ') ORDER BY `sort`';
         $answers = Database::sql2array($query, 'cid');
         foreach ($answers as &$answer) {
             $answer['comment'] = _bbcode_filter_process($answer['comment']);
             $answer['time'] = date('Y/m/d H:i', $answer['timestamp']);
             $comments[$answer['pid']]['answers'][] = $answer;
         }
     }
     $uids = array();
     foreach ($comments as &$comment) {
         $uids[$comment['uid']] = $comment['uid'];
         $comment['comment'] = _bbcode_filter_process($comment['comment']);
         $comment['time'] = date('Y/m/d H:i', $comment['timestamp']);
     }
     $uids[$theme['user_id']] = $theme['user_id'];
     $this->data['theme']['users'] = $this->getUsers($uids);
     $this->data['theme']['tid'] = $this->forum_id;
     $this->data['theme']['theme_id'] = $this->theme_id;
     $this->data['theme']['comments'] = $comments;
     $this->data['theme']['comments']['count'] = $count_with_answers;
     $this->data['theme']['comments']['count_nop'] = $count;
     $this->data['conditions'] = $cond->getConditions();
 }
Exemplo n.º 2
0
	function getTheme() {
		if (!$this->theme_id)
			return;

		$query = 'SELECT uid as user_id,title,body FROM `node_revisions` WHERE `nid`=' . $this->theme_id . ' LIMIT 1';
		$theme = Database::sql2row($query);
		$theme['body'] = _bbcode_filter_process($theme['body']);
		$this->data['theme'] = $theme;

		$query = 'SELECT subject,comment,timestamp,uid FROM `comments` WHERE `nid` = ' . $this->theme_id . ' ORDER BY `timestamp`';
		$comments = Database::sql2array($query);
		$uids = array();
		foreach ($comments as &$comment) {
			$uids[$comment['uid']] = $comment['uid'];
			$comment['comment'] = _bbcode_filter_process($comment['comment']);
		}
		$uids[$theme['user_id']] = $theme['user_id'];
		$this->data['theme']['users'] = $this->getUsers($uids);
		$this->data['theme']['tid'] = $this->forum_id;
		$this->data['theme']['comments'] = $comments;
	}