public function destroyBulk(Request $request, $exam_id)
 {
     $table_records = $request->input('table_records');
     if (empty($table_records) or !is_array($table_records)) {
         return redirect()->back();
     }
     $exam = Exam::findOrFail($exam_id);
     $exam->questions()->detach($table_records);
     return redirect()->route('exams.questions.index', $exam->id);
 }
Beispiel #2
0
 public function index()
 {
     $exams = Exam::select('exams.*')->join('academycycle_semesters as acsem', function ($join) {
         $join->on('acsem.id', '=', 'exams.semester_id')->where('acsem.active', '=', 1);
     })->join('academycycle_semesterevents AS acsemevts', function ($join) {
         $join->on('acsemevts.semester_id', '=', 'acsem.id');
     })->join('academycycle_semesterevent_types AS ast', function ($join) {
         $join->on('ast.id', '=', 'acsemevts.type_id')->where('ast.slug', '=', 'midterm');
     })->whereDate('exams.start_at', '<=', date('Y-m-d'))->whereDate('exams.finish_at', '>=', date('Y-m-d'))->groupBy('exams.id')->with('questions', 'questions.choices')->get();
     return $exams;
 }
Beispiel #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $sessions = ClassroomSession::select('id', 'classroom_id')->whereIn('classroom_id', [157, 168, 176, 186, 198, 213, 217])->get();
     // $this->comment(PHP_EOL.$sessions->count().PHP_EOL);
     foreach ($sessions as $session) {
         $students = ClassroomStudent::select('student_id')->where('student_id', 1841)->where('classroom_id', $session->classroom_id)->get();
         // $this->comment(PHP_EOL.$students->count().PHP_EOL);
         foreach ($students as $student) {
             $exist = StudentClassroomSession::where('classroom_session_id', $session->id)->where('student_id', $student->student_id)->value('id');
             if ($exist) {
                 $this->comment(PHP_EOL . ' HAS ' . $exist . PHP_EOL);
             } else {
                 $data = ['student_id' => $student->student_id, 'attendee_id' => $student->student_id, 'classroom_session_id' => $session->id, 'student_link' => '', 'semester_id' => 9];
                 $attendance = ['entry_time' => null, 'exit_time' => null, 'attended_minutes' => null, 'teacher_id' => null, 'classroom_session_id' => $session->id, 'student_id' => $student->id, 'valid' => 0, 'manual' => 0];
                 StudentClassroomSession::create($data);
                 ClassroomSessionAttendance::create($attendance);
                 $this->comment(PHP_EOL . ' NOT ' . PHP_EOL);
             }
         }
     }
     // Student::with('classrooms', 'subjects')->has('classrooms',  '=', 3)->leftJoin('subject_sub')
     exit;
     \DB::connection()->enableQueryLog();
     Exam::select('exams.type', 'exams.start_at', 'exams.finish_at', 'exams.name', 'exams.id')->join('subject_subjects as subsub', 'subsub.id', '=', 'exams.subject_id')->join('student_subjects as stusub', function ($j) {
         $j->on('stusub.subject_id', '=', 'subsub.id')->where('stusub.student_id', '=', 10001)->where('stusub.state', '=', 'study');
     })->where(function ($query) {
         $query->orWhereIn('exams.type', ['midterm', 'remidterm', 'activity'])->orWhereRaw('exams.id IN (SELECT ce.exam_id FROM classrooms_exam as ce
                             JOIN classrooms as c ON c.id = ce.classroom_id
                             JOIN classroom_students as cs ON cs.classroom_id = c.id
                                 AND cs.student_id = 10001
                             WHERE exam_id = exams.id GROUP BY ce.id)');
         // if ($request->has('finalExam') == 'true') {
         //     $query->orWhereIn('exams.type',
         //         [
         //     'final',
         //                 'summer',
         //                 'refinal'
         //         ]);
         // }
     })->where('exams.semester_id', 9)->where('finish_at', '>=', date('Y-m-d H:i:s'))->groupBy('exams.id')->orderBy('exams.start_at', 'ASC')->get();
     // Exam::count();
     $query = \DB::getQueryLog();
     $lastQuery = end($query);
     var_dump($lastQuery);
     // echo "done";
     exit;
     // $sessions = ClassroomSession::select('id')->whereIn('interval_id', [2,14,15])->get();
     // foreach ($sessions as $session) {
     //     ClassroomSessionAttendance::where('classroom_session_id', $session->id)->update(['valid' => 1]);
     // }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     if (Exam::count()) {
         return;
     }
     $tests = DB::connection('old')->table('tests')->where('test_id', '>', 6)->WhereIn('test_type', [1, 2, 3, 11, 21])->get();
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     Exam::truncate();
     ExamQuestion::truncate();
     $exam_type = [1 => 'midterm', 2 => 'final', 3 => 'summer', 11 => 'remidterm', 21 => 'refinal'];
     $all_test = [];
     $all_test_q = [];
     foreach ($tests as $test) {
         $exams = [];
         $exams['id'] = $test->test_id;
         $exams['name'] = $test->test_title;
         $exams['subject_id'] = $test->test_subjectid;
         $exams['type'] = $exam_type[$test->test_type];
         $exams['semester_id'] = $test->test_semid;
         $exams['active'] = 1;
         $exams['start_at'] = date('Y-m-d H:i:s', $test->test_starttime);
         $exams['finish_at'] = date('Y-m-d H:i:s', $test->test_endtime);
         $exams['created_at'] = $test->test_created;
         $exams['updated_at'] = $test->test_modified;
         $all_test[] = $exams;
         foreach (explode(',', $test->test_question_ids) as $q_id) {
             $test_q = [];
             $test_q['question_id'] = $q_id;
             $test_q['exam_id'] = $test->test_id;
             $all_test_q[] = $test_q;
         }
     }
     foreach (array_chunk($all_test, 500) as $exam_group) {
         DB::table('exams')->insert($exam_group);
     }
     foreach (array_chunk($all_test_q, 500) as $test_q_group) {
         DB::table('exam_questions')->insert($test_q_group);
     }
     $this->command->info('table tests successfully transferd');
 }
