public function init() { parent::init(); $this->module = \Yii::$app->getModule(Module::$name); // Текущий модуль $model = new PostComment(); $this->comments = $model->getRecentPostComments($this->limit); }
<p><?php echo Markdown::convert($model->anons); ?> </p> <p> <?php if (PostComment::getCountComments($model->id) > 0) { ?> <span class="glyphicon glyphicon-comment"></span> <a href="<?php echo Url::to(['default/view', 'id' => $model->id, '#' => 'comments']); ?> "><?php echo Module::t('module', 'COMMENTS:{count}', ['count' => PostComment::getCountComments($model->id)]); ?> </a> | <?php } ?> <?php if ($model->tagLinks) { ?> <span class="glyphicon glyphicon-tags"></span> <?php echo Tags::array2string($model->tagLinks); ?> <?php } ?> </p>
/** * @param $id * @return array|\yii\db\ActiveRecord[] */ public static function getComments($id) { return PostComment::find()->where(['moder' => PostComment::COMMENT_MODER_ALLOWED])->andWhere(['material_id' => $id])->andWhere(['type' => PostComment::TYPE_OF_COMMENT])->all(); }
/** * Возвращает все комментарии к посту * и осуществляет связь hasMany с PostComment * @return ActiveQuery */ public function getComments() { return $this->hasMany(PostComment::className(), ['material_id' => 'id'])->where(['namespace' => PostComment::MATERIAL_MODEL_OF_NAMESPACE])->orderBy(['parent_id' => SORT_ASC, 'id' => SORT_ASC]); }