Fix calcStat for Forum and Topic

This commit is contained in:
Visman 2020-06-23 18:53:43 +07:00
parent c0d9ebc700
commit 88458ad942
2 changed files with 14 additions and 14 deletions

View file

@ -22,13 +22,19 @@ class CalcStat extends Method
}
$vars = [':fid' => $this->model->id];
$sql = 'SELECT COUNT(t.id)
FROM ::topics AS t
WHERE t.forum_id=?i:fid AND t.moved_to!=0';
$moved = $this->c->DB->query($sql, $vars)->fetchColumn();
$sql = 'SELECT COUNT(t.id) as num_topics, SUM(t.num_replies) as num_replies
FROM ::topics AS t
WHERE t.forum_id=?i:fid';
WHERE t.forum_id=?i:fid AND t.moved_to=0';
$result = $this->c->DB->query($sql, $vars)->fetch();
$this->model->num_topics = $result['num_topics'];
$this->model->num_topics = $result['num_topics'] + $moved;
$this->model->num_posts = $result['num_topics'] + $result['num_replies'];
$sql = 'SELECT t.last_post, t.last_post_id, t.last_poster, t.subject as last_topic

View file

@ -23,13 +23,6 @@ class CalcStat extends Method
if ($this->model->moved_to) {
$num_replies = 0;
$result = [
'id' => 0,
'poster' => '',
'poster_id' => 0,
'posted' => 0,
'edited' => 0,
];
} else {
$vars = [
':tid' => $this->model->id
@ -47,14 +40,15 @@ class CalcStat extends Method
LIMIT 1';
$result = $this->c->DB->query($sql, $vars)->fetch();
$this->model->last_post_id = $result['id'];
$this->model->last_poster = $result['poster'];
$this->model->last_poster_id = $result['poster_id'];
$this->model->last_post = $result['edited'] > 0 && $result['edited'] > $result['posted'] ? $result['edited'] : $result['posted'];
}
//????
$this->model->num_replies = $num_replies;
$this->model->last_post_id = $result['id'];
$this->model->last_poster = $result['poster'];
$this->model->last_poster_id = $result['poster_id'];
$this->model->last_post = $result['edited'] > 0 && $result['edited'] > $result['posted'] ? $result['edited'] : $result['posted'];
$this->model->num_replies = $num_replies;
return $this->model;
}