Beispiel #5
0
 public function unloadexam($subject_id, $exam_type, $msg = 0)
 {
     $exam_ids = Exam::select('id')->where('subject_id', $subject_id)->where('type', $exam_type)->get()->toArray();
     $statistics = Student::with(['examresults' => function ($q) use($exam_ids) {
         $q->whereIn('exam_id', $exam_ids);
         $q->where('filename', '');
     }])->whereHas('examresults', function ($q) use($exam_ids) {
         $q->whereIn('exam_id', $exam_ids);
         $q->where('filename', '');
     });
     if ($msg == 1) {
         $statistics = $statistics->pluck('username')->toArray();
         return redirect()->route('students.messages.create', compact('statistics'));
     }
     $statistics = $statistics->get();
     return view('exams::reports.unloadexam', compact('statistics', 'subject_id', 'exam_type'));
 }
Beispiel #6
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $semester_id = semester()->id;
     $results = ExamResult::leftJoin('exam_result_answers as era', 'era.exam_result_id', '=', 'exam_results.id')->select('exam_results.id', 'exam_results.student_id', 'exam_results.filename')->where('exam_results.filename', '!=', '')->where('exam_results.semester_id', $semester_id)->whereNull('era.id')->groupBy('exam_results.id')->get();
     // $semester_id = semester()->id;
     if (!$results->count()) {
         $this->comment(PHP_EOL . 'All is corrected' . PHP_EOL);
     }
     $this->comment(PHP_EOL . 'Starting Correcting ' . $results->count() . '....' . PHP_EOL);
     foreach ($results as $result) {
         // $this->comment(PHP_EOL.'C'.PHP_EOL);
         try {
             $file = File::get('/var/www/node/rest/exams/' . $result->filename);
         } catch (\Illuminate\Contracts\Filesystem\FileNotFoundException $e) {
             $this->comment(PHP_EOL . 'No Answers File Provided' . PHP_EOL);
             continue;
         }
         $exam_file = json_decode($file);
         if (empty($exam_file->exam_id)) {
             $error = 1;
             $this->comment(PHP_EOL . 'Wrong file no exam_id' . PHP_EOL);
             continue;
         }
         if (empty($exam_file->questions) or !is_array($exam_file->questions)) {
             $this->comment(PHP_EOL . 'No Answers in the file you provided' . PHP_EOL);
             continue;
         }
         $exam_id = $exam_file->exam_id;
         $student_id = $exam_file->student_id;
         if (!($exam = Exam::with(['questions' => function ($query) {
             $query->wherePivot('devide_grade', 0);
         }, 'questions.choices'])->find($exam_id))) {
             $this->comment(PHP_EOL . 'Exam does not exist' . PHP_EOL);
             continue;
         }
         $result_data = ['student_id' => $student_id, 'exam_id' => $exam->id, 'semester_id' => $exam->semester_id];
         $grade_per_question = 0.5;
         if ($exam->type == 'activity') {
             $grade_per_question = $this->activity_points / $exam->questions->count();
         } else {
             if ($exam->type == 'midterm') {
                 $grade_per_question = $this->midterm_points / $exam->questions->filter(function ($question) {
                     return $question->type != 'essay';
                 })->count();
             } else {
                 $this->comment(PHP_EOL . 'We Only correcting activities for now' . PHP_EOL);
                 continue;
             }
         }
         // dd($grade_per_question);
         // if ($result = ExamResult::firstOrCreate($result_data)) {
         $result_answers = [];
         $grade = 0.0;
         $answers = $exam_file->questions;
         foreach ($answers as $answer) {
             $result_answer = [];
             $result_answer['question_id'] = $answer->question_id;
             $result_answer['answer'] = $answer->answer;
             $result_answers[$answer->question_id] = $result_answer;
         }
         StudentGrade::where('student_id', $student_id)->where(['ref_key' => 'exam', 'ref_value' => $exam->id])->delete();
         $result->answers()->delete();
         foreach ($exam->questions as $question) {
             $current_grade = 0;
             switch ($question->type) {
                 case 'true_false':
                     $true_choice = $question->choices->first(function ($key, $choice) {
                         return $choice->istrue;
                     });
                     $is_true = array_where($answers, function ($key, $answer) use($true_choice) {
                         return $answer->answer == $true_choice->id;
                     });
                     // var_dump($true_choice->toArray());
                     if (count($is_true)) {
                         $current_grade = $grade_per_question;
                     }
                     break;
                 case 'single_choice':
                     $true_choice = $question->choices->first(function ($key, $choice) {
                         return $choice->istrue;
                     });
                     $is_true = array_where($answers, function ($key, $answer) use($true_choice) {
                         return $answer->answer == $true_choice->id;
                     });
                     if (count($is_true)) {
                         $current_grade = $grade_per_question;
                     }
                     break;
                 case 'multiple_choice':
                     $question_grade = 0;
                     $multiple_answer = array_first($answers, function ($key, $answer) use($question) {
                         return $answer->question_id == $question->id;
                     });
                     if ($multiple_answer) {
                         $all_answers = $multiple_answer ? array_filter(explode(",", $multiple_answer->answer)) : [];
                         $all_answered_count = count($all_answers);
                         if ($all_answered_count == $question->choices->count() || $all_answered_count == 0) {
                             $current_grade = 0.0;
                         } else {
                             $true_answers = $question->choices->filter(function ($question) {
                                 return $question->istrue;
                             });
                             if ($true_answers) {
                                 $true_answers_ids = $true_answers->pluck('id')->toArray();
                                 $true_answers_count = count($true_answers_ids);
                                 $right_answered_count = count(array_intersect($all_answers, $true_answers_ids));
                                 $wrong_answered_count = $all_answered_count - $right_answered_count;
                                 $grade_per_choice = $true_answers_count > 0 ? $grade_per_question / $true_answers_count : 0;
                                 $multichoice_right_grade = $right_answered_count * $grade_per_choice;
                                 $multichoice_wrong_grade = $wrong_answered_count * $grade_per_choice;
                                 if ($multichoice_wrong_grade <= $multichoice_right_grade) {
                                     $question_grade = $multichoice_right_grade - $multichoice_wrong_grade;
                                 } else {
                                     $question_grade = 0;
                                 }
                                 // if ($question_grade > $grade_per_question) {
                                 // $current_grade = $grade_per_question;
                                 // } else {
                                 $current_grade = $question_grade;
                                 // }
                                 // $current_grade = $multichoice_right_grade;
                             }
                         }
                     }
                     break;
             }
             $result_answers[$question->id]['degree'] = $current_grade;
             $grade += $current_grade;
         }
         foreach ($result_answers as $a) {
             $result->answers()->create($a);
         }
         if ($exam->type == 'activity' && $grade > $this->activity_points) {
             $grade = $this->activity_points;
         }
         $notes = '';
         switch ($exam->type) {
             case 'midterm':
                 $notes = 'درجة اختبار المنتصف الاختيار ' . $exam->name;
                 break;
             case 'activity':
                 $notes = 'درجة النشاط ' . $exam->name;
                 break;
         }
         $search_data = ['student_id' => $student_id, 'ref_value' => $exam->id, 'ref_key' => 'exam', 'subject_id' => $exam->subject_id, 'semester_id' => $semester_id, 'notes' => $notes];
         $update_data = ['value' => round($grade, 2)];
         StudentGrade::updateOrCreate($search_data, $update_data);
     }
     $this->comment(PHP_EOL . 'Correcting is done :)' . PHP_EOL);
 }
