14 private $_commentsAmount;
24 if (!is_array($this->contentId)) {
25 $this->contentId = array($this->contentId);
45 if ($this->_commentsAmount === null) {
46 $dependency =
new CExpressionDependency(
47 'Yii::app()->db->createCommand()->select("id, status")->from(Comment::model()->tableName())->where(array("in", "content_id", ' . var_export($this->contentId,
true) .
'))->queryAll()'
49 $result = Yii::app()->db->cache(Yii::app()->getModule(
'comments')->cacheTime, $dependency)
51 ->select(
'content_id, count(*) as count')
53 ->where(array(
'and',
'status=' . Comment::APPROVED, array(
'in',
'content_id', $this->contentId)))
57 $this->_commentsAmount = array();
58 foreach ($result as $r) {
59 $this->_commentsAmount[$r[
'content_id']] = $r[
'count'];
62 return $this->_commentsAmount;
74 $amount = isset($this->commentsAmount[$contentId]) ? $this->commentsAmount[$contentId] : 0;
75 $this->render(
'CommentsAmountWidget', array(
'amount' => $amount));