/** * 显示一个文章的信息 * @return type */ public function actionArticle() { $id = \Yii::$app->request->get('id'); $idTrue = true; if (empty($id)) { $idTrue = FALSE; } if ($idTrue) { $articleInfo = Comment::find()->where('id=:id', [':id' => $id])->one(); if (!$articleInfo) { $idTrue = FALSE; } else { if ($articleInfo->is_public === 0 && \Yii::$app->user->getId() !== $articleInfo->to_user_id && \Yii::$app->user->getId() !== $articleInfo->user_id) { $idTrue = FALSE; } } } if (!$idTrue) { $error = '当前评论不存在或者已经被禁止显示'; $notices = array('type' => 2, 'msgtitle' => '错误的访问', 'message' => $error, 'backurl' => Url::toRoute('/say/index'), 'backtitle' => '返回'); Yii::$app->getSession()->setFlash('wechat_fail', array($notices)); $this->redirect(Url::toRoute('/public/notices')); } return $this->render('article', ['articleInfo' => $articleInfo]); }
public function actionAddComment() { if (\Yii::$app->request->isAjax) { $model = new Comment(); if (\Yii::$app->user->isGuest) { $model->scenario = 'isGuest'; } $data = ['error' => true]; if ($model->load(\Yii::$app->request->post())) { $parentID = \Yii::$app->request->post('parent_id'); $root = $model->makeRootIfNotExist(); if (!$parentID) { $model->appendTo($root); } else { $parent = Comment::find()->where(['id' => $parentID])->one(); $model->appendTo($parent); } $articleModel = Article::findOne($model->model_id); $data = ['replaces' => [['what' => '#comments', 'data' => $this->renderAjax('@app/themes/basic/modules/article/views/default/_comments', ['model' => $articleModel])]]]; } return Json::encode($data); } else { throw new NotFoundHttpException(\Yii::t('app', 'Page not found')); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $commentTable = Comment::tableName(); $user = Yii::$app->getModule("user")->model("User"); // set up query with relation to `user.username` $userTable = $user::tableName(); $query->joinWith(['user' => function ($query) use($userTable) { $query->from(['user' => $userTable]); }]); $profileTable = \common\modules\user\models\Profile::tableName(); $query->joinWith(['profile' => function ($query) use($profileTable) { $query->from(['profile' => $profileTable]); }]); $dataProvider = new ActiveDataProvider(['query' => $query]); // enable sorting for the related columns $addSortAttributes = ["user.username", 'profile.full_name']; foreach ($addSortAttributes as $addSortAttribute) { $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]]; } if (!($this->load($params) && $this->validate())) { return $dataProvider; } $createdTime = strtotime($this->created_at); $startDay = date("Y-m-d 00:00:00", $createdTime); $endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24); if ($this->created_at) { $query->andFilterWhere(['between', 'created_at', $startDay, $endDay]); } $query->andFilterWhere(["{$commentTable}.id" => $this->id, "{$commentTable}.user_id" => $this->user_id, 'parent_id' => $this->parent_id]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')])->andFilterWhere(['like', 'profile.full_name', $this->getAttribute('profile.full_name')]); return $dataProvider; }
public function actionList($event_id) { \Yii::$app->response->format = Response::FORMAT_JSON; $dp = new ActiveDataProvider(); $dp->query = Comment::find()->with('user')->where(['event_id' => $event_id])->orderBy(['id' => SORT_DESC]); $dp->pagination->pageSize = 6; return ['items' => $dp->getModels(), 'pageCount' => $dp->getPagination()->getPageCount(), 'totalCount' => $dp->getTotalCount(), 'page' => $dp->pagination->page, 'count' => $dp->getCount()]; }
/** * * @param int $data * @return \yii\data\ActiveDataProvider */ public static function findComments($data = array()) { if (!isset($data['limit'])) { $data['limit'] = 10; } $model = new Comment(); $dataProvider = new ActiveDataProvider(['query' => $model->find()->Where('is_public=:isp and top_id=0 and c_type="article" ', [':isp' => $data['is_public']])->orderBy(" id desc ")->limit($data['limit']), 'pagination' => ['pagesize' => $data['limit']]]); return $dataProvider; }
public function run() { $query = Comment::find(); if ($this->entity == Comment::ENTITY_ITEM || $this->entity == Comment::ENTITY_EVENT || $this->entity == Comment::ENTITY_SCHOOL) { $query = $query->andWhere(['entity' => $this->entity, 'entity_id' => $this->entity_id])->orderBy('date_create DESC'); } $commentsAll = $query->all(); $commentIds = []; $comments = []; $commentsParent = []; $commentsLink = []; /** @var Comment[] $commentsAll */ foreach ($commentsAll as $comment) { if ($comment->parent_id == 0) { // Главный комментарий $commentsLink[$comment->id] = true; $commentIds[] = $comment->id; if ($comment->deleted == 0) { $comments[] = $comment; } } else { // Ответ на комментарий $commentsLink[$comment->id] = $comment->parent_id; } } foreach ($commentsAll as $comment) { if ($comment->deleted == 0) { $commentId = $comment->parent_id; while (isset($commentsLink[$commentId])) { if ($commentsLink[$commentId] === true) { break; } else { if ($commentsLink[$commentId] != $commentId) { $commentId = $commentsLink[$commentId]; } else { $commentId = null; } } } if (!empty($commentId)) { $commentsParent[$commentId][] = $comment; $commentIds[] = $comment->id; } } } $thisUser = User::thisUser(); /** @var Vote[] $voteItemsAll */ $voteItemsAll = !empty($thisUser) ? $thisUser->getVotesByEntity(Vote::ENTITY_COMMENT, $commentIds) : []; $voteItems = []; foreach ($voteItemsAll as $voteItem) { $voteItems[$voteItem->entity_id] = $voteItem; } return $this->render('commentsWidget/list', ['comments' => $comments, 'voteItems' => $voteItems, 'commentsParent' => $commentsParent, 'entity' => $this->entity, 'entity_id' => $this->entity_id, 'showDialog' => $this->showDialog]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::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, 'user_id' => $this->user_id, 'product_id' => $this->product_id, 'order_id' => $this->order_id, 'star' => $this->star, 'point' => $this->point, 'up' => $this->up, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'section_id' => $this->section_id, 'parent' => $this->parent, 'status' => $this->status, 'thumbsup' => $this->thumbsup, 'thumbsdown' => $this->thumbsdown, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find()->orderBy('id DESC'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'post_id' => $this->post_id, 'parent_id' => $this->parent_id, 'thumbsup' => $this->thumbsup, 'thumbsdown' => $this->thumbsdown, '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]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'article_id' => $this->article_id]); $query->andFilterWhere(['like', 'subject', $this->subject])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'create_time' => $this->create_time, 'post_id' => $this->post_id]); $query->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'is_active' => $this->is_active, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'user_email', $this->user_email]); return $dataProvider; }
/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($id) { $list_comment = new ActiveDataProvider(['query' => Comment::find()->where(['post_id' => $id, 'status' => 1])]); $model_comment = new Comment(); if ($model_comment->load(Yii::$app->request->post())) { $model_comment->post_id = $id; $model_comment->status = 0; if ($model_comment->save()) { Yii::$app->session->setFlash('success', 'Ваш комментарий был отправлен администраторам сайта и будет опубликован после проверки..'); } else { Yii::$app->session->setFlash('error', 'Ваш комментарий не был отправлен по техническим причинам. Попробуйте ещё раз.'); } } return $this->render('view', ['model' => $this->findModel($id), 'list_comment' => $list_comment, 'model_comment' => $model_comment]); }
public function actionDm() { \Yii::$app->response->format = Response::FORMAT_JSON; $article_id = \Yii::$app->request->post('article_id'); $time = \Yii::$app->request->post('time'); $page = \Yii::$app->request->post('page'); $query = Comment::find()->where(['article_id' => $article_id]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $models = $query->offset($pages->offset)->orderBy('created_at desc')->limit($pages->limit)->with('user')->asArray()->all(); $hasNext = 0; if ($page < $pages->pageCount) { $hasNext = 1; } return ['list' => $models, 'hasNext' => $hasNext, 'time' => $time]; }
public function actionView($id) { $model = Article::find()->where(['id' => $id, 'status' => Article::STATUS_ACTIVE])->one(); if ($model === null) { throw new NotFoundHttpException('not found'); } // 浏览量变化 $model->addView(); $commentModel = new Comment(); $commentQuery = Comment::find()->where(['article_id' => $id, 'parent_id' => 0]); $countCommentQuery = clone $commentQuery; $pages = new Pagination(['totalCount' => $countCommentQuery->count()]); $commentModels = $commentQuery->offset($pages->offset)->orderBy('created_at desc')->limit($pages->limit)->all(); $hots = Article::find()->where(['category_id' => $model->category_id])->limit(10)->orderBy('view desc')->all(); return $this->render('view', ['model' => $model, 'commentModel' => $commentModel, 'commentModels' => $commentModels, 'pages' => $pages, 'hots' => $hots]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Comment::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'news_id' => $this->news_id, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
public function actionView($slug) { $album = Gallery::cat($slug); if (!$album) { throw new \yii\web\NotFoundHttpException('无照片.'); } // 评论列表 $commentDataProvider = new ActiveDataProvider(['query' => Comment::find()->andWhere(['article_id' => $album->model->category_id, 'parent_id' => 0, 'comment_type' => 'gallery']), 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); //评论数 $commentNum = Comment::find()->andWhere(['article_id' => $slug, 'parent_id' => 0, 'comment_type' => 'gallery'])->count(1); $commentModels = $commentDataProvider->getModels(); $pages = $commentDataProvider->getPagination(); // 评论框 $commentModel = new Comment(); return $this->render('view', ['album' => $album, 'photos' => $album->photos(['pagination' => ['pageSize' => 10]]), 'commentModel' => $commentModel, 'commentModels' => $commentModels, 'pages' => $pages, 'commentDataProvider' => $commentDataProvider, 'commentNum' => $commentNum]); }
/** * Displays a single Suggestion model. * @param integer $id * @return mixed */ public function actionView($id) { $comment = new Comment(); if (Yii::$app->request->post()) { $comment->sugg_id = $id; $comment->part_id = strval(Yii::$app->user->id); $comment->content = Yii::$app->request->post('Comment')['content']; if ($comment->save()) { Yii::$app->session->setFlash('success', '评论成功'); return $this->redirect(['view', 'id' => $id]); } else { error_log(print_r($comment->errors, true)); Yii::$app->session->setFlash('error', '评论失败'); return $this->redirect(['view', 'id' => $id]); } } $commentsProvider = new ActiveDataProvider(['query' => Comment::find()->where(['sugg_id' => $id])->orderBy('created_at DESC'), 'pagination' => ['pageSize' => 20]]); return $this->render('view', ['model' => $this->findModel($id), 'comment' => $comment, 'commentsProvider' => $commentsProvider]); }
public function actionIndex() { \Yii::$app->response->format = Response::FORMAT_JSON; $userId = \Yii::$app->user->id; $id = \Yii::$app->request->get('id'); $type = \Yii::$app->request->get('type', 'article'); $action = \Yii::$app->request->get('action', 'up'); if ($type == 'article') { $model = Article::find()->where(['id' => $id])->select('id,up,down')->one(); } else { $model = Comment::find()->where(['id' => $id])->select('id,up,down')->one(); } $vote = Vote::find()->where(['type_id' => $id, 'type' => $type, 'action' => $action, 'user_id' => $userId])->one(); if (empty($vote)) { $model->{$action} += 1; $model->save(false); $vote = new Vote(); $params = ['type' => $type, 'action' => $action, 'type_id' => $id, 'user_id' => $userId]; $vote->attributes = $params; $vote->save(); } return ['up' => $model->up, 'down' => $model->down]; }
public function actionView($slug) { $commentForm = new Comment(); $article = Content::find()->where(['slug' => $slug, 'type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE])->with(['createdBy', 'category', 'tags'])->one(); if (empty($article)) { throw new NotFoundHttpException('没有找到相应文章。。。'); } if ($commentForm->load(Yii::$app->request->post())) { $commentForm->content_id = $article['id']; if ($commentForm->save()) { Yii::$app->session->setFlash('success', '评论发表成功'); return $this->refresh(); } else { Yii::$app->session->setFlash('error', '评论发表失败'); } } $article->updateCounters(['view_total' => 1]); $model = Comment::find()->where(['content_id' => $article['id'], 'status' => Comment::STATUS_ACTIVE]); $countModel = clone $model; $commentsPagination = new Pagination(['totalCount' => $countModel->count('id')]); $comments = $model->orderBy('created_at')->select(['id', 'ip', 'url', 'text', 'created_at', 'email', 'nickname', 'parent_id'])->asArray()->all(); return $this->render('view', ['article' => $article, 'commentForm' => $commentForm, 'comments' => $comments, 'commentsPagination' => $commentsPagination]); }
/** * 保存商品 */ public function save() { $newComent = new Comment(); $newComent->setAttributes($this->attributes); //获得对应回复ID的信息 $upComment = Comment::find()->where('id=:id', [':id' => $this->top_id])->one(); if (!$upComment) { return FALSE; } //设置title $newComent->setAttribute('c_title', $this->user_id . ',' . $upComment->c_title); //设置to_user_id $newComent->setAttribute('to_user_id', $upComment->user_id); $newComent->setAttribute("c_type", 'pinrun'); $newComent->setAttribute("is_public", $upComment->is_public); $newComent->setAttribute("c_nums", 0); $newComent->setAttribute("c_addtime", date('Y-m-d H:i:s')); if ($newComent->save()) { Comment::updateAllCounters(['c_nums' => 1], "id=:id", [':id' => $this->top_id]); return $this->top_id; } else { return FALSE; } }
public function actionComment() { if (isset($_POST['user_id']) && isset($_POST['post_id']) && isset($_POST['content'])) { $comment = new Comment(); $comment['user_id'] = $_POST['user_id']; $comment['post_id'] = $_POST['post_id']; $comment['content'] = $_POST['content']; $comment['create_at'] = $_POST['create_at']; //$comment['create_at'] = Yii::$app->formatter->asDatetime("Y-m-d"); $comment->save(); $user = User::findOne(['id' => $_POST['user_id']]); if ($user['image'] != "") { $image = Yii::$app->request->baseUrl . "/images/" . $user['image']; } else { $image = Yii::$app->request->baseUrl . "/images/avatar-default.jpg"; } $id = $_POST['post_id']; $receiver = Post::findOne(['id' => $id])['user_id']; if ($receiver != Yii::$app->user->getId()) { $newNotify = new PostNotification(); $newNotify['post_id'] = $id; $newNotify['type'] = 1; $newNotify['status'] = 0; $newNotify['action_id'] = Yii::$app->user->getId(); $newNotify['receiver_id'] = $receiver; $newNotify['create_at'] = date("Y/m/d H:i"); $newNotify->save(); } $listComment = Comment::find()->where(['post_id' => $id])->asArray()->all(); foreach ($listComment as $oneComment) { $isAdded[$oneComment['user_id']] = 0; } $isAdded[$receiver] = 1; foreach ($listComment as $oneComment) { $receiver = $oneComment['user_id']; if ($receiver != Yii::$app->user->getId() && $isAdded[$receiver] != 1) { $newNotify = new PostNotification(); $newNotify['post_id'] = $id; $newNotify['type'] = 1; $newNotify['status'] = 0; $newNotify['action_id'] = Yii::$app->user->getId(); $newNotify['receiver_id'] = $receiver; $newNotify['create_at'] = date("Y/m/d H:i"); $newNotify->save(); } $isAdded[$receiver] = 1; } echo '<div class="box-comment">' . '<img class="img-circle img-sm" src="' . $image . '" alt="user image">' . '<div class="comment-text">' . '<span class="username">' . $user['username'] . '<span class="text-muted pull-right">' . $comment['create_at'] . '</span>' . '</span>' . $comment['content'] . '</div>' . '</div>'; } else { echo 'NO'; } }
/** * Lists all Comment models. * @return mixed */ public function actionCommented() { $query = Comment::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['created_at' => SORT_DESC]); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeOrder']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]); return $this->render('commented', ['models' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination]); }
public function actionViews() { $this->layout = '/blog'; $slug = Yii::$app->request->get('slug'); $blog = Blog::find()->where(['slug' => $slug])->one(); if ($blog) { $viwsQuantity = (int) $blog->view; $blog->view = $viwsQuantity + 1; $blog->updateAttributes(['view']); $coment_model = Comment::find()->where(['blog_id' => $blog->id])->all(); $this->meta = $blog; $prevBlog = Blog::find()->where('id >' . $blog->id)->orderBy('id ASC')->limit(1)->asArray()->all(); $nextBlog = Blog::find()->where('id <' . $blog->id)->orderBy('id DESC')->limit(1)->asArray()->all(); //vd($prevBlog[0]['slug']); return $this->render('views', ['model' => $blog, 'coment_model' => $coment_model, 'nextBlog' => !empty($nextBlog) ? $nextBlog[0]['slug'] : NULL, 'prevBlog' => !empty($prevBlog) ? $prevBlog[0]['slug'] : NULL]); } else { $this->redirect('site/index'); } }
public function getComment($conditions) { return Comment::find()->asArray()->where($conditions)->one(); }
/** * 获取评论数量 * @return int|string */ public function getCommentCount() { return Comment::find()->where(['post_id' => $this->id])->count(); }
public function actionViews($id) { $this->layout = '/blog'; $id = Yii::$app->request->get('id'); $blog = Blog::find()->where(['id' => $id])->one(); $viwsQuantity = (int) $blog->view; $blog->view = $viwsQuantity + 1; $blog->updateAttributes(['view']); $coment_model = Comment::find()->where(['blog_id' => $id])->all(); return $this->render('views', ['model' => $blog, 'coment_model' => $coment_model]); }
public function actionComments($article_id = 0) { if (Yii::$app->request->isAjax) { $comment_id = intval(Yii::$app->request->get('comment_id')); $comment = Comment::find()->where("id = {$comment_id}")->one(); $comment->status = Comment::STATUS_DELETE; $comment->save(); return json_encode(['errCode' => 0]); } $comments = Article::getComments($article_id); return $this->render('comments', ['comments' => $comments]); }
/** * Lists all Comment models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Comment::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * @param integer the maximum number of comments that should be returned * @return array the most recently added comments */ public function findRecentComments($limit = 10) { $query = Comment::find()->where(['status' => Comment::STATUS_ACTIVE])->orderBy('created_at DESC')->limit($limit)->all(); return $query; }