Beispiel #7
0
 public function getAcademicCalendar($background = false)
 {
     $student = Student::select('students.*')->joinTermName()->findOrFail($this->student_id);
     $exams = Exam::inCurrentSemester()->ofStudent($this->student_id)->select('ss.name', 'exams.start_at')->get();
     $pdf = $this->preparePdf($background);
     // ---- >
     $html = '<h2>التقويم الأكاديمي</h2>';
     $pdf->writeHTMLCell(210, 20, 0, 50, $html, 0, 0, false, true, "C");
     $pdf->SetFontSize(12);
     $html = 'بتاريخ : ' . Date::now()->format('l d F Y');
     $pdf->writeHTMLCell(60, 10, 150, 40, $html, 0, 0, false, true, "C");
     $pdf->SetFontSize(13, 'B');
     $html = '<table cellpadding="3">
   <tr><td align="right">إسم لطالب</td><td align="right">' . $student->name . '</td></tr>
   <tr><td align="right">الرقم الجامعي</td><td align="right">' . $student->code . '</td></tr>
   <tr><td align="right">تاريخ الإلتحاق</td><td align="right">' . Date::parse($student->created_at)->format('l d F Y') . '</td></tr>
   <tr><td align="right">السنة الدراسية</td><td align="right">' . $student->year_name . '</td></tr>
 </table>';
     $pdf->writeHTMLCell(100, 20, 10, 70, $html, 0, 0, false, true, "R");
     $pdf->SetFontSize(15, 'B');
     $pdf->writeHTMLCell(170, 20, 20, 110, view('students::documents._examtable', compact('exams'))->render(), 0, 0, false, true, "C");
     $html = '<table border="0" width="100%"><tbody><tr><td>القبول والتسجيل</td></tr>
 <tr><td>مركز التعليم عن بعد - كلية العلوم الشرعية</td></tr></tbody></table>';
     $pdf->writeHTMLCell(130, 5, 90, 250, $html, 0, 0, false, true, "C");
     ob_clean();
     return $pdf;
 }
