예제 #1
0
 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();
     }
 }
예제 #2
0
 /**
  * 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]);
         }
     }
 }
예제 #4
0
 /**
  * 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]);
 }
예제 #5
0
 public function binhluan(BinhLuanRequest $request, $id, $xe_id)
 {
     $binhluan = new Comment();
     $binhluan->xe_id = $xe_id;
     $binhluan->nguoidung_id = $id;
     $binhluan->noidung = $request->txtbinhluan;
     $binhluan->save();
     return redirect()->route('chitietsp', $xe_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]);
     }
 }
예제 #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function addComment($tour_id)
 {
     $comment = new Comment();
     $comment->id_tour = $tour_id;
     $comment->id_user = Yii::$app->user->id;
     $comment->comment = $this->comment;
     $comment->date = date('Y-m-d h:m:s');
     $comment->save(false);
 }
예제 #8
0
 public function store(Request $request)
 {
     $comment = new Comment();
     $comment->fill($request->all());
     $comment->user_id = Auth::user()->id;
     $comment->recipe_id = $request->get('recipe_id');
     $comment->save();
     return Comment::with('author')->where('id', $comment->id)->first();
 }
예제 #9
0
 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]);
 }
예제 #10
0
 /**
  * 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', '添加评论失败');
     }
 }
예제 #11
0
 public function postIndex($doc)
 {
     $comment = Input::get('comment');
     $newComment = new Comment();
     $newComment->user_id = Auth::user()->id;
     $newComment->doc_id = $comment['doc']['id'];
     $newComment->text = $comment['text'];
     $newComment->save();
     // Late load the user.
     $newComment->user;
     return Response::json($newComment->toArray());
 }
예제 #12
0
 /**
  * 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]);
     }
 }
예제 #13
0
 /**
  * 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]);
 }
예제 #14
0
 public function actionCreate()
 {
     $data = $_POST['data'];
     $time = time();
     $data['create_at'] = $time;
     $data['user_id'] = User::getCurrentId();
     $comment = new Comment();
     $comment->attributes = $data;
     $post = new Post();
     $post->updateAll(['reply_at' => $time, 'last_reply_id' => $data['user_id']], 'id=:id', [':id' => $data['post_id']]);
     $comment->save();
     $this->redirect(array('/post/view', 'id' => $data['post_id']));
 }
 /**
  * Seeds the table.
  *
  * @return void
  */
 public function run()
 {
     /** @var Post $post */
     $post = Post::firstOrFail();
     $comment = new Comment();
     $comment->body = 'First!';
     $comment->post_id = $post->id;
     $comment->save();
     $comment = new Comment();
     $comment->body = 'I like XML better';
     $comment->post_id = $post->id;
     $comment->save();
 }
예제 #16
0
 public function create()
 {
     $newcomment = new Comment($_POST);
     // $newcomment['user_id'] = static::$auth->user()->id;
     if (!$newcomment->isValid()) {
         $_SESSION['comment.form'] = $newcomment;
         header("Location:.\\?page=recipe&id=" . $newcomment->id);
         exit;
     }
     $newcomment->save();
     echo 'here';
     header("Location:.\\?page=recipe&id=" . $newcomment->id . "#comment-" . $newcomment->id);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['content' => 'required']);
     $comment = new Comment();
     $comment->post_id = Input::get('post_id');
     $comment->type = Input::get('type');
     $comment->content = Input::get('content');
     $comment->user_id = Auth::user()->id;
     if ($comment->save()) {
         return Redirect::to('admin/comments');
     } else {
         return Redirect::back()->withInput()->withErrors('保存失败!');
     }
 }
 public function create()
 {
     $input = $_POST;
     $input['user_id'] = static::$auth->user()->id;
     $newcomment = new Comment($input);
     if (!$newcomment->isValid()) {
         // echo "here";
         $_SESSION['comment.form'] = $newcomment;
         header("Location:.\\?page=movie&id=" . $newcomment->movie_id);
         exit;
     }
     $newcomment->save();
     header("Location: ./?page=movie&id=" . $newcomment->movie_id . "#comment-" . $newcomment->id);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $content = $this->getDocument();
     $attributes = array_get($content, 'data.attributes', []);
     $attributes['post_id'] = array_get($content, 'data.links.author.linkage.id', null);
     $rules = ['body' => 'required', 'post_id' => 'required|integer'];
     $validator = Validator::make($attributes, $rules);
     if ($validator->fails()) {
         throw new BadRequestHttpException();
     }
     $comment = new Comment($attributes);
     $comment->save();
     return $this->getCreatedResponse($comment);
 }
