/**
  * @param Request $request
  * @param $comment_id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function update(Request $request)
 {
     $comment_id = $request->input('comment_id');
     $comment = Comments::where('id', $comment_id)->first();
     $user = $request->user();
     if ($user->is_admin() or $user->is_moderator() or $user->id == $comment->user_id) {
         $content = $request->input('content');
         $comment->content = $content;
         $comment->save();
         $product = Products::where('id', $comment->on_product)->first();
         return redirect('/product/' . $product->slug);
     } else {
         redirect('/')->withErrors('You have not sufficient permissions');
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $coms = new Comments();
     $coms->content = $request->input('content');
     $coms->mem_id = $request->input('mem_id');
     $coms->pro_id = $request->input('pro_id');
     $coms->save();
 }
 public function addComment(Request $request)
 {
     $newComment = new Comments();
     $newComment->body = $request->body;
     $newComment->post_id = $request->post_id;
     $newComment->save();
     return $newComment;
 }
Exemplo n.º 4
0
 public function addComment(Request $request)
 {
     $comments = new Comments();
     $comments->from_user = \Auth::user()->id;
     $comments->on_post = $request->input('on_post');
     $comments->body = $request->get('body');
     $comments->save();
     return redirect('profilePage');
 }
Exemplo n.º 5
0
 public function new_comment(Request $request, $id)
 {
     $comment_postID = $id;
     $comment_data = $request->input('comment_content');
     if ($request->ajax()) {
         $com = new Comments();
         $com->post_id = $comment_postID;
         $com->comment_content = $comment_data;
         $com->save();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $comment = new Comments();
     $comment->user_id = $request->user()->id;
     // obezbedena avtentikacija ?
     $comment->post_id = $request->get('post_id');
     // ->post_id
     $comment->message = $request->get('message');
     $comment->save();
     // return redirect('home')->with('message', 'Comment is succesfully published');
 }
Exemplo n.º 7
0
 public function newComment(Request $request)
 {
     if (Auth::guest()) {
         return Redirect::to('/auth/login');
     } else {
         $comment = new Comments();
         $comment->user_id = Auth::user()->id;
         $comment->answer_id = $request->a_id;
         $comment->comment = $request->comment;
         $comment->date = date("Y-m-d H:i:s");
         $comment->save();
         return back();
     }
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $title = 'Dashboard';
     $posts = Posts::all()->take(3);
     $comments = Comments::all()->take(3);
     return view('dashboard')->withTitle($title)->withPosts($posts)->withComments($comments);
     //return home.blade.php template from resources/views folder
 }
Exemplo n.º 9
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show(News $news)
 {
     $news->increment('dibaca');
     $comments = Comments::orderBy('created_at', 'DESC')->get()->where('news_id', $news->id);
     $sidebar = $news->orderBy('dibaca', 'DESC')->limit(5)->get();
     $otherposts = News::orderBy('created_at', 'DESC')->where('kategori_id', $news->kategori_id)->limit(3)->get();
     return view('sowindows.show', compact(['news', 'otherposts', 'comments', 'sidebar']));
 }
Exemplo n.º 10
0
 public function store(Request $request)
 {
     $input['from_user'] = $request->user() - id;
     $input['on_post'] = $request->input('on_post');
     $input['body'] = $request->input('body');
     $slug = $request->input('slug');
     Comments::create($input);
     return redirect($slug)->with('message', 'Comment published');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $reading_id = Comments::where('id', $id)->first();
     $redirectId = $reading_id->reading_id;
     $comment = Comments::findOrFail($id);
     $comment->comment = $request->comment;
     $comment->save();
     return redirect("currently_reading/{$redirectId}");
 }
Exemplo n.º 12
0
 public function trash(Request $request)
 {
     $comments = Comments::onlyTrashed()->orderBy('id', 'desc')->paginate(5);
     $result = [];
     foreach ($comments as $row) {
         $result[] = ['id' => (int) $row->id, 'name' => ucwords($row->name), 'city' => ucwords($row->city), 'comment' => $row->comment];
     }
     return response()->json($result)->setCallback($request->input('callback'));
 }
Exemplo n.º 13
0
 public function index($id = 0)
 {
     $categories = Categories::all();
     $categories = $categories->sortBy('sort_id');
     $item = Items::find($id);
     $comments = Comments::where('items_id', '=', $id)->get();
     $data = ['categories' => $categories, 'item' => $item, 'id' => $item->categories_id, 'comments' => $comments];
     return view('items.index', $data);
 }
Exemplo n.º 14
0
 public function show($slug)
 {
     $product = Products::where('slug', $slug)->first();
     if ($product == NULL) {
         return redirect('/')->withErrors('Requested url does not exist');
     }
     $comments = Comments::where('on_product', $product->id)->orderBy('created_at', 'asc')->paginate(5);
     $categories = Categories::all();
     return view('product.show')->withProduct($product)->withCategories($categories)->withComments($comments);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //on_post, from_user, body
     $input['from_user'] = $request->user()->id;
     $input['on_post'] = $request->input('on_post');
     $input['body'] = $request->input('body');
     $slug = $request->input('slug');
     Comments::create($input);
     return redirect($slug)->with('message', 'Komentarmu telah dipublikasikan');
 }
Exemplo n.º 16
0
 public function loadCommentsForPost($id)
 {
     $comments = Comments::where('post_id', $id)->orderBy('created_at', 'asc')->get();
     // bidejkji vo baza chuvame samo ime na slika,
     Log::info($comments);
     foreach ($comments as $key => $comment) {
         $comment->user = User::find($comment->user_id);
         $imgName = $comment->user->profile_picture;
         $imgData = base64_encode(File::get('uploads/profile_pictures/thumbnails/' . $imgName));
         $comment->user->profile_picture = $imgData;
     }
     return response()->json(['comments' => $comments]);
 }
Exemplo n.º 17
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     $comment = Comments::find($id);
     $post = Posts::find($comment->on_post);
     $slug = $post->slug;
     if ($comment && ($comment->from_user == $request->user()->id || $request->user()->is_admin() || $request->user()->is_moderator())) {
         $comment->delete();
         $data['message'] = 'Comment deleted Successfully';
     } else {
         $data['errors'] = 'Invalid Operation. You have not sufficient permissions';
     }
     return redirect('/' . $slug)->with($data);
 }
Exemplo n.º 18
0
 public function getComments()
 {
     try {
         $statusCode = 200;
         $response = ['comments' => []];
         $comments = Comments::all();
     } catch (Exception $e) {
         $statusCode = 400;
     } finally {
         // return Response::json($response, $statusCode);
         return Response::json(array('statuscode' => $statusCode, 'comments' => $comments->toArray()));
     }
 }
Exemplo n.º 19
0
 public function all($entity)
 {
     parent::all($entity);
     $this->filter = \DataFilter::source(new \App\Comments());
     $this->filter->add('active', 'Active', 'select')->options(\App\Comments::lists("Active", "active")->all());
     $this->filter->add('name', 'Name', 'text');
     $this->filter->add('created_at', 'Created Date', 'datetime')->format('Y-m-d H:i:s', 'uk');
     $this->filter->submit('search');
     $this->filter->reset('reset');
     $this->filter->build();
     $this->grid = \DataGrid::source($this->filter);
     $this->grid->add('active', 'Active', 'active');
     $this->grid->add('name', 'Name');
     $this->grid->add('comment', 'Comment');
     $this->grid->add('created_at', 'Created Date', 'created_at');
     $this->addStylesToGrid();
     return $this->returnView();
 }
Exemplo n.º 20
0
 public function index(Request $request)
 {
     if (!($count = $this->redis->get(COUNTER_KEY))) {
         $count = Votes::count();
         $this->redis->set(COUNTER_KEY, $count);
     }
     if ($count > 999 && $count <= 999999) {
         $kFormat = number_format($count / 1000, 1, '.', ' ') . ' K';
     } elseif ($count > 999999) {
         $kFormat = number_format($count / 1000000, 1, '.', ' ') . ' M';
     } else {
         $kFormat = $count;
     }
     $total = str_pad($count, 6, 0, STR_PAD_LEFT);
     $exist = $request->session()->get('voted');
     $comments = Comments::orderBy('id', 'desc')->limit(5)->get();
     $commentCount = Comments::count();
     return view('home', ['total' => $total, 'count' => $count, 'exist' => $exist, 'kFormat' => $kFormat, 'comments' => $comments, 'commentCount' => $commentCount]);
 }
Exemplo n.º 21
0
 public function dashboard()
 {
     // current month name
     // dd(date("F", mktime(0, 0, 0, Carbon::now()->month, 10)));
     // dd(Carbon::now()->subMonth()->startOfMonth());
     // dd(date("F", mktime(0, 0, 0, Carbon::now()->subMonth()->startOfMonth()->month, 10)));
     $currentMonthStart = Carbon::now()->startOfMonth();
     $subOneMonthStart = Carbon::now()->subMonth()->startOfMonth();
     $subTwoMonthsStart = Carbon::now()->subMonth(2)->startOfMonth();
     $subThreeMonthsStart = Carbon::now()->subMonth(3)->startOfMonth();
     $subFourMonthsStart = Carbon::now()->subMonth(4)->startOfMonth();
     $subFiveMonthsStart = Carbon::now()->subMonth(5)->startOfMonth();
     $currentMonthEnd = Carbon::now()->endOfMonth();
     $subOneMonthEnd = Carbon::now()->subMonth()->endOfMonth();
     $subTwoMonthsEnd = Carbon::now()->subMonth(2)->endOfMonth();
     $subThreeMonthsEnd = Carbon::now()->subMonth(3)->endOfMonth();
     $subFourMonthsEnd = Carbon::now()->subMonth(4)->endOfMonth();
     $subFiveMonthsEnd = Carbon::now()->subMonth(5)->endOfMonth();
     $currentMonthTitle = date("F", mktime(0, 0, 0, Carbon::now()->startOfMonth()->month, 10));
     $subOneMonthTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth()->startOfMonth()->month, 10));
     $subTwoMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(2)->startOfMonth()->month, 10));
     $subThreeMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(3)->startOfMonth()->month, 10));
     $subFourMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(4)->startOfMonth()->month, 10));
     $subFiveMonthsTitle = date("F", mktime(0, 0, 0, Carbon::now()->subMonth(5)->startOfMonth()->month, 10));
     $postsCurrentMonth = Posts::where('created_at', '>=', $currentMonthStart)->count();
     $postsSubOneMonth = Posts::where('created_at', '>=', $subOneMonthStart)->where('created_at', '<=', $subOneMonthEnd)->count();
     $postsSubTwoMonths = Posts::where('created_at', '>=', $subTwoMonthsStart)->where('created_at', '<=', $subTwoMonthsEnd)->count();
     $postsSubThreeMonths = Posts::where('created_at', '>=', $subThreeMonthsStart)->where('created_at', '<=', $subThreeMonthsEnd)->count();
     $postsSubFourMonths = Posts::where('created_at', '>=', $subFourMonthsStart)->where('created_at', '<=', $subFourMonthsEnd)->count();
     $postsSubFiveMonths = Posts::where('created_at', '>=', $subFiveMonthsStart)->where('created_at', '<=', $subFiveMonthsEnd)->count();
     $commentsCurrentMonth = Comments::where('created_at', '>=', $currentMonthStart)->count();
     $commentsSubOneMonth = Comments::where('created_at', '>=', $subOneMonthStart)->where('created_at', '<=', $subOneMonthEnd)->count();
     $commentsSubTwoMonths = Comments::where('created_at', '>=', $subTwoMonthsStart)->where('created_at', '<=', $subTwoMonthsEnd)->count();
     $commentsSubThreeMonths = Comments::where('created_at', '>=', $subThreeMonthsStart)->where('created_at', '<=', $subThreeMonthsEnd)->count();
     $commentsSubFourMonths = Comments::where('created_at', '>=', $subFourMonthsStart)->where('created_at', '<=', $subFourMonthsEnd)->count();
     $commentsSubFiveMonths = Comments::where('created_at', '>=', $subFiveMonthsStart)->where('created_at', '<=', $subFiveMonthsEnd)->count();
     // $posts = Posts::where('active','1')->where('archive','0')->orderBy('created_at','desc')->paginate(10);
     // $postsPending = Posts::where('active','0')->orderBy('created_at','desc')->get();
     // $postsPendingCount = Posts::where('active','0')->count();
     $popularPosts = DB::table('comments')->join('posts', 'posts.id', '=', 'comments.on_post')->where('posts.archive', '=', 0)->select(array('posts.title', DB::raw('COUNT(comments.on_post) as totalComments')))->groupBy('on_post')->orderBy('totalComments', 'desc')->take(10)->get();
     return view('pages.dashboard', compact('currentMonthTitle', 'subOneMonthTitle', 'subTwoMonthsTitle', 'subThreeMonthsTitle', 'subFourMonthsTitle', 'subFiveMonthsTitle', 'postsCurrentMonth', 'postsSubOneMonth', 'postsSubTwoMonths', 'postsSubThreeMonths', 'postsSubFourMonths', 'postsSubFiveMonths', 'commentsCurrentMonth', 'commentsSubOneMonth', 'commentsSubTwoMonths', 'commentsSubThreeMonths', 'commentsSubFourMonths', 'commentsSubFiveMonths', 'popularPosts'));
 }
Exemplo n.º 22
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $comment = Comments::find($id);
     $slug = $request->input('slug');
     $comment->delete();
     $data['message'] = 'Comment deleted Successfully';
     return redirect()->back()->with($data);
 }
Exemplo n.º 23
0
 public function viewPost($postID)
 {
     if (!auth() || !auth()->user()) {
         $browser = get_browser(null, true);
         // Allow crawler && Facebook Bot view post without logging in.
         if ($browser['crawler'] != 1 && stripos($_SERVER["HTTP_USER_AGENT"], 'facebook') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'face') === false && stripos($_SERVER["HTTP_USER_AGENT"], 'google') === false) {
             $redirectPath = '/post/' . $postID;
             return redirect('/login')->with('redirectPath', $redirectPath);
         }
         $token = md5(rand(), false);
         $DisplayedQuestions = ConstsAndFuncs::$FreeQuestionsForCrawler;
     }
     $post = Posts::find($postID);
     if (count($post) < 1) {
         return view('errors.404');
     }
     $courseID = $post['CourseID'];
     $course = Courses::find($courseID);
     $post->visited++;
     $post->update();
     $post = $post->toArray();
     if (auth() && auth()->user()) {
         $userID = auth()->user()->getAuthIdentifier();
         if (User::find($userID)['admin'] < ConstsAndFuncs::PERM_ADMIN) {
             if ($course['Hidden'] == 1 || $post['Hidden'] == 1) {
                 return view('errors.404');
             }
         }
         $tmp = Learnings::where('UserID', '=', $userID)->where('CourseID', '=', $courseID)->get()->toArray();
         if (count($tmp) < 1) {
             $learnings = new Learnings();
             $learnings->UserID = $userID;
             $learnings->CourseID = $courseID;
             $learnings->save();
             $course->NoOfUsers++;
             $course->update();
         }
         // Insert a new record into DoExams Table to mark the time user start answering questions in post.
         $exam = new Doexams();
         $exam->UserID = $userID;
         $exam->PostID = $postID;
         $token = md5($userID . rand(), false) . md5($postID . rand(), false);
         $exam->token = $token;
         $exam->save();
         // Check if user is vip or not
         $user = User::find(auth()->user()->getAuthIdentifier());
         if ($user['vip'] == 0) {
             $DisplayedQuestions = $post['NoOfFreeQuestions'];
         } else {
             $DisplayedQuestions = new \DateTime($user['expire_at']) >= new \DateTime() ? -1 : $post['NoOfFreeQuestions'];
         }
         if ($user['admin'] >= ConstsAndFuncs::PERM_ADMIN) {
             $DisplayedQuestions = -1;
         }
         // If web hasn't provide some VIP package
         // every user will be able to see full post
         if (ConstsAndFuncs::IS_PAID == 0) {
             $DisplayedQuestions = -1;
         }
     }
     $photo = $post['Photo'];
     if ($DisplayedQuestions > 0) {
         $questions = Questions::where('PostID', '=', $postID)->take($DisplayedQuestions)->get()->toArray();
     } else {
         $questions = Questions::where('PostID', '=', $postID)->get()->toArray();
     }
     $AnswersFor1 = array();
     $TrueAnswersFor1 = array();
     $AnswersFor2 = array();
     $Spaces = array();
     $SetOfSpaceIDs = array();
     $Subquestions = array();
     $AnswersFor5 = array();
     $QuestionFor5IDs = array();
     $AnswersFor6 = array();
     $DragDropIDs = array();
     $CompleteAnswersFor6 = array();
     $AnswersFor3 = array();
     $AnswersFor4 = array();
     $FillCharacterIDs = array();
     $ArrangedIDs = array();
     $maxscore = 0;
     foreach ($questions as $q) {
         switch ($q['FormatID']) {
             case 1:
                 // Trắc nghiệm
                 $answers = Answers::where('QuestionID', '=', $q['id'])->get()->toArray();
                 foreach ($answers as $a) {
                     if ($a['Logical'] == 1) {
                         $TrueAnswersFor1 += [$q['id'] => $a['id']];
                         break;
                     }
                 }
                 $info = [$q['id'] => $answers];
                 if (count($answers) > 0) {
                     $maxscore++;
                 }
                 $AnswersFor1 += $info;
                 continue;
             case 2:
                 // Điền từ
                 $spaces = Spaces::where('QuestionID', '=', $q['id'])->get()->toArray();
                 $Spaces += [$q['id'] => $spaces];
                 foreach ($spaces as $s) {
                     $SetOfSpaceIDs = array_merge($SetOfSpaceIDs, [$s['id']]);
                     $a = Answers::where('SpaceID', '=', $s['id'])->get()->toArray();
                     shuffle($a);
                     $AnswersFor2 += [$s['id'] => $a];
                 }
                 $maxscore += count($spaces);
                 continue;
             case 3:
                 $answer = Answers::where('QuestionID', '=', $q['id'])->get()->toArray();
                 $AnswersFor3 += [$q['id'] => $answer[0]];
                 $ArrangedIDs = array_merge($ArrangedIDs, [$q['id']]);
                 $maxscore++;
                 continue;
             case 4:
                 $answer = Answers::where('QuestionID', '=', $q['id'])->get()->toArray();
                 $AnswersFor4 += [$q['id'] => $answer[0]];
                 $FillCharacterIDs = array_merge($FillCharacterIDs, [$q['id']]);
                 $maxscore++;
                 continue;
             case 5:
                 // Nối
                 $subquestions = Subquestions::where('QuestionID', '=', $q['id'])->get()->toArray();
                 $answer = array();
                 foreach ($subquestions as $s) {
                     $a = Answers::where('SubQuestionID', '=', $s['id'])->get()->toArray();
                     $answer += [$s['id'] => $a[0]];
                 }
                 $AnswersFor5 += [$q['id'] => $answer];
                 $maxscore += count($subquestions);
                 $Subquestions += [$q['id'] => $subquestions];
                 $QuestionFor5IDs = array_merge($QuestionFor5IDs, [$q['id']]);
                 continue;
             case 6:
                 // Kéo thả
                 $DragDropIDs = array_merge($DragDropIDs, [$q['id']]);
                 $answers = Answers::where('QuestionID', '=', $q['id'])->get()->toArray();
                 $AnswersFor6 += [$q['id'] => $answers];
                 $s = '';
                 foreach ($answers as $a) {
                     $s .= $a['Detail'] . ' ';
                 }
                 $CompleteAnswersFor6 += [$q['id'] => $s];
                 // $CompleteAnswersFor6 = array_merge($CompleteAnswersFor6, [$s]);
                 $maxscore++;
                 continue;
         }
     }
     $Comments = Comments::all()->toArray();
     $result = array('Comments' => json_encode($Comments), 'Questions' => $questions, 'Post' => $post, 'MaxScore' => $maxscore, 'NumOfQuestions' => count($questions = Questions::where('PostID', '=', $postID)->get()->toArray()), 'Token' => $token, 'DisplayedQuestions' => $DisplayedQuestions);
     if (auth() && auth()->user() && User::find(auth()->user()->getAuthIdentifier())['admin'] >= ConstsAndFuncs::PERM_ADMIN) {
         $nextPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '>=', $post['id'])->get()->toArray();
         $previousPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '<', $post['id'])->get()->toArray();
         $result += ['NextPost' => count($nextPost) > 1 ? $nextPost[1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->first()->toArray()['id']];
         $result += ['PreviousPost' => count($previousPost) > 0 ? $previousPost[count($previousPost) - 1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->orderBy('created_at', 'desc')->first()->toArray()['id']];
     } else {
         $nextPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '>=', $post['id'])->where('Hidden', '=', 0)->get()->toArray();
         $previousPost = Posts::where('CourseID', '=', $post['CourseID'])->where('id', '<', $post['id'])->where('Hidden', '=', 0)->get()->toArray();
         $result += ['NextPost' => count($nextPost) > 1 ? $nextPost[1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->where('Hidden', '=', 0)->first()->toArray()['id']];
         $result += ['PreviousPost' => count($previousPost) > 0 ? $previousPost[count($previousPost) - 1]['id'] : Posts::where('CourseID', '=', $post['CourseID'])->where('Hidden', '=', 0)->orderBy('created_at', 'desc')->first()->toArray()['id']];
     }
     $newpost = array_merge($nextPost, $previousPost);
     $result += ['newpost' => $newpost];
     // dd($newpost);
     // dd($post);
     $ahtk = Tags::where('PostID', '=', $postID)->get()->toArray();
     $Hashtag = array();
     foreach ($ahtk as $k) {
         $ht = Hashtags::find($k['HashtagID'])['Hashtag'];
         if (strlen($ht) > 0) {
             $Hashtag = array_merge($Hashtag, [$ht]);
         }
     }
     return view('viewpost')->with($result)->with(compact(['result', 'newpost', 'Hashtag', 'AnswersFor1', 'TrueAnswersFor1', 'AnswersFor3', 'ArrangedIDs', 'Spaces', 'AnswersFor2', 'SetOfSpaceIDs', 'AnswersFor4', 'FillCharacterIDs', 'subquestions', 'AnswersFor5', 'Subquestions', 'QuestionFor5IDs', 'AnswersFor6', 'DragDropIDs', 'CompleteAnswersFor6']));
 }
Exemplo n.º 24
0
 protected function create(array $data)
 {
     return Comments::create(['body' => $data['body'], 'user_id' => Auth::user()->id, 'items_id' => $data['items_id']]);
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($proId)
 {
     $comments = Comments::where('pro_id', $proId)->get();
     return response()->json($comments);
 }
Exemplo n.º 26
0
 public function createComment($userId, $propositionId, $body)
 {
     return Comments::create(["commenter_id" => $userId, "proposition_id" => $propositionId, "body" => $body]);
 }
Exemplo n.º 27
0
 public function deny($id)
 {
     // admin only check
     if (Auth::user()->is_admin()) {
         $comment = Comments::find($id);
         $comment->active = 0;
         $comment->save();
     }
     return redirect()->back();
 }
Exemplo n.º 28
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($title)
 {
     $currentNews = News::where('title_en', $title)->get();
     $comments = Comments::where('id', '=', 'comment_id')->get();
     return view('CurrentNews', ['currentNews' => $currentNews, 'comments' => $comments]);
 }
Exemplo n.º 29
0
 public static function edit($action, array $data, $id)
 {
     $goods = self::find($id);
     if ($action == 'edit') {
         $rows = Album::where('pid', $id)->get();
         $srcNum = Album::where('pid', $id)->count();
         $path = 'uploads';
         $files = Upload::fileUpload($path);
         $uploadNum = count($files);
         if ($uploadNum < $srcNum) {
             $i = 0;
             foreach ($files as $file) {
                 $array = ['album_path' => $file['name']];
                 unlink("uploads/" . $rows[$i]->album_path);
                 $rows[$i]->update($array);
                 $i++;
             }
             for ($j = $i; $j < $srcNum; $j++) {
                 $rows[$j]->delete();
                 unlink("uploads/" . $rows[$j]->album_path);
             }
         } elseif ($uploadNum == $srcNum) {
             $i = 0;
             foreach ($files as $file) {
                 $updateArr = ['album_path' => $file['name']];
                 unlink("uploads/" . $rows[$i]->album_path);
                 $rows[$i]->update($updateArr);
                 $i++;
             }
         } elseif ($uploadNum > $srcNum) {
             $i = 0;
             foreach ($rows as $row) {
                 $updateArr = array('album_path' => $files[$i]['name']);
                 unlink("uploads/" . $row->album_path);
                 $row->update($updateArr);
                 $i++;
             }
             for ($j = $i; $j < $uploadNum; $j++) {
                 $insertArr = array('pid' => $id, 'album_path' => $files[$j]['name']);
                 Album::create($insertArr);
             }
         }
         if ($goods->update($data)) {
             return self::success(['pro_id' => $id]);
         }
         return self::fail();
     } elseif ($action == 'delete') {
         if (self::where('id', $id)->delete()) {
             foreach (Album::where('pid', $id)->get() as $row) {
                 unlink("uploads/" . $row->album_path);
             }
             Album::where('pid', $id)->delete();
             Comments::where('pro_id', $id)->delete();
             return self::success();
         }
         return self::fail();
     }
 }
Exemplo n.º 30
0
 public function GetCommentsOnDoctor()
 {
     $doc = json_decode($_COOKIE['doctor_user'], true);
     $doc_id = $doc[0]['doc_id'];
     // this should be replaced by $COOKIE reference
     try {
         $comments = Comments::whereDoctor_id($doc_id)->orderBy('id', 'DESC')->limit(20)->get();
         foreach ($comments as $com) {
             $pat = Patients::whereUser_id($com->user_id)->first();
             $img = Images::whereUser_id($pat->user_id)->first();
             $main_ob['com_data'] = $com;
             $main_ob['pat_first_name'] = $pat->first_name;
             $main_ob['pat_last_name'] = $pat->last_name;
             $main_ob['pat_img'] = $img->image_path;
             $res[] = $main_ob;
         }
     } catch (Exception $e) {
         $this->LogError('AjaxController Get Comments On Doctor Function', $e);
     }
     return response()->json($res);
 }