Beispiel #8
0
 public function student_exam_result($exam_id, $student_id)
 {
     $exam = Exam::findOrFail($exam_id);
     $questions = ExamQuestion::select('exams.id', 'exam_questions.question_id', 'answer', 'degree')->with('question', 'question.choices')->where('exam_questions.exam_id', $exam_id)->join('exams', function ($j) {
         $j->on('exam_questions.exam_id', '=', 'exams.id')->where('exams.semester_id', '=', semester()->id);
     })->join('exam_results', function ($j) use($student_id) {
         $j->on('exams.id', '=', 'exam_results.exam_id')->where('exam_results.semester_id', '=', semester()->id)->where('exam_results.student_id', '=', $student_id);
     })->join('exam_result_answers', function ($j) {
         $j->on('exam_results.id', '=', 'exam_result_answers.exam_result_id')->on('exam_questions.question_id', '=', 'exam_result_answers.question_id');
     })->get();
     $records = ExamRecording::select('stream_name', 'id')->where('student_id', $student_id)->where('exam_id', $exam_id)->get();
     return view('exams::exams.student_exam_result', compact('questions', 'exam', 'records'));
 }
 public function storequestion(QuestionRequest $request, $activity_id)
 {
     $question = new Question();
     Session::put('typeQ', $request->get('type'));
     $question->fill($request->all());
     $question->user_id = teacher()->id;
     $question->save();
     $exam = Exam::findOrFail($activity_id);
     $exam->questions()->detach($question->id);
     $exam->questions()->attach($question->id);
     $choices = $request->input('choices');
     if (!empty($choices)) {
         //not essay
         foreach ($choices as $key => $choice) {
             if ($request->get('type') != 'multiple_choice') {
                 if ($request->input('choices_correct_new_00') == $key) {
                     // TF or Single choice
                     $istrue = 1;
                 } else {
                     $istrue = 0;
                 }
             } else {
                 if (!empty($request->choices_correct_new)) {
                     //multiple_choice
                     //if(!empty($request->choices_correct_new))
                     if (array_key_exists($key, $request->choices_correct_new)) {
                         $istrue = 1;
                     } else {
                         $istrue = 0;
                     }
                     //$istrue = $request->input('choices_correct_new['.$key.']');
                 } else {
                     $istrue = 0;
                 }
             }
             Choice::create(['choice' => $choice, 'question_id' => $question->id, 'istrue' => $istrue]);
         }
     }
     $message = 'تم اضافة السؤال بنجاح';
     if (request('submit') == 'save') {
         return redirect()->route('teachers.profile.createquestion', array('id' => $activity_id))->with('success', $message);
     } else {
         $request->session()->forget('typeQ');
         return redirect()->route('teachers.profile.questions', array('id' => $activity_id))->with('success', $message);
     }
 }