예제 #20
0
 /**
  * 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]);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $this->checkParametersEmpty();
     $content = $this->getDocument();
     $attributes = array_get($content, 'data.attributes', []);
     $attributes['post_id'] = array_get($content, 'data.relationships.post.data.id', null);
     /** @var \Illuminate\Validation\Validator $validator */
     $rules = ['body' => 'required', 'post_id' => 'required|integer'];
     $validator = Validator::make($attributes, $rules);
     if ($validator->fails()) {
         throw new ValidationException($validator);
     }
     $comment = new Comment($attributes);
     $comment->save();
     return $this->getCreatedResponse($comment);
 }
예제 #22
0
 public function postSaveComment(Request $request)
 {
     $comment_name = $request->get("comment_name");
     $comment_email = $request->get("comment_email");
     $comment_content = $request->get("comment_content");
     $blog_id = $request->get("blog_id");
     $comment = new Comment();
     $comment->comment_name = $comment_name;
     $comment->comment_email = $comment_email;
     $comment->comment_content = $comment_content;
     $comment->comment_create = date("Y/m/d");
     $comment->comment_blogs_id = $blog_id;
     $comment->save();
     $message = "Saved";
     return redirect('/news/detail/' . $blog_id)->withMessage($message);
 }
예제 #23
0
 /**
  * Displays a single Items model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $commentsData = comment::getComments($id);
     $model = $this->findModel($id);
     $newComment = new Comment();
     $addToBasket = new basket();
     $description = new Description();
     $description->find()->where(['item_id' => $id])->all();
     $itemRating = ItemsRating::findOne($id);
     if ($model->count == 0) {
         Yii::$app->db->createCommand(" UPDATE `items` SET items.is_aviable=0 WHERE items.id =" . $id)->execute();
     } else {
         if (!Yii::$app->user->isGuest) {
             $uid = Yii::$app->user->identity->getId();
             $get_user = \dektrium\user\models\User::getUser($uid)->getModels()[0]['username'];
             if (isset($_POST['Comment'])) {
                 //            print_r($_POST['Comment']['text']);
                 $newComment = new Comment();
                 $newComment->author = $get_user;
                 $newComment->item_id = $id;
                 $newComment->user_id = $uid;
                 $newComment->date = date("Y-m-d h:i:s");
                 $newComment->text = $_POST['Comment']['text'];
                 $newComment->save();
             }
             if (isset($_POST['Basket'])) {
                 if ($model->is_aviable) {
                     if ($_POST['Basket']['count'] <= $model->count) {
                         $addToBasket = new Basket();
                         $have = $addToBasket->find()->where(['item_id' => $id, 'user_id' => $uid])->all();
                         if (!$have) {
                             $addToBasket->item_id = $id;
                             $addToBasket->user_id = $uid;
                             $addToBasket->name = $model->name;
                             $addToBasket->price = $model->price;
                             $addToBasket->count = $_POST['Basket']['count'];
                             $addToBasket->sum = $model->price * $_POST['Basket']['count'];
                             $addToBasket->save();
                         }
                     }
                 }
                 return $this->redirect(['view', 'id' => $id]);
             }
         }
     }
     return $this->render('view', ['model' => $model, 'commentsData' => $commentsData, 'newComment' => $newComment, 'itemRating' => $itemRating, 'addToBasket' => $addToBasket, 'description' => $description]);
 }
예제 #24
0
 /**
  * Добавление нового комментария
  * @param  integer $id   Идентификатор задания, которому принадлежит комментарий
  * @param  string $text  Текст комментария 
  * @return redirect      После выполнения редиректит на главную.
  */
 public function actionNew($id, $text)
 {
     //Определение текущего языка
     SiteController::locale();
     //Определение полей для заполнения
     $comment = new Comment();
     $comment->task_id = $id;
     $comment->text = $text;
     $comment->date = date('Y-m-d H:i:s');
     //В зависимости от успеха сохранения, пишет в память сообщение от успехе или лог ошибок
     if ($comment->save()) {
         Yii::$app->session->setFlash('success', Yii::t('msg/msg', 'Комментарий добавлен'));
     } else {
         Yii::$app->session->setFlash('errors', $comment->errors);
     }
     return $this->redirect("/");
 }
예제 #25
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['nickname' => 'required|max:30', 'content' => 'required|max:255', 'articleid' => 'required|numeric', 'email' => 'required']);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $comment = new Comment();
     $comment->nickname = $request->input('nickname');
     $comment->content = $request->input('content');
     $comment->email = $request->input('email');
     $comment->articleid = $request->input('articleid');
     if ($comment->save()) {
         return Redirect::back();
     } else {
         return Redirect::back()->withInput()->withErrors('评论发表失败!');
     }
 }
