public function saveScore(Request $request)
 {
     if (!auth() || !auth()->user()) {
         echo 'Kết quả chưa được lưu.';
         return;
     }
     $UserID = auth()->user()->getAuthIdentifier();
     $data = $request->all();
     $token = $data['token'];
     // day by day, no. of record will increase
     // => maybe there are multiple record with the same value of UserID and token
     // => pick the newest record
     $record = Doexams::where('token', 'LIKE', $token)->where('UserID', '=', $UserID)->get()->last();
     if (count($record->toArray()) < 1) {
         echo 'Kết quả chưa được lưu.';
         return;
     }
     $record->Score = $request['Score'] . '/' . $request['MaxScore'];
     $record->update();
     $oldDateTime = $record->created_at->getTimestamp();
     $newDateTime = $record->updated_at->getTimestamp();
     $diff = ($newDateTime - $oldDateTime) / 3600.0;
     $record->Time = $diff;
     $record->update();
     if ($diff > 0) {
         $course = Courses::find(Posts::find($record->PostID)->CourseID);
         $course->TotalHours += $diff;
         $course->update();
     }
     echo 'Kết quả đã được lưu lại.';
     return;
 }
Esempio n. 2
0
 public function deletePost($deletePostId)
 {
     $deletePost = Posts::find($deletePostId);
     if ($deletePost->photo != 'noImage.jpg') {
         //delete the image associative with the post
         \File::Delete('img/Post/' . $deletePost->photo);
     }
     $deletePost->delete();
     return redirect('admin');
 }
Esempio n. 3
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);
 }
 /**
  * Delete the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function delete($id)
 {
     $post = \App\Posts::find($id);
     $user_id = $post->user()->id;
     $post->delete();
     // Send a message to the user.
     $reason = $_POST['reason'];
     if (isset($_POST['other_reason']) && $_POST['other_reason'] != "") {
         $reason = $_POST['other_reason'];
     } else {
         $reason = $_POST['reason'];
     }
     $message = "Your post has been removed due to the following reason: " . $reason;
     \App\Message::send((int) $_POST['user_id'], 0, "Your post has been removed", $message);
     header('Location:' . url('admin/users/edit/' . $user_id));
     exit;
 }
 /**
  * get item by id
  * @param $id
  * @return mixed
  */
 public function getById($id)
 {
     try {
         $statusCode = 200;
         $response = [];
         $post = Posts::find($id);
         if ($post != null) {
             $response['post'] = ['id' => $post->id, 'title' => $post->title, 'description' => $post->description, 'content' => $post->content, 'published' => $post->published];
             $statusCode = 200;
         } else {
             $statusCode = 400;
         }
         $response['status'] = $statusCode;
     } catch (Exeption $e) {
         $statusCode = 400;
     } finally {
         return \Response::json($response, $statusCode);
     }
 }
Esempio n. 6
0
 public function store(Request $request, $id)
 {
     if ($request->ajax()) {
         $post = Posts::find($id);
         $edit_header = $request->input('Header');
         $edit_content = $request->input('Content');
         $v = Validator::make($request->all(), ['Header' => 'required|max:32', 'Content' => 'required']);
         if (!$v->fails()) {
             $post->Header = $edit_header;
             $post->Content = $edit_content;
             if ($post->save()) {
                 $response = array('status' => 'success', 'msg' => 'Setting created successfully');
             } else {
                 $response = array('status' => 'error', 'msg' => 'save failed');
             }
         } else {
             $response = array('status' => 'error', 'msg' => 'v failed');
         }
         return Response::json($response);
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $question = Questions::find($id);
     @unlink(public_path('images/imageQuestion/' . $question['Photo']));
     $postid = $question['PostID'];
     $format = Posts::find($postid)['FormatID'];
     if ($format == 1) {
         $answers = Answers::where('QuestionID', '=', $id)->get()->toArray();
         foreach ($answers as $answer) {
             Answers::destroy($answer['id']);
         }
     } else {
         if ($format == 2) {
             $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray();
             foreach ($spaces as $value) {
                 SpacesController::destroy($value['id']);
             }
         }
     }
     $question->delete();
     return redirect(route('user.viewpost', $postid));
 }
Esempio n. 8
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $data = [];
     $post = Posts::find($id);
     if ($post) {
         if ($post->user_id == $request->user()->id) {
             $post->delete();
         } else {
             // vrakjam 401 unauthorized
             return response()->json([], 401);
         }
     } else {
         // vrakjam 404 not found
         return response()->json([], 404);
     }
 }