Beispiel #10
0
 public function store(Request $request)
 {
     $error = 0;
     if (!$request->hasFile('answer')) {
         $error = 1;
         $message = 'لم تقم برفع أي ملف';
         return response()->json(compact('error', 'message'), 200, [], JSON_NUMERIC_CHECK);
     }
     $file = $request->file('answer');
     $exam_file = json_decode(file_get_contents($file->getRealPath()));
     if (empty($exam_file->exam_id)) {
         $error = 1;
         $message = 'الملف الذي رفعته غير صحيح';
         return response()->json(compact('error', 'message'), 200, [], JSON_NUMERIC_CHECK);
     }
     if (empty($exam_file->questions) or !is_array($exam_file->questions)) {
         $error = 1;
         $message = 'لا توجد إجابات بالاختبار الذي رفعته';
         return response()->json(compact('error', 'message'), 200, [], JSON_NUMERIC_CHECK);
     }
     $exam_id = $exam_file->exam_id;
     $student_id = $exam_file->student_id;
     if (!($exam = Exam::with('questions', 'questions.choices')->find($exam_id))) {
         $error = 1;
         $message = 'الاختبار الذي تحاول رفع إجابته غير موجود';
         return response()->json(compact('error', 'message'), 200, [], JSON_NUMERIC_CHECK);
     }
     $result_data = ['student_id' => $student_id, 'exam_id' => $exam->id, 'semester_id' => $exam->semester_id];
     $grade_per_question = 0.5;
     if ($exam->type == 'activity') {
         $grade_per_question = round($this->activity_points / $exam->questions->count(), 2);
     }
     // dd($grade_per_question);
     if ($result = ExamResult::firstOrCreate($result_data)) {
         $result_answers = [];
         $grade = 0.0;
         $answers = $exam_file->questions;
         foreach ($answers as $answer) {
             $result_answer = [];
             $result_answer['question_id'] = $answer->question_id;
             $result_answer['answer'] = $answer->answer;
             $result_answers[] = $result_answer;
         }
         StudentGrade::where('student_id', $student_id)->where(['ref_key' => 'exam', 'ref_value' => $exam->id])->delete();
         $result->answers()->delete();
         foreach ($result_answers as $a) {
             $result->answers()->create($a);
         }
         foreach ($exam->questions as $question) {
             switch ($question->type) {
                 case 'true_false':
                     $true_choice = $question->choices->first(function ($key, $choice) {
                         return $choice->istrue;
                     });
                     $is_true = array_where($answers, function ($key, $answer) use($true_choice) {
                         return $answer->answer == $true_choice->id;
                     });
                     // var_dump($true_choice->toArray());
                     if (count($is_true)) {
                         $grade += round($grade_per_question, 2);
                     }
                     break;
                 case 'single_choice':
                     $true_choice = $question->choices->first(function ($key, $choice) {
                         return $choice->istrue;
                     });
                     $is_true = array_where($answers, function ($key, $answer) use($true_choice) {
                         return $answer->answer == $true_choice->id;
                     });
                     if (count($is_true)) {
                         $grade += round($grade_per_question, 2);
                     }
                     break;
                 case 'multiple_choice':
                     $multiple_answer = array_first($answers, function ($key, $answer) use($question) {
                         return $answer->question_id == $question->id;
                     });
                     if ($multiple_answer) {
                         $all_answers = $multiple_answer ? explode(",", $multiple_answer->answer) : 0;
                         if (count($all_answers) == $question->choices->count()) {
                             $grade += "0.00";
                         } else {
                             $true_answers = $question->choices->filter(function ($question) {
                                 return $question->istrue;
                             });
                             if ($true_answers) {
                                 $true_answers_ids = $true_answers->pluck('id')->toArray();
                                 $intersect = array_intersect($all_answers, $true_answers_ids);
                                 $multichoice_grade = count($intersect) * ($grade_per_question / count($true_answers_ids));
                                 $grade += round($multichoice_grade, 2);
                             }
                         }
                     }
                     break;
             }
         }
         if ($exam->type == 'activity' && $grade > $this->activity_points) {
             $grade = $this->activity_points;
         }
         $data = ['student_id' => $student_id, 'value' => $grade, 'ref_value' => $exam->id, 'ref_key' => 'exam', 'subject_id' => $exam->subject_id, 'semester_id' => Semester()->id, 'notes' => 'درجة الأنشطة'];
         StudentGrade::create($data);
         $message = 'تم رفع الإجابة بنجاح';
         return response()->json(compact('error', 'message'), 200, [], JSON_NUMERIC_CHECK);
     } else {
         $error = 1;
         $message = 'لم يتم حفظ الإجابة!! حدث خلل.';
         return response()->json(compact('error', 'message'), 200, [], JSON_NUMERIC_CHECK);
     }
     return response()->json(compact('error', 'message'), 200, [], JSON_NUMERIC_CHECK);
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     //Exam
     Exam::created(function ($exam) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_exam', 'reference_id' => $exam->id]);
     });
     Exam::updated(function ($exam) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_exam', 'reference_id' => $exam->id]);
     });
     Exam::deleted(function ($exam) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_exam', 'reference_id' => $exam->id]);
     });
     //ExamCenter
     ExamCenter::created(function ($center) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_center', 'reference_id' => $center->id]);
     });
     ExamCenter::updated(function ($center) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_center', 'reference_id' => $center->id]);
     });
     ExamCenter::deleted(function ($center) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_center', 'reference_id' => $center->id]);
     });
     //ExamCenterPeriod
     ExamCenterPeriod::created(function ($period) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_period', 'reference_id' => $period->id]);
     });
     ExamCenterPeriod::updated(function ($period) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_period', 'reference_id' => $period->id]);
     });
     ExamCenterPeriod::deleted(function ($period) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_period', 'reference_id' => $period->id]);
     });
     //ExamQuestion
     ExamQuestion::created(function ($question) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_question', 'reference_id' => $question->id]);
     });
     ExamQuestion::updated(function ($question) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_question', 'reference_id' => $question->id]);
     });
     ExamQuestion::deleted(function ($question) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_question', 'reference_id' => $question->id]);
     });
     //ExamRecording
     ExamRecording::created(function ($recording) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_recording', 'reference_id' => $recording->id]);
     });
     ExamRecording::updated(function ($recording) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_recording', 'reference_id' => $recording->id]);
     });
     ExamRecording::deleted(function ($recording) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_recording', 'reference_id' => $recording->id]);
     });
     //ExamResult
     ExamResult::created(function ($result) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_result', 'reference_id' => $result->id]);
     });
     ExamResult::updated(function ($result) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_result', 'reference_id' => $result->id]);
     });
     ExamResult::deleted(function ($result) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_result', 'reference_id' => $result->id]);
     });
     //ExamResultAnswer
     ExamResultAnswer::created(function ($answer) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_answer', 'reference_id' => $answer->id]);
     });
     ExamResultAnswer::updated(function ($answer) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_answer', 'reference_id' => $answer->id]);
     });
     ExamResultAnswer::deleted(function ($answer) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_answer', 'reference_id' => $answer->id]);
     });
     //ExamRules
     ExamRules::created(function ($rule) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_rule', 'reference_id' => $rule->id]);
     });
     ExamRules::updated(function ($rule) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_rule', 'reference_id' => $rule->id]);
     });
     ExamRules::deleted(function ($rule) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_rule', 'reference_id' => $rule->id]);
     });
     //ExamExcuse
     ExamExcuse::created(function ($excuse) {
         UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_excuses', 'reference_id' => $excuse->id]);
     });
     ExamExcuse::updated(function ($excuse) {
         UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_excuses', 'reference_id' => $excuse->id]);
     });
     ExamExcuse::deleted(function ($excuse) {
         UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Exams_excuses', 'reference_id' => $excuse->id]);
     });
 }
