/**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(CourseRequest $request, $id)
 {
     //
     $courses = Courses::findorfail($id);
     $courses->update($request->all());
     return redirect(action('CoursesController@index'));
 }
Пример #2
0
 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;
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     //
     $tags = Tags::findorfail($id);
     $courses = Courses::lists('course_name', 'id');
     return view('Tags.edit', compact(['tags', 'courses']));
 }
Пример #4
0
 public static function getColumn($column)
 {
     $array = Courses::all();
     $result = array();
     foreach ($array as $item) {
         $result += array($item['id'] => $item[$column]);
     }
     if (count($result) > 0) {
         return $result;
     } else {
         return array('-1' => 'Chưa có khóa học nào được tạo.');
     }
     //        $array = array('ID'=>1, 'ID1'=>3, '2'=>5);
     //        return $array;
 }
Пример #5
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));
 }
Пример #6
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public static function destroy($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $course = Courses::find($id);
     $posts = Posts::where('CourseID', '=', $id)->get()->toArray();
     //        dd($posts);
     foreach ($posts as $post) {
         PostsController::destroy($post['id']);
         //            dd($post['id']);
     }
     $course->delete();
     return redirect(route('admin'));
 }
 public function CourseQuestions($id)
 {
     $course = Courses::findorfail($id);
     $questions = $course->questions;
     return view('Question.courseQuestions', compact('course', 'questions'));
 }