public function newComment(CommentFormRequest $request)
 {
     $comment = new Comment(array('post_id' => $request->get('post_id'), 'content' => $request->get('content')));
     $comment->save();
     //         return redirect()->back()->with('status', 'Your comment has been created!');
     return redirect()->back()->with('status', 'Your comment has been created!');
 }
Ejemplo n.º 2
0
 public function actionDelete()
 {
     $id = $_GET['id'];
     $comment = new ModelComment();
     $comment->id = $id;
     $comment->delete();
     header('Location: /admin');
 }
Ejemplo n.º 3
0
 /**
  * Post a comment on a blog post
  * POST
  *
  * @param Request $request
  * @param int $id
  * @param string $title
  * @return Response
  */
 public function postComment(Request $request, $id, $title)
 {
     $this->validate($request, ['comment' => 'required']);
     $comment = new BlogCommentManager();
     $comment->author = \Auth::user()->guid;
     $comment->date = date('Y-m-d H:i:s');
     $comment->blog_id = $id;
     $comment->text = nl2br($request->comment);
     $comment->save();
     return redirect()->route('blog.view', [$id, $title]);
 }
Ejemplo n.º 4
0
 public function index()
 {
     //总访问量
     $visits = \Cache::get('visits', 0);
     //今日注册用户
     $todayUsers = User::today()->count('user_id');
     //总用户数
     $totalUsers = User::count('user_id');
     //管理员聊天记录
     $chatMessages = AdminMessage::with('admin')->limit(10)->oldest()->get();
     //最新留言
     $guestBook = GuestBook::with('user')->limit(10)->oldest()->get();
     //最新注册用户
     $users = User::limit(24)->oldest()->get();
     //最新评论
     $comments = Comment::limit(10)->oldest()->get();
     // 总会员数量/待审核会员/普通会员/高端会员
     $user_all_num = User::count('user_id');
     $user_shenhe_num = User::status(\App\Enum\User::STATUS_CHECK)->count('user_id');
     $user_level1_num = User::level(\App\Enum\User::LEVEL_1)->count('user_id');
     $user_level3_num = User::level(\App\Enum\User::LEVEL_3)->count('user_id');
     // 自我介绍待审核数量
     $user_info_num = UserInfo::where('introduce_status', \App\Enum\User::INTRODUCE_CHECK)->count('user_id');
     // 会员相片审核数量
     $user_gallery_num = DB::table('user_gallery')->where('status', '待审核')->where('image_url', '!=', '')->count('photo_id');
     // 文章数量
     $article_num = DB::table('articles')->count('article_id');
     $res = array('user_all_num' => $user_all_num, 'user_shenhe_num' => $user_shenhe_num, 'user_level1_num' => $user_level1_num, 'user_level3_num' => $user_level3_num, 'user_info_num' => $user_info_num, 'user_gallery_num' => $user_gallery_num, 'article_num' => $article_num);
     return $this->view('index', $res);
     // return $this->view('index')->with('visits', $visits)->with('todayUsers', $todayUsers)->with('totalUsers',
     //         $totalUsers)->with('chatMessages', $chatMessages)->with('guestBook', $guestBook)->with('users',
     //         $users)->with('comments', $comments);
 }
 public function addComment(\app\model\Comment $comment)
 {
     $successfulComment = false;
     $comments = $this->getAllComments();
     try {
         $db = $this->db->getConnection();
         $sql = "INSERT INTO {$this->dbTable} (" . self::$commenterColumn . ", " . self::$contentColumn . ", " . self::$venueIdentifierColumn . ", " . self::$timeStampColumn . ") VALUES (?, ?, ?, ?)";
         $params = array($comment->getName(), $comment->getContent(), $comment->getVenueIdentifier(), $comment->getTimeStamp());
         $query = $db->prepare($sql);
         $query->execute($params);
         $successfulComment = true;
     } catch (\PDOException $e) {
         die("Database error, please try again later");
     }
     return $successfulComment;
 }
Ejemplo n.º 6
0
    private function saveComment($request)
    {
        $comment = new Comment();
        $user = $this->userSession->getUser();
        $user = $this->em->find("App\Model\User", $user->getId());
        $comment->setUser($user);
        $comment->setComment($request->get('comment'));
        $post = $this->em->find("App\Model\Post", $request->get('postId'));
        $post->setCommentsNum($post->getCommentsNum()+1);
        $comment->setPost($post);
        $comment->setPostedAt(new \DateTime('now'));
        $this->em->persist($comment);
        $this->em->flush();

        return $comment;
    }