예제 #26
0
 /**
  * 保存评论数据
  * @param $data
  * @return array
  * @throws CommentApiException
  */
 public function save($data)
 {
     $must = array("fid", "user_id", "nickname", "content", "ip");
     //必须要存在的字段
     foreach ($must as $val) {
         if (isset($data[$val]) == false) {
             throw new CommentApiException($val . "不能为空~!");
         }
     }
     if ($data["user_id"] < 1) {
         throw new CommentApiException("错误的user_id" . $data["user_id"]);
     }
     //        if (isset($data["star"]) && empty($data["star"]) == false) {
     //            $extendData["star"] = $data["star"];
     //        }
     $data["content"] = $this->filterContent($data["content"]);
     //对于评论内容的合法性检查
     $data["created_time"] = time();
     //发布时间
     $this->isBan($data["user_id"], $data["ip"]);
     //检测用户是否被禁言
     //盖楼处理
     $data = array_merge($data, $this->processLevelAndPath($data["fid"]));
     //保存评论
     $comment = new Comment($data);
     if ($comment->save() == false) {
         throw new CommentApiException("评论保存失败~!");
     }
     $result = array();
     //保存要返回的数据
     //        //处理扩展数据
     //        $extendData = array();//扩展数据
     //        if (isset($data["top"]) && empty($data["top"]) == false) {
     //            $extendData["top"] = $data["top"];
     //        }
     //
     //        if (empty($extendData) == false) {
     //            //创建
     //            $extendData["id"] = $comment->id;
     //            $extend = new Extend($extendData);
     //            if ($extend->save() == false) {
     //                throw new CommentApiException("评分信息保存失败~!");
     //            }
     //        }
     return $result;
 }
예제 #27
0
 /**
  * If the user is blocked - he is not able to leave a comment
  * @param CommentFormRequest $request Request
  * @return type Redirect
  */
 public function addComment(CommentFormRequest $request)
 {
     $ip = $request->getClientIp();
     $blacklisted = Firewall::isBlacklisted($ip);
     if ($blacklisted) {
         Flash::warning('Sorry, you have been blocked and you can\'t leave comments right now');
         return Redirect::route('comments');
     } else {
         $newMessage = new Comment();
         $newMessage->comment = $request->get('comment');
         $newMessage->name = $request->get('name');
         $newMessage->email = $request->get('email');
         $newMessage->ip = $ip;
         $newMessage->save();
         Flash::success('Thank you for your opinion!');
         return Redirect::route('comments');
     }
 }
예제 #28
0
 public function store()
 {
     $comment = new Comment();
     $comment->author_nickname = Input::get('nickname');
     $comment->author_email = Input::get('email');
     $comment->author_ip = \Request::getClientIp();
     $comment->text = Input::get('content');
     $comment->article_id = Input::get('article_id');
     $comment->parent_id = Input::get('p_id');
     $comment->created_at = Carbon::now();
     if ($comment->save()) {
         $article = Article::find($comment->article_id);
         $article->setUpdatedAt(Carbon::now());
         $article->save();
         return Redirect::back();
     } else {
         return Redirect::back()->withInput()->withErrors('评论发表失败!');
     }
 }
예제 #29
0
 public function post(Request $request)
 {
     if (Auth::user()) {
         $rules = ['article_id' => 'required|integer', 'parent_id' => 'required|integer', 'content' => 'required|max:255'];
         $data = ['article_id' => $request->input('articleId'), 'parent_id' => $request->input('parent_id'), 'content' => $request->input('comment')];
         if (validate::make($data, $rules)) {
             $model = new Comment($data);
             $model->author = Auth::user()->name;
             $model->user_id = AUth::user()->id;
             if ($model->save()) {
                 return redirect()->back()->with('success', 'comment succeed');
             } else {
                 return redirect()->back()->with('error', 'something wrong occurred,please fill in again')->withInput();
             }
         } else {
         }
     } else {
         return redirect()->back()->with('error', "you haven't logged in yet")->withInput();
     }
 }
예제 #30
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param Article $article
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request, Article $article)
 {
     $comment = new Comment();
     $comment->comment_content = $request->get('comment_content');
     $comment->username = Auth::user()->username;
     /** @var \App\Models\ContentBase $contentBase */
     $contentBase = ContentBase::create(['content_type' => 2]);
     $comment->comment_id = $contentBase->content_id;
     $parent = $request->get('parent_comment');
     if ($parent) {
         $comment->content_id = $parent;
     } else {
         $comment->content_id = $article->content->content_id;
     }
     $comment->save();
     if ($request->ajax()) {
         return response()->json($comment);
     }
     return response('');
 }