public function actionView($id) { $note = Note::find()->where(['id' => $id])->with('comments')->with('user')->one(); if (!$note) { throw new NotFoundHttpException(); } if (Yii::$app->user->can('viewNote', ['note' => $note])) { $query = Note::find()->with('user'); $previousNote = $query->where(['<=', 'created_at', $note->created_at])->andWhere(['<', 'id', $note->id])->andWhere(['visibility' => Note::VIS_PUBLIC_LISTED])->orderBy('created_at DESC, id DESC')->one(); $nextNote = $query->where(['>=', 'created_at', $note->created_at])->andWhere(['>', 'id', $note->id])->andWhere(['visibility' => Note::VIS_PUBLIC_LISTED])->orderBy('created_at ASC, id ASC')->one(); $comment = new Comment(); if ($comment->load(Yii::$app->request->post()) && $comment->validate()) { $parentId = Yii::$app->request->post('parentId'); if ($parentId !== null && CommentClosure::find()->where(['child_id' => $parentId])->max('depth') >= Yii::$app->params['maxCommentsDepth']) { throw new ForbiddenHttpException(); } $comment->user_id = Yii::$app->user->getId(); $comment->note_id = $note->id; $comment->save(false); CommentClosure::insertComment($comment->id, $parentId); return $this->refresh(); } return $this->render('view', ['note' => $note, 'previousNote' => $previousNote, 'nextNote' => $nextNote, 'comment' => $comment]); } else { throw new ForbiddenHttpException(); } }
/** * Displays a single Post model. * * @param integer $id * @return mixed */ public function actionView($slug) { try { Yii::trace('Trace :' . __METHOD__, __METHOD__); $model = Post::find()->where(['slug' => $slug])->one(); if ($model === null) { throw new NotFoundHttpException(); } $response = null; $commentForm = new Comment(['scenario' => 'create']); if ($commentForm->load($_POST) === true && $commentForm->validate() === true) { $commentForm->created = Yii::$app->formatter->asDateTime('now', 'php:Y-m-d H:i:s'); $commentForm->post_id = $model->id; if ($commentForm->save() === true) { $response = $this->redirect(['/post/view', 'slug' => $slug]); } } //get all comments $comments = $model->getComments()->orderBy('created DESC')->all(); if ($response === null) { $response = $this->render('view', ['model' => $model, 'comments' => $comments, 'commentForm' => $commentForm]); } return $response; } catch (Exception $e) { Yii::error($e->getMessage(), __METHOD__); throw $e; } }
/** * Displays a single Journal model. * @param integer $id * @return mixed */ public function actionView($id) { //var_dump($notify); die(); $searchModel = new JournalSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $model = $this->findModel($id); $comment = new Comment(); $comment->user_id = \Yii::$app->user->id; $commentProvider = new ActiveDataProvider(['query' => Comment::find()->where(['journal_id' => $id])]); Yii::$app->notification->viewer($id); if ($comment->load(Yii::$app->request->post())) { $comment->journal_id = $id; $comment->time = date('Y-m-d H:i:s'); if ($comment->save()) { Yii::$app->notification->notify($model->entry, $model, $comment->user, 'comment', $model->shared_with . ',' . $model->user_id); Yii::$app->session->setFlash('success', 'Comment posted successfully.'); return Yii::$app->getResponse()->redirect(array('/journal/view/' . $model->id)); } else { exit; } } else { if (Yii::$app->request->isAjax) { return $this->renderAjax('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]); } else { return $this->render('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]); } } }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comment(); if ($model->load(Yii::$app->request->post())) { $model->save(); } return $this->redirect(['article/view', 'id' => $model->article_id]); }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionView($id) { $article = $this->findModel($id); $model = new Comment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->request->referrer; } return $this->render('view', ['model' => $model]); }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionMypath() { $model = new Comment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', '添加评论成功'); return $this->redirect(['route/view', 'id' => $model->route_id]); } else { Yii::$app->getSession()->setFlash('error', '添加评论失败'); } }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Comment(); $createdAt = time(); $model->created_at = $createdAt; $model->updated_at = $createdAt; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['post/view', 'id' => $model->post_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($shop_id) { $model = new Comment(); if ($model->load(Yii::$app->request->post())) { $model->author_id = Yii::$app->user->identity->id; $model->user_id = $shop_id; if ($model->save()) { return $this->goBack(); } } else { } return $this->render('create', ['model' => $model]); }
/** * Displays a post detail. * @param integer $id * @return mixed */ public function actionDetail($id) { $postModel = new Comment(); if ($postModel->load(Yii::$app->request->post())) { $postModel->status = Comment::STATUS_PENDING; $postModel->post_id = $id; if ($postModel->save()) { $this->added = 1; } } $tags = Tag::findTagWeights(Yii::$app->params['tagCloudCount']); $commentModel = new Comment(); $commentDataProvider = $commentModel->findRecentComments(Yii::$app->params['recentCommentCount']); //Yii::$app->params['recentCommentCount'] return $this->render('detail', ['model' => $this->findModel($id), 'commentDataProvider' => $commentDataProvider, 'tags' => $tags, 'postModel' => $postModel, 'added' => $this->added]); }
public function actionReply($id) { $request = Yii::$app->getRequest(); $me = Yii::$app->getUser()->getIdentity(); $topic = $this->findTopicModel($id, ['node', 'author']); if (!$me->canReply($topic)) { throw new ForbiddenHttpException('您没有权限回复或此主题已关闭回复。'); } $model = new Comment(); if ($model->load($request->post()) && $model->validate()) { $model->user_id = $me->id; $cid = new \app\models\Commentid(['id' => null]); $cid->save(false); $model->id = $cid->id; $model->link('topic', $topic); $this->redirect(Topic::getRedirectUrl($id, $model->position)); } return $this->render('add', ['comment' => $model, 'topic' => Util::convertModelToArray($topic)]); }
/** * @param $slug * @return string * @throws NotFoundHttpException */ public function actionView($slug) { $product = Catalog::product($slug); if (!$product) { throw new NotFoundHttpException(); } $comment = new Comment(); if (!\Yii::$app->user->isGuest && $comment->load(\Yii::$app->request->post())) { $comment->user_id = \Yii::$app->user->id; $comment->status = Comment::STATUS_ACTIVE; $product->model->link('comments', $comment); } $wishListModel = new AddToWishListForm(); $wishList = WishList::get(); if ($wishListModel->load(\Yii::$app->request->post())) { $wishList->add($product->model->id); } $category = Catalog::cat($product->model->category_id); return $this->render('view', ['product' => $product, 'category' => $category, 'wishListModel' => $wishListModel, 'inWishList' => $wishList->has($product->model->id)]); }
public function actionCommentAjax($id) { $model = new Comment(); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->params['commentNeedApproval']) { $model->type = 0; } else { $model->type = 1; } $model->status = 1; $model->post_id = $id; if ($model->save()) { if (isset($model->user)) { $username = $model->user->username; $avatar = $model->user->avatar; $url = Url::to(['user/view', 'id' => $model->user_id]); } else { $username = $model->author ? $model->author : "游客"; $avatar = Yii::$app->homeUrl . "upload/avatar/default.png"; $url = "javascript:;"; } if ($model->parent_id) { $li = '<li class="media">'; $endli = '</li>'; } else { $li = ''; $endli = ''; } echo Json::encode($li . '<div class="media"><a class="pull-left" href="' . $url . '"> <img class="media-object img-circle" alt="' . Html::encode($username) . '" src="' . $avatar . '" style="width: 48px; height: 48px;"> </a> <div class="media-body"> <h4 class="media-heading"><a href="' . $url . '">' . Html::encode($username) . '</a> • <span title="' . date("Y-m-d H:i:s", $model->create_time) . '">' . Common::formatTime($model->create_time) . '</span></h4> <p>' . Html::encode($model->content) . '</p><div class="ops"><a href="" class="comment-up" data-id="' . $model->id . '"><i class="glyphicon glyphicon-thumbs-up"></i> (<span>0</span>)</a> <a href="" class="comment-down" data-id="' . $model->id . '"><i class="glyphicon glyphicon-thumbs-down"></i> (<span>0</span>)</a> <a href="" class="comment-reply" data-id="' . $model->id . '" data-postid="' . $id . '" title="回复"><i class="glyphicon glyphicon-share-alt"></i></a></div>' . $endli); } else { echo "0"; } } else { echo "0"; } Yii::$app->end(); }
/** * Creates a new comment. * This method attempts to create a new comment based on the user input. * If the comment is successfully created, the browser will be redirected * to show the created comment. * @param News the news that the new comment belongs to * @return Comment the comment instance */ protected function newComment($model) { $comment = new Comment(); if ($comment->load(Yii::$app->request->post())) { /**验证通过***/ $comment->attributes = $_POST['Comment']; if (Yii::$app->user->isGuest) { return $comment; } else { $comment->author_id = Yii::$app->user->id; //评论者的id $comment->author_name = Yii::$app->user->getIdentity()->username; //评论者的名称 $comment->create_time = date("Y-m-d H:i:s", time()); if (Yii::$app->user->getIdentity()->role == 1) { $comment->status = 1; } else { $comment->status = 2; } //待审核 //$comment->post_id = $model->id;//文章id $comment->user_id = $model->author_id; //文章作者id $comment->classify_type = Humour::getClassName(); //分类 $comment->comment_parent_id = '0'; } if ($comment->author_id === '') { Yii::$app->Session->setFlash('commentSubmitted', '请先登录'); $this->refresh(); exit; } $comment->content = $_POST['Comment']['content']; if ($model->addComment($comment)) { if ($comment->status == Comment::STATUS_PENDING) { Yii::$app->Session->setFlash('commentSubmitted', '评论会在审核通过后显示。'); } $this->refresh(); } } return $comment; }
/** * addOrUpdateComment. * * Updates or creates a Comment * * @param array $comment * * @return Comment $obj with User relationship loaded */ public function addOrUpdateComment(array $comment) { $obj = new Comment(); $obj->text = $comment['text']; $obj->user_id = $comment['user']['id']; $obj->doc_id = $this->doc_id; if (isset($comment['id'])) { $obj->id = $comment['id']; } $obj->parent_id = $this->id; $obj->save(); $obj->load('user'); return $obj; }
public function actionView($id) { $news = $this->findModel($id); $commentForm = new Comment(); $commentForm->news_id = $news->id; if ($commentForm->load(Yii::$app->request->post()) && $commentForm->save()) { return $this->refresh('#c' . $commentForm->id); } return $this->render('view', ['model' => $news, 'commentForm' => $commentForm]); }