Ejemplo n.º 7
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $data = \Request::all();
     $data['user_id'] = \Auth::user()->id;
     $result = \App\Model\Comment::create($data);
     return back()->with('name', 'comment');
 }
Ejemplo n.º 8
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Comment $result)
 {
     $attributes = $result->all();
     $attributes['type_id'] = 0;
     if (!captcha_check($attributes['captcha'])) {
         Notification::error('验证码错误');
         return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList'])->withInput();
     }
     unset($attributes['captcha']);
     if (Session::token() !== $attributes['_token']) {
         Notification::error('token错误');
         return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList'])->withInput();
     }
     unset($attributes['_token']);
     try {
         $attributes['content'] = htmlspecialchars($attributes['content']);
         CommentModel::create($attributes);
         ArticleStatus::updateCommentNumber($attributes['el_id']);
         Notification::success('评论成功');
         return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList']);
     } catch (\Exception $e) {
         Notification::error($e->getMessage());
         return redirect()->route('article.show', ['id' => $attributes['el_id'], '#commentList'])->withInput();
     }
 }
Ejemplo n.º 9
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (Comment::create(Input::all())) {
         return Redirect::back();
     } else {
         return Redirect::back()->withInput()->withErrors('评论发表失败!');
     }
 }
Ejemplo n.º 10
0
 public function actionIndex()
 {
     $view = new View();
     $view->title = 'Blog | Admin';
     //        $comments = Comment::getAll();
     $view->comments = Comment::getAll();
     $view->users = User::getAll();
     $view->displayPage('admin/index');
 }
Ejemplo n.º 11
0
 public function actionOne()
 {
     $id = $_GET['id'];
     // If a comment has been sent:
     if ($this->isPost()) {
         $comm = new ModelComment();
         // fields cannot be empty!
         $success = $comm->fill(['article_id' => $id, 'author' => htmlspecialchars($_POST['author']), 'text' => htmlspecialchars($_POST['text'])]);
         $success ? $comm->save() : ($_SESSION['error'] = 'Fill all fields!');
         header('Location: /article/one?id=' . $id . '#comment');
         exit;
     }
     // Getting the particular article:
     $item = ModelArticle::getOneById($id);
     $this->isFound($item);
     $comments = ModelComment::getByColumn('article_id', $id);
     $view = new View(['item' => $item, 'comments' => $comments, 'title' => $item->title]);
     $view->displayPage('articles/one');
 }
Ejemplo n.º 12
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $article = Article::getArticleModelByArticleId($id);
     $tags = Tag::getTagModelByTagIds($article->tags);
     $authorArticle = Article::getArticleModelByUserId($article->user_id);
     $commentList = Comment::getCommentListModel($id);
     $data = array('article' => $article, 'tags' => $tags, 'authorArticle' => $authorArticle, 'commentList' => $commentList);
     viewInit();
     return homeView('article', $data);
 }
 /**
  * Handle the event.
  *
  * @param  CommentSendEmail  $event
  * @return void
  */
 public function handle(CommentSendEmail $event)
 {
     //
     if ($event->parentId != 0) {
         $parent = Comment::find($event->parentId);
         if (!empty($parent)) {
             Mail::send('emails.comment', ['username' => $parent->username, 'id' => $parent->el_id], function ($message) use($parent) {
                 $message->to($parent->email, $parent->username)->subject('您的评论被回复了');
             });
         }
     }
 }
Ejemplo n.º 14
0
 public function show($id)
 {
     if (is_null($id)) {
         return view('errors.404');
     }
     $post = Post::with('user')->find($id);
     if (!$post) {
         return view('errors.404');
     }
     $comments = Comment::with('user')->where('post_id', $id)->orderBy('created_at', 'desc')->paginate(5);
     $this->viewData['post'] = $post;
     $this->viewData['comments'] = $comments;
     return view('posts.show', $this->viewData);
 }
Ejemplo n.º 15
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->ajax()) {
         $result = ['html' => '', 'msg' => 'Something went wrong', 'success' => false];
         $input = $request->input();
         $validation = Validator::make($request->all(), Comment::$validation, Comment::$messages);
         if ($validation->fails()) {
             $errors = $validation->messages();
             $result['msg'] = get_message_from($errors);
             return response()->json($result);
         }
         $input['user_id'] = $this->currentUser->id;
         $comment = Comment::create($input);
         if (!$comment) {
             $result['msg'] = 'Can not post your comment';
         } else {
             $result = ['html' => view('comments._a_comment', ['comment' => $comment])->render(), 'msg' => 'Posted your comment', 'success' => true];
         }
         return response()->json($result);
     }
 }
