/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BlogComment::find(); $query->orderBy(['created_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'post_id' => $this->post_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
public function run() { $str = ''; $query = new Query(); $res = $query->select('sum(click) as click')->from('blog_post')->one(); $click = $res['click']; $str .= '<div class="site-stat">Просмотров: ' . $click . '</div>'; $postCount = $query->from('blog_post')->where(['status' => Status::STATUS_ACTIVE])->count(); $str .= '<div class="site-stat">Статей: ' . $postCount . '</div>'; //$commentCount = $query->from('blog_comment')->where(['status'=>Status::STATUS_ACTIVE])->count(); $commentCount = BlogComment::find()->joinWith('blogPost')->where(['blog_comment.status' => Status::STATUS_ACTIVE, 'blog_post.status' => Status::STATUS_ACTIVE])->count(); $str .= '<div class="site-stat">Комментариев: ' . $commentCount . '</div>'; return $this->render('portal', ['title' => $this->title, 'content' => $str]); }
public function run() { $request = Yii::$app->getRequest(); $post = BlogPost::findOne(['surname' => Yii::$app->request->get('surname')]); $post_id = $post->id; //$post = BlogPost::findOne($post_id); $this->modelComment = new BlogComment(); if ($request->isAjax && $this->modelComment->load($request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; $this->modelComment->status = Status::STATUS_INACTIVE; $errors = ActiveForm::validate($this->modelComment); if (count($errors) != 0) { Yii::$app->getSession()->setFlash('blog.commentAddError', json_encode($errors)); } else { $transaction = Yii::$app->db->beginTransaction(); try { if (!$this->modelComment->save()) { Yii::$app->getSession()->setFlash('blog.commentAddError', 'Ошибка'); //throw new ErrorException('Error!'); } $transaction->commit(); Yii::$app->getSession()->setFlash('blog.commentAddSuccess', 'Отправлено на модерацию'); } catch (ErrorException $e) { $transaction->rollBack(); Yii::$app->getSession()->setFlash('blog.commentAddError', $e->getMessage()); } } $this->modelComment = new BlogComment(); } $commentsList = BlogComment::find()->where(['post_id' => $post_id, 'status' => Status::STATUS_ACTIVE])->orderBy(['created_at' => SORT_DESC])->all(); $this->modelComment->post_id = $post_id; if (!Yii::$app->user->isGuest) { $this->modelComment->email = Yii::$app->params['blogUserEMail']; $this->modelComment->author = Yii::$app->params['blogUserDisplayName']; $this->modelComment->user_id = Yii::$app->params['blogUserId']; } return $this->render('@sircovsw/blog/widgets/Comment/views/index', array('modelComment' => $this->modelComment, 'commentsList' => $commentsList)); }
public function run() { //$comments = Comment::find()->where(['status' => Comment::STATUS_ACTIVE])->orderBy(['create_time' => SORT_DESC])->limit($this->maxComments)->all(); $comments = BlogComment::findRecentComments($this->maxComments); return $this->render('recentComments', ['title' => $this->title, 'comments' => $comments]); }
/** * Finds the Comment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Comment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BlogComment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getParent() { return $this->hasOne(BlogComment::className(), ['id' => 'parent_id']); }
public function getComments() { return $this->hasMany(BlogComment::className(), ['post_id' => 'id']); }