Beispiel #12
0
 public function saveresult($subject_id = 0, $exam_id = 0, $student_id = 0, $exam_type = null)
 {
     # code...
     $exam = Exam::findOrFail($exam_id);
     $student = Student::findOrFail($student_id);
     $grade = config('exams.grade');
     $questions = ExamQuestion::select('exams.id', 'exam_results.id as exam_result_id', 'exam_questions.question_id', 'answer', 'degree', 'qbq.question as questionname', 'qbq.model_answer as modelanswer')->with('question', 'question.choices')->where('exam_questions.exam_id', $exam_id)->join('exams', function ($j) {
         $j->on('exam_questions.exam_id', '=', 'exams.id')->where('exams.semester_id', '=', semester()->id);
     })->join("questionbank_questions AS qbq", "qbq.id", '=', "exam_questions.question_id")->join('exam_results', function ($j) use($student_id) {
         $j->on('exams.id', '=', 'exam_results.exam_id')->where('exam_results.semester_id', '=', semester()->id)->where('exam_results.student_id', '=', $student_id);
     })->join('exam_result_answers', function ($j) {
         $j->on('exam_results.id', '=', 'exam_result_answers.exam_result_id')->on('exam_questions.question_id', '=', 'exam_result_answers.question_id');
     })->where('qbq.type', '=', 'essay')->get();
     return view('teachers::profile.tests.saveresult', compact('questions', 'subject_id', 'exam_id', 'grade', 'exam_type', 'student_id', 'student'));
 }
 public function move(Request $request)
 {
     $input = $request->all();
     $exam = Exam::findOrFail($input['exam_id']);
     $exam->questions()->attach($input['table_records']);
     return redirect()->route('exams.exams.display', $exam->id);
 }