Ejemplo n.º 16
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $comment = Comment::find($id);
     $comment->delete();
     return Redirect::to('admin/comments');
 }
 public function getAnswerDetail()
 {
     $request = Request::capture();
     $token = $request->input('token');
     $answerId = $request->input('answerId');
     $userId = AuthController::getUserIdByToken($token);
     if ($userId == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_AUTH_ERROR, '', '认证失败');
     }
     if ($answerId == null) {
         return Utility::response_format(Utility::RESPONSE_CODE_Error, '', 'answerId不能为空');
     }
     $answer = Answer::select('id', 'answer_content', 'answer_time', 'question_id', 'user_id', 'is_resolved')->where('id', $answerId)->first()->toArray();
     //        print_r($question);
     // 个人信息
     $userInfo = UserInfo::select('user_name', 'head_pic')->where('user_id', $answer['user_id'])->first()->toArray();
     $answer = array_merge($answer, $userInfo);
     // 图片
     $picIds = AnswerPictures::select('pic_id')->where('answer_id', $answer['id'])->get()->toArray();
     $pics = Picture::whereIn('id', $picIds)->get()->toArray();
     $answer = array_merge($answer, ['image' => $pics]);
     // 评论数
     $comments = Comment::where('answer_id', $answer['id'])->count();
     $answer = array_merge($answer, ['commentNumber' => $comments]);
     // 赞数
     $upCount = AnswerUp::where('answer_id', $answer['id'])->count();
     $answer = array_merge($answer, ['upNumber' => $upCount]);
     return Utility::response_format(Utility::RESPONSE_CODE_SUCCESS, $answer, '请求成功');
 }
Ejemplo n.º 18
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $comment = Comment::where('page_id', $id)->delete();
     $page = Page::find($id)->delete();
     return Redirect::to('admin');
 }
Ejemplo n.º 19
0
 /**
  * 显示评论列表页
  * @return $this
  */
 public function index()
 {
     $models = Comment::all(['comment_id', 'content', 'user_id', 'article_id', 'created_at']);
     $models->load(['user', 'article']);
     return $this->view('index')->with('models', $models);
 }
Ejemplo n.º 20
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  * Xóa một comment
  */
 public function destroy($id)
 {
     Comment::destroy($id);
     return Response::json(array('success' => true));
 }
 public function removeCMTAction()
 {
     return Comment::removeCmt($_POST['id']);
 }
Ejemplo n.º 22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     if (Comment::destroy($id)) {
         Notification::success('删除成功');
     } else {
         Notification::success('删除失败');
     }
     return redirect()->back();
 }
 public function singleAction($id)
 {
     if ($entry = Entry::findOrFail($id)) {
         if ($postData = $this->getPostData()) {
             $postData['entry_id'] = $id;
             Comment::create($postData);
             return $this->redirect('singleEntry', array('id' => $id));
         }
         $entry['username'] = User::where('id', strval($entry['user_id']))->first()['name'];
         $data['entry'] = $entry;
         $data['comments'] = Comment::where('entry_id', $id)->get();
     } else {
         $data['error'] = 'Không tìm thấy bài viết';
     }
     return $this->render('entry/single.html.twig', $data);
 }
Ejemplo n.º 24
0
 public function removeCmt($id)
 {
     return Comment::where('id', $id)->delete();
 }
Ejemplo n.º 25
0
 public function testHasManySave()
 {
     $user = User::read(3);
     $comment1 = Comment::create(['text' => 'create']);
     $comment2 = Comment::newRecord(['text' => 'new record']);
     $user->Comment[] = $comment1;
     $user->Comment[] = $comment2;
     $this->assertEquals(true, $user->save());
     $this->assertEquals($user->id, $comment1->user_id);
     $this->assertEquals($user->id, $comment2->user_id);
     $this->assertEquals('create', $user->Comment[0]->text);
     $this->assertEquals('new record', $user->Comment[1]->text);
     /*
     *	本当に保存できたかreadで確認
     */
     $savedComment1 = Comment::read($user->Comment[0]->id);
     $savedComment2 = Comment::read($user->Comment[1]->id);
     $this->assertEquals('create', $savedComment1->text);
     $this->assertEquals('new record', $savedComment2->text);
     $this->assertEquals($user->id, $savedComment1->user_id);
     $this->assertEquals($user->id, $savedComment2->user_id);
 }