Esempio n. 1
0
 /**
  * @see http://developer.wiziq.com/class/status-ping
  * @param  Request $request request comming from wiziq as POST
  * @return void
  */
 public function statusPing(Request $request)
 {
     $input = $request->all();
     // \Log::info($input);
     // \Log::info('status ping received');
     // \Log::info($input);
     if (empty($input)) {
         return response()->json("ACCEPT POST ONLY");
     }
     $session = DB::table('classroom_sessions')->where('wiziq_id', $input['class_id'])->first();
     if ($session) {
         if (!empty($input['class_status'])) {
             DB::table('classroom_sessions')->where('id', $session->id)->update(['wiziq_status' => $input['class_status']]);
             // $session->save();
         }
         if (!empty($input['recording_status'])) {
             DB::table('classroom_sessions')->where('id', $session->id)->update(['wiziq_recording_status' => $input['recording_status']]);
             // $session->wiziq_recording_status = $input['recording_status'];
             // $session->save();
             if ($input['recording_status'] == 'available') {
                 //$this->generateReport($session);
             }
         }
         exit;
         if (!empty($input['attendance_report_status']) and $input['attendance_report_status'] == 'available' && isset($input['attendance_report_file'])) {
             if (ClassroomSessionAttendance::where('classroom_session_id', $session->id)->count()) {
                 exit;
             }
             // $client = new CurlClient();
             // $rawResponse = $client->getResponse($input['attendance_report_file'], []);
             $file = $request->file('attendance_report_file');
             $xmlObject = simplexml_load_string(File::get($file->getRealPath()));
             $response = new WiziqResponse($xmlObject);
             if (!$response->isSuccess()) {
                 throw mikemix\Wiziq\Common\Api\Exception\CallException::from($response);
             }
             $response = $response->getResponse();
             $student_ids = [];
             if ((int) $response->class_id == $session->wiziq_id) {
                 // Log::info($response->attendee_list[0]);
                 foreach ($response->attendee_list[0] as $attendee) {
                     $student_id = null;
                     $teacher_id = null;
                     if (isset($attendee['presenter']) and $attendee['presenter'] == true && !empty((int) $attendee->attendee_id)) {
                         $teacher_id = (int) $attendee->attendee_id;
                     } elseif (!empty((int) $attendee->attendee_id)) {
                         $student_id = (int) $attendee->attendee_id;
                     } else {
                         continue;
                     }
                     $data = ['entry_time' => Date::parse((string) $attendee->entry_time)->format('Y-m-d H:i:s'), 'exit_time' => Date::parse((string) $attendee->exit_time)->format('Y-m-d H:i:s'), 'classroom_session_id' => $session->id, 'teacher_id' => $teacher_id, 'student_id' => $student_id, 'attended_minutes' => (int) $attendee->attended_minutes];
                     if ($teacher_id) {
                         TeacherFund::create(['teacher_id' => $teacher_id, 'amount' => config('classrooms.payment_per_session'), 'reference_key' => 'session', 'reference_id' => $session->id, 'semester_id' => semester()->id]);
                     } elseif ($student_id) {
                         $student_ids[] = $student_id;
                     }
                     $attendance = ClassroomSessionAttendance::create($data);
                     if ($student_id) {
                         $grade_data = ['student_id' => $student_id, 'subject_id' => $session->subject_subject_id, 'value' => $session->subject->hours == 2 ? 2.5 : 2, 'ref_key' => 'attendance', 'notes' => trans('classrooms::attendances.attended_for', ['attended_minutes' => (int) $attendee->attended_minutes, 'session' => $session->title, 'subject' => $session->subject->name]), 'ref_value' => $attendance->id];
                         StudentGrade::create($grade_data);
                     }
                 }
                 $students = Student::whereHas('classrooms', function ($query) use($session) {
                     return $query->where('classrooms.id', $session->classroom_id);
                 })->whereNotIn('id', $student_ids)->get();
                 foreach ($students as $student) {
                     $data = ['teacher_id' => NULL, 'student_id' => $student->id, 'classroom_session_id' => $session->id, 'entry_time' => NULL, 'exit_time' => NULL, 'attended_minutes' => 0, 'manual' => 0, 'valid' => 0];
                     event(new StudentAbsentSession($student, $session, $session->subject));
                     ClassroomSessionAttendance::create($data);
                 }
             }
         }
     }
 }
Esempio n. 2
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);
 }
Esempio n. 3
0
 public function storeresult(Request $request)
 {
     $value = $request->value;
     $student_id = $request->student_id;
     $subject_id = $request->subject_id;
     $exam_id = $request->exam_id;
     $question_id = $request->question_id;
     $exam_type = $request->exam_type;
     StudentGrade::where('student_id', $student_id)->where(['ref_key' => 'examessay', 'ref_value' => $exam_id])->delete();
     DB::table('exam_result_answers')->where('exam_result_id', '=', $exam_id)->where('question_id', '=', $question_id)->delete();
     $data = ['student_id' => $student_id, 'value' => $value, 'ref_value' => $exam_id, 'ref_key' => 'examessay', 'subject_id' => $subject_id, 'semester_id' => Semester()->id, 'notes' => 'درجة المقالى'];
     StudentGrade::create($data);
     DB::table('exam_result_answers')->insert(['exam_result_id' => $exam_id, 'question_id' => $question_id, 'degree' => $value, 'answer' => 'essay']);
     return redirect()->route('teachers.profile.students', [$subject_id, $exam_type])->with('success', 'تم حفظ الدرجه بنجاح');
 }