Beispiel #14
0
 public function test(Request $request)
 {
     ClassroomSessionExcuse::truncate();
     ClassroomSessionAttendance::where('student_id', 10001)->update(['valid' => 0]);
     exit;
     $student_id = 4796;
     $order_dir = in_array($request->input('order_dir'), ['ASC', 'DESC']) ? $request->input('order_dir') : 'ASC';
     $exams = Exam::select('exams.type', 'exams.start_at', 'exams.finish_at', 'exams.name', 'exams.id')->join('subject_subjects as subsub', 'subsub.id', '=', 'exams.subject_id')->join('student_subjects as stusub', function ($j) use($student_id) {
         $j->on('stusub.subject_id', '=', 'subsub.id')->where('stusub.student_id', '=', $student_id)->where('stusub.state', '=', 'study');
     })->where(function ($query) use($request, $student_id) {
         $query->orWhereIn('exams.type', ['midterm', 'remidterm'])->orWhereRaw('exams.id IN (SELECT ce.exam_id FROM classrooms_exam as ce
                             JOIN classrooms as c ON c.id = ce.classroom_id
                             JOIN classroom_students as cs ON cs.classroom_id = c.id
                                 AND cs.student_id = ' . $student_id . '
                             WHERE exam_id = exams.id GROUP BY ce.id)');
         if ($request->has('finalExam')) {
             $query->orWhereIn('exams.type', ['final', 'summer', 'refinal']);
         }
     })->where('exams.semester_id', semester()->id)->where('finish_at', '>=', date('Y-m-d H:i:s'))->groupBy('exams.id')->orderBy('exams.start_at', $order_dir)->with(['questions' => function ($w) {
         $w->select('questionbank_questions.id', 'questionbank_questions.question', 'questionbank_questions.type');
         if (false) {
             $w->orderByRaw('RAND()');
         } else {
             $w->orderBy('questionbank_questions.type', 'DESC');
         }
     }, 'questions.choices' => function ($w) {
         $w->select('questionbank_choices.id', 'questionbank_choices.question_id', 'questionbank_choices.choice', 'questionbank_choices.istrue');
     }])->get();
     return $exams;
     exit;
     $specialities = Specialty::selectRaw('asp.id, asp.name, asp.short_description, asp.description, GROUP_CONCAT(adp.subject_ids) as subject_ids, COUNT(adt.id) as terms, COUNT(DISTINCT ady.id) as years')->leftJoin('academystructure_departments as adp', 'adp.spec_id', '=', 'asp.id')->leftJoin('academystructure_terms as adt', 'adt.id', '=', 'adp.term_id')->leftJoin('academystructure_years as ady', 'ady.id', '=', 'adt.year_id')->from('academystructure_specialties as asp')->groupBy('asp.id')->with('departments')->get();
     foreach ($specialities as $specialty) {
         $subject_ids = explode(",", preg_replace(['/\\[/', "/\\]/"], "", $specialty->subject_ids));
         $specialty->hours = Subject::whereIn('id', $subject_ids)->sum('hour');
         foreach ($specialty->departments as $department) {
             $subject_ids = explode(",", preg_replace(['/\\[/', "/\\]/", '/"/', "/'/"], "", $department->subject_ids));
             // var_dump($subject_ids);
             $department->subjects = Subject::whereIn('id', $subject_ids)->get();
         }
     }
     $specialities->makeHidden(['subject_ids']);
     return $specialities;
     exit;
     $status_ping_url = \App::environment('local') ? 'http://46.40.236.186:9090/DARES/public/classrooms/classrooms/status_ping' : route('classrooms.sessions.status-ping');
     $WiziqApi = new WiziqApi();
     try {
         $wiziqclassroom = WiziqClassroom::build("test", new DateTime("2016-08-10 23:55:00"))->withPresenter(20, "test teacher")->withAttendeeLimit(config("classrooms.attendee_limit"))->withReturnUrl('https://el-css.edu.om')->withDuration(10)->withExtendDuration(0)->withStatusPingUrl($status_ping_url)->withTimeZone("Asia/Muscat")->withLanguageCultureName("ar-SA")->withCreateRecording(true);
         $response = $WiziqApi->create($wiziqclassroom);
         \Log::info($response);
         exit(var_dump($response));
         $data = ['wiziq_id' => $response['class_id'], 'recording_link' => $response['recording_url'], 'presenter_link' => $response['presenter_url']];
         /** add attendees to virtual classroom */
         Log::info($response);
         if ($session->fill($data)->save() && $response) {
             $error = $this->createStudentsSessions($classroom->students, $session);
         }
     } catch (\mikemix\Wiziq\Common\Api\Exception\CallException $e) {
         $error = 1;
     } catch (\mikemix\Wiziq\Common\Http\Exception\InvalidResponseException $e) {
         $error = 1;
     } catch (\PDOException $e) {
         $error = 1;
     }
     if ($error == 0) {
         event(new VirtualClassroomsCreated());
     } else {
         $session->wiziq_status = 'error';
         $session->save();
     }
 }