/** * Creates a new Comment model. * For ajax request will return json object * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $request = Yii::$app->request; $model = new Comment(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['code' => '200', 'message' => 'OK', 'data' => $this->renderPartial('create', ['model' => $model])]; } else { if ($model->load($request->post()) && $model->save()) { return ['code' => '200', 'message' => 'Create Comment success']; } else { return ['code' => '400', 'message' => 'Validate error', 'data' => $this->renderPartial('create', ['model' => $model])]; } } } else { /* * Process for non-ajax request */ if ($model->load($request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } }
public function actionAddComment() { $comment = new Comment(); $comment->load(Yii::$app->request->post(), ''); if ($comment->save()) { return $comment; } return $comment->getErrors(); }
/** * 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]); } }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth')); $model = new Comment(); $model->loadDefaultValues(); 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 actionComment($id) { $model = new Comment(); $model->load(Yii::$app->request->post()); $model->article_id = $id; if ($model->validate()) { $model->save(); Yii::$app->session->setFlash("success", "Ок"); } $this->redirect(["article/view", "id" => $id]); }
public function actionView($slug) { $commentForm = new Comment(); if ($commentForm->load(Yii::$app->request->post())) { if ($commentForm->save()) { Yii::$app->session->setFlash('success', '评论发表成功'); } else { Yii::$app->session->setFlash('error', '评论发表失败'); } } return $this->render('view', ['article' => Page::getInstance()->getBySlug($slug), 'commentForm' => $commentForm]); }
/** * 保存商品 */ public function save() { $newComent = new Comment(); $newComent->setAttributes($this->attributes); $newComent->setAttribute('c_type', 'article'); $newComent->setAttribute("c_addtime", date('Y-m-d H:i:s')); if ($newComent->save()) { $logisct_id = \Yii::$app->db->lastInsertID; return $logisct_id; } else { return FALSE; } }
public function actionCreate() { $model = new Comment(); $model->load(\Yii::$app->request->post()); $model->user_id = \Yii::$app->user->id; $returnUrl = \Yii::$app->request->getReferrer(); if ($model->save()) { \Yii::$app->session->setFlash('success', '评论成功!'); } else { \Yii::$app->session->setFlash('error', '评论失败!'); } return $this->redirect($returnUrl); }
/** * Displays homepage. * * @return mixed */ public function actionIndex() { $model = new Comment(); if ($model->load(Yii::$app->request->post())) { $model->is_active = 0; $model->created_at = date('Y-m-d H:i:s'); $model->updated_at = date('Y-m-d H:i:s'); $model->save(); Yii::$app->session->setFlash('success', 'Thank you! Your comment has been added successfully. It will be available after moderation ;)'); return $this->redirect('/'); } return $this->render('comments', ['model' => $model]); }
public function actionAddComment() { $productId = Yii::$app->request->post('productId'); $rank = Yii::$app->request->post('rank'); $content = Yii::$app->request->post('content'); $comment = new Comment(); $comment->attributes = ['product_id' => $productId, 'user_id' => Yii::$app->user->identity->id, 'rank' => $rank, 'content' => $content]; if ($comment->save(true)) { return ['status' => true, 'message' => '成功']; } else { return ['status' => false, 'message' => '失败: ' . Html::errorSummary($comment)]; } }
/** * Creates a new Comment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed * @throws NotFoundHttpException */ public function actionCreate() { $model = new Comment(); if (Yii::$app->request->isGet) { throw new NotFoundHttpException('The requested page does not exist.'); } $model->author_id = Yii::$app->user->id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['../post/view', 'id' => $model->post_id]); } else { return $this->render('../post/view', ['model' => Post::findOne($model->post_id)]); } }
/** * 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 actionView($slug) { $post = Post::findOne(['slug' => $slug]); $comment = new Comment(); $comment->name = ''; $comment->email = ''; $comment->body = ''; if ($comment->load(Yii::$app->request->post())) { $comment->status = 0; if ($comment->save()) { Yii::$app->session->setFlash('success', ['type' => 'success', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'You\'re comment successfully stored and will shown after approval.', 'title' => 'Saving Comment']); } else { Yii::$app->session->setFlash('error', ['type' => 'danger', 'duration' => 12000, 'icon' => 'fa fa-chat', 'message' => 'Sorry but we couldn\'t store your comment.', 'title' => 'Saving Comment']); } } return $this->render('view', ['post' => $post, 'comment' => $comment]); }
/** * @return array * Добавление комментария */ public function actionAddComment() { if (\Yii::$app->request->isAjax) { \Yii::$app->response->format = Response::FORMAT_JSON; $model = new Comment(); $model->user_id = \Yii::$app->user->identity->id; $model->event_id = $_POST['event_id']; $model->message = $_POST['message']; $model->created = time(); if ($model->save()) { if (isset($_POST['notify_all']) && $_POST['notify_all'] == 'true') { EventForm::commenatAllNotification($_POST['event_id'], $_POST['message']); } return ['item' => $model, 'user' => $model->user]; } } }
public function actionDetail($id) { $postModel = new Comment(); if ($postModel->load(Yii::$app->request->post())) { $postModel->status = Comment::STATUS_INACTIVE; $postModel->post_id = $id; if ($postModel->save()) { $this->added = 1; } } $tags = Tag::findTagWeights(); $cateModel = new Cate(); $cateDataProvider = $cateModel->getCates(); $postData = new Post(); $postDataProvider = $postData->findRecentPosts(); $commentModel = new Comment(); $commentDataProvider = $commentModel->findRecentComments(); return $this->render('detail', ['tags' => $tags, 'added' => $this->added, 'postModel' => $postModel, 'model' => $this->findModel($id), 'postDataProvider' => $postDataProvider, 'cateDataProvider' => $cateDataProvider, 'commentDataProvider' => $commentDataProvider]); }
/** * 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 actionAdd() { if (User::thisUser()->reputation < Comment::MIN_REPUTATION_COMMENT_CREATE) { return Yii::$app->getResponse()->redirect(Url::home()); } $anchor = ''; $comment = new Comment(); if ($comment->load(Yii::$app->request->post())) { $comment->description = nl2br($comment->description); $comment->description = \yii\helpers\HtmlPurifier::process($comment->description, []); $comment->entity_id = (int) $comment->entity_id; $comment->parent_id = (int) $comment->parent_id; $comment->user_id = Yii::$app->user->identity->getId(); $comment->like_count = 0; if ($comment->save()) { $anchor = $comment->id; } } return json_encode(['content' => \frontend\widgets\CommentsWidget::widget(['entity' => $comment->entity, 'entity_id' => $comment->entity_id, 'showDialog' => false]), 'anchor' => $anchor]); }
public function actionNewComment() { if ($this->isAjax()) { $model = new Comment(); $model->load($this->getParams()); $validate = $model->validate(); $reCaptcha = new ReCaptcha(); $response = $reCaptcha->check(); if ($validate && $response->isValid() && $model->save(false)) { return $this->getSuccessResponse(['email' => $model->email, 'text' => $model->text]); } else { $res = []; if (!$validate) { $res['modelErrors'] = ActiveForm::validate($model); } if (!$response->isValid()) { $res['reCaptchaError'] = true; } return $res; } } return Yii::$app->params['response']['error']; }
/** * Displays a single Post model. * @param integer $id * @return mixed */ public function actionView($id) { $id = intval($id); $commentmodel = new Comment(); if ($commentmodel->load(Yii::$app->request->post())) { if (Yii::$app->user->isGuest) { //登录后才能评论 Yii::$app->user->returnUrl = Yii::$app->request->getUrl(); //记录登录后要返回的地址 return $this->redirect(['/site/login']); } else { $commentmodel->post_id = $id; $result = $commentmodel->dealContent(Yii::$app->request->post()); if ($result) { $commentmodel->save(); $this->refresh(); } else { Yii::$app->getSession()->setFlash('error', '评论内容过多或盖楼太多,请调整后重新提交评论'); } } } return $this->render('view', ['model' => $this->findModel($id), 'commentmodel' => $commentmodel]); }
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 actionAdd() { $identity = Yii::$app->getUser()->getIdentity(); if (isset($identity->profile)) { //vd($identity->profile); } $comment_id = Yii::$app->request->post('comment_id'); $message = Yii::$app->request->post('message'); if ($message && $message != '') { $model = new Comment(); $model->content = $message; $model->blog_id = $comment_id; $model->author_id = 1; $model->social = $identity ? 1 : 0; $model->social_name = $identity ? $identity->profile['name'] : null; $model->social_avatar = $identity && !empty($identity->profile['photo']) ? $identity->profile['photo'] : null; //$model->validate(); //vd($model->getErrors()); $model->save(); } else { throw new NotFoundHttpException('Пустое сообщение.'); } $arrResult = []; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $arrResult['html'] = $this->renderAjax('_oneAjaxComment', ['model' => $model]); return $arrResult; }
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'; } }
public function actionAjaxAdd() { Yii::$app->response->format = Response::FORMAT_JSON; if (Yii::$app->request->get('product_id') && Yii::$app->request->get('order_id') && Yii::$app->request->get('star') && Yii::$app->request->get('content')) { $model = new Comment(); $model->user_id = Yii::$app->user->id; $model->username = Yii::$app->user->identity->username; $model->product_id = Yii::$app->request->get('product_id'); $model->order_id = Yii::$app->request->get('order_id'); $model->star = Yii::$app->request->get('star'); $model->content = Yii::$app->request->get('content'); if ($model->save()) { return ['status' => 1]; } else { return ['status' => -2]; } } return ['status' => -1]; }
public function actionAdd() { $comment_id = Yii::$app->request->post('comment_id'); $message = Yii::$app->request->post('message'); if ($message && $message != '') { $model = new Comment(); $model->content = $message; $model->blog_id = $comment_id; $model->author_id = Yii::$app->user->id; //$model->validate(); //vd($model->getErrors()); $model->save(); } else { throw new NotFoundHttpException('Пустое сообщение.'); } $arrResult = []; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $arrResult['html'] = $this->renderAjax('_oneAjaxComment', ['model' => $model]); return $arrResult; }
/** * Сохраняет комментарий. * @param Comment $comment модель комментария * @param array $data данные пришедшие из формы * @return bool */ public function save(Comment $comment, array $data) { $isLoad = $comment->load(['pid' => $data['pid'], 'title' => $data['title'], 'content' => $data['content']], ''); return $isLoad && $comment->save(); }
public function actionAddComment() { $this->user_has_login(); $comment = new Comment(); $comment->comment = $this->post['article_comment']; $comment->user_id = $this->post['user']->id; $comment->type_id = $this->post['article_id']; $comment->status = 0; $comment->type = Comment::TYPE_ARTICLE; if ($comment->save()) { return json_encode(Yii::$app->params['ERROR']['SUCCESS']); } }