Esempio n. 9
0
 public function komentar($next)
 {
     if (trim(Input::get('isi')) != "") {
         $komen = new Komentar();
         $komen->idpengguna = Auth::user()->id;
         $komen->idpost = $next;
         $komen->isi = Input::get('isi');
         $komen->save();
         $a = Posts::find($next);
         return redirect(url($a->slug));
     } else {
         return redirect(url($a->slug));
     }
 }
Esempio n. 10
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $post = \App\Posts::find($id);
     $post->delete();
     return $post;
 }
Esempio n. 11
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Posts::find($id)->delete();
     return redirect(url('mine/posts'));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy(Request $request, $id)
 {
     //
     $post = Posts::find($id);
     if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) {
         $post->delete();
         $data['message'] = 'Post deleted Successfully';
     } else {
         $data['errors'] = 'Invalid Operation. You have not sufficient permissions';
     }
     return redirect('/')->with($data);
 }
 public function getPost(Request $request)
 {
     return Posts::find($request->id);
 }
Esempio n. 14
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  Request $request
  * @param int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $post = Posts::find($id);
     if ($post && ($post->author_id == Auth::user()->id || $request->user()->is_admin())) {
         try {
             $post->delete();
             $data = array('alert-type' => 'alert alert-success', 'alert-message' => 'Posten ble slettet!');
         } catch (\Exception $e) {
         }
     } else {
         $data = array('alert-type' => 'alert alert-danger', 'alert-message' => 'Du har ikke tilgang til å slette denne posten!');
     }
     return Redirect::to('/admin/poster/alle')->with($data);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     //
     $post = Posts::find($id);
     if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) {
         $post->delete();
         $data['message'] = 'Postingan telah di hapus';
     } else {
         $data['errors'] = 'Invalid Operation. Kamu tidak boleh mengakses halaman';
     }
     return redirect('/')->with($data);
 }
Esempio n. 16
0
 public function unarchive($id)
 {
     // admin only check
     if (Auth::user()->is_admin()) {
         $post = Posts::find($id);
         $post->archive = 0;
         $post->save();
     }
     return redirect()->back();
 }
Esempio n. 17
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $data = array('data' => Posts::find($id));
     return view('artikel.edit')->with($data);
 }
Esempio n. 18
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request)
 {
     $post_id = $request->input('post_id');
     $post = Posts::find($post_id);
     if ($post && ($post->author_id == $request->user()->id || $request->user()->is_admin())) {
         $title = $request->input('title');
         $slug = str_slug($title);
         $duplicate = Posts::where('slug', $slug)->first();
         if ($duplicate) {
             if ($duplicate->id != $post_id) {
                 return redirect('edit/' . $post->slug)->withErrors('Title already taken!');
             } else {
                 $post->slug = $slug;
             }
         } else {
             $post->slug = $slug;
         }
         $post->title = $title;
         $post->body = $request->input('body');
         if ($request->has('save')) {
             $post->active = 0;
             $message = 'Post saved successfully!';
             $landing = 'edit/' . $post->slug;
         } else {
             $post->active = 1;
             $message = 'Post published successfully!';
             $landing = $post->slug;
         }
         $post->save();
         return redirect($landing)->withMessage($message);
     } else {
         return redirect('/')->withErrors('You have not sufficient permissions to edit a post.');
     }
 }
Esempio n. 19
0
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $post = Posts::find($id);
     @unlink(public_path('images/imagePost/' . $post['Photo']));
     $questions = Questions::where('PostID', '=', $id)->get()->toArray();
     foreach ($questions as $question) {
         QuestionsController::destroy($question['id']);
     }
     $courseid = $post['CourseID'];
     $post->delete();
     $course = Courses::find($post->CourseID);
     $course->NoOfPosts--;
     $course->update();
     return redirect(route('admin.viewcourse', $courseid));
 }
Esempio n. 20
0
 public function processUpdateExpire(Request $request)
 {
     $intPostId = $request->intPostId;
     $strExpDate = $request->strExpDate;
     $strExpDate = strtotime($strExpDate);
     $Post = Posts::find($intPostId);
     $Post->expdate = $strExpDate;
     echo $Post->save();
 }
Esempio n. 21
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     Posts::find($id)->delete();
     return redirect(url('artikel'));
 }
Esempio n. 22
0
 public function show($id)
 {
     $post = Posts::find($id);
     $postagems = DB::table('posts')->orderBy('id', 'desc')->take(3)->get();
     return view('site.novidades.posts', compact('post', 'postagems'));
 }