Example #1
0
 public function show($courseId = null)
 {
     if (null === $courseId || null === ($course = Course::with(['department'])->find($courseId))) {
         throw new NotFoundHttpException();
     }
     return response()->json($course);
 }
Example #2
0
 /**
  * Course filter.
  */
 protected function keywordFilter()
 {
     if (isset($this->filter['keyword'])) {
         $keyword = trim($this->filter['keyword']);
         if (mb_strlen($keyword) > 0) {
             $this->model = $this->model->where(function ($query) use($keyword) {
                 $query->where('code', 'like', "%{$keyword}%")->orWhere('name', 'like', "%{$keyword}%")->orWhere('name_en', 'like', "%{$keyword}%")->orWhere('professor', 'like', "%{$keyword}%");
             });
             ++$this->filterCount;
         }
     }
 }
Example #3
0
 public function store(Requests\Courses\CommentsRequest $request, $courseId, $commentId = null)
 {
     if (!Course::where('id', '=', $courseId)->exists()) {
         throw new NotFoundHttpException();
     } else {
         if (null !== $commentId && !Comment::where('course_id', '=', $courseId)->where('id', '=', $commentId)->exists()) {
             throw new NotFoundHttpException();
         }
     }
     $comment = Comment::create(['user_id' => $request->user()->user->account_id, 'course_id' => $courseId, 'courses_comment_id' => $commentId, 'content' => $request->input('content'), 'anonymous' => boolval($request->input('anonymous', false))]);
     return response()->json($comment);
 }
Example #4
0
 public function store(Requests\Courses\ExamsRequest $request, $courseId)
 {
     if (!Course::where('id', '=', $courseId)->exists()) {
         throw new NotFoundHttpException();
     }
     $path = ['dir' => storage_path('uploads/courses/exams'), 'name' => str_random()];
     $exam = Exam::create(['user_id' => $request->user()->user->account_id, 'course_id' => $courseId, 'semester_id' => $request->input('semester'), 'file_name' => $request->file('file')->getClientOriginalName(), 'file_type' => $request->file('file')->getMimeType(), 'file_path' => $path['name'], 'file_size' => $request->file('file')->getSize(), 'created_at' => Carbon::now()]);
     if (!$exam->exists) {
         throw new InternalErrorException();
     }
     $request->file('file')->move($path['dir'], $path['name']);
     $this->dispatch(new ScanExamUploadFiles($exam));
     return response()->json($exam);
 }
Example #5
0
 /**
  * Save courses data to database.
  *
  * @param array $data
  * @return bool
  */
 protected function savingData($data)
 {
     foreach ($data as $datum) {
         $department_id = array_search($datum['department'], $this->correspondenceTable) + 22;
         // prefix 22
         DB::beginTransaction();
         try {
             foreach ($datum['courses'] as $course) {
                 if (Course::where('code', '=', $course['code'])->where('professor', '=', $course['professor'])->exists()) {
                     continue;
                 } else {
                     if (null !== $course['dimension']) {
                         $course['dimension'] = Category::where('category', '=', 'courses.dimension')->where('name', '=', $course['dimension'])->first()->getAttribute('id');
                     }
                 }
                 Course::create(['code' => $course['code'], 'department_id' => $department_id, 'dimension_id' => $course['dimension'], 'name' => $course['name'], 'name_en' => $course['name_en'], 'professor' => $course['professor']]);
                 ++$this->count;
             }
         } catch (Exception $e) {
             DB::rollBack();
             $this->error($e->getMessage());
             return false;
         }
         DB::commit();
     }
     return true;
 }