Answer the question
In order to leave comments, you need to log in
How to count documents at each level, including sublevels, in a nestedset?
Has anyone asked this question? I think the answers will be useful not only to me.
At the moment, I've only come up with this
private function _getCount($root=true){
$criteria = new CDbCriteria();
$criteria->addCondition('parent_id IS '.($root ? '' : ' NOT ').' NULL');
$criteria->addCondition('category_id IN (
SELECT
id
FROM
forum_categories
WHERE
_left >= :left
AND _right<= :right
AND _root= :root)'
);
$criteria->params[':left'] = $this->_left;
$criteria->params[':right'] = $this->_right;
$criteria->params[':root'] = $this->_root;
return YiiForumPost::model()->count($criteria);
}
public function getCountTopics(){
return $this->_getCount();
}
public function getCountPosts(){
return $this->_getCount(true);
}
Answer the question
In order to leave comments, you need to log in
counters should be stored in the cache (redis), and the base should not be touched
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question