public function actionIndex()
 {
     $searchModel = new CommentSearchModel();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $commentModel = CommentModel::className();
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentModel' => $commentModel]);
 }
 /**
  * Find model by ID.
  *
  * @param integer|array $id Comment ID
  * @return null|CommentModel
  * @throws NotFoundHttpException
  */
 protected function findModel($id)
 {
     /** @var CommentModel $model */
     $commentModelClass = CommentModel::className();
     if (($model = $commentModelClass::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
Beispiel #3
0
 /**
  * Executes the widget.
  * @return string the result of widget execution to be outputted.
  */
 public function run()
 {
     /* @var $module Module */
     $module = Module::$name;
     //Get comment model class from `comment` Module
     $commentModelClass = CommentModel::className();
     //Get entity from widget and hash it.
     $entity = $this->model;
     $entityId = $entity->{$this->entityIdAttribute};
     $entity = hash('crc32', $entity::className());
     //Get comment tree by entity and entityId
     $comments = $commentModelClass::getTree($entity, $entityId, $this->maxLevel);
     //Create comment model
     $commentModel = Yii::createObject($commentModelClass);
     //Encrypt entity and entityId values
     $encryptedEntity = Yii::$app->getSecurity()->encryptByKey(Json::encode(['entity' => $entity, 'entityId' => $entityId]), $module);
     return $this->render('index', ['comments' => $comments, 'commentModel' => $commentModel, 'maxLevel' => $this->maxLevel, 'encryptedEntity' => $encryptedEntity, 'pjaxContainerId' => $this->pjaxContainerId]);
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getClass()
 {
     return $this->hasOne(CommentModel::className(), ['id' => 'model_class']);
 }
Beispiel #5
0
 public function getArticleCommentCount()
 {
     return $this->hasMany(CommentModel::className(), ['entityId' => 'id'])->count();
 }