/**
  * Boot the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->registerTranslations();
     $this->registerConfig();
     $this->registerViews();
     StudentGrade::creating(function ($grade) {
         $grade->semester_id = semester()->id;
     });
     Relation::morphMap(['students' => \Modules\Students\Entities\Student::class]);
 }
Esempio n. 2
0
 public function index($student_id, Request $request)
 {
     if (!$student_id) {
         return redirect()->rotue('students.students.index');
     }
     $grades = StudentGrade::where('student_grades.student_id', $student_id)->select('student_grades.*', 'exams.id as exam_id', 'exams.name as exam_name')->with('semester', 'subject')->leftJoin("exams", function ($j) {
         $j->on('exams.id', '=', 'student_grades.ref_value')->where('student_grades.ref_key', '=', 'exam');
     })->groupBy('student_grades.id')->get();
     $student = Student::findOrFail($student_id);
     if ($request->has('partial')) {
         return view('students::grades._list', compact('grades', 'student'));
     }
     return view('students::grades.index', compact('grades', 'student'));
 }
Esempio n. 3
0
 /**
  * Display a listing of the resource.student_subjects
  * @return Response
  */
 public function index(Request $request)
 {
     $statistics = StudentGrade::where('student_grades.semester_id', semester()->id)->select('subject_id', 'student_id', DB::raw('SUM(value) as sgrade'))->with(['subject', 'student' => function ($query) {
         $query->whereHas('subjects', function ($q) {
             $q->where('semester_id', semester()->id);
             $q->where('state', 'study');
         });
     }])->groupBy('student_id', 'subject_id')->orderBy('student_id');
     if (request('mark_from')) {
         $statistics->having('sgrade', '>=', request('mark_from'));
     }
     if (request('mark_to')) {
         $statistics->having('sgrade', '<', request('mark_to'));
     }
     $statistics = $statistics->get()->groupBy('student_id')->get();
     // dd($statistics);
     return view('exams::reports.index', compact('statistics'));
 }
Esempio n. 4
0
 public function show($student_id)
 {
     $student = Student::with(['classrooms', 'registration', 'registration.type', 'department', 'subjects'])->select('students.*')->joinTermName()->findOrFail($student_id);
     $grades = StudentGrade::with('semester', 'subject')->inCurrentSemester()->where('student_id', $student->id)->get();
     $registration = $student->registration;
     //$study_plan = getspecialtystruct(1);
     if ($student->department->spec_id) {
         $study_plan = getspecialtystruct($student->department->spec_id);
     } else {
         $study_plan = getspecialtystruct(2);
     }
     //dd($study_plan);
     $departments = Department::select(\DB::raw('GROUP_CONCAT(subject_ids) as sid , id as name'))->where('spec_id', 1)->get()->toArray();
     $departments_subjects;
     foreach ($departments as $key => &$aa) {
         $a = implode(',', array_unique(array_merge(json_decode(str_replace('],[', ',', $aa['sid']), TRUE))));
         $departments_subjects = explode(',', $a);
     }
     $student_subjects = StudentSubject::select(\DB::raw('GROUP_CONCAT(subject_id) as sid'))->where('student_id', $student_id)->where('state', 'success')->get()->toArray();
     $student_subject_ids = explode(',', $student_subjects[0]['sid']);
     $result = array_diff($departments_subjects, $student_subject_ids);
     $complete_deplome_subjects = empty($result);
     return view('students::students.show', compact('student', 'registration', 'grades', 'study_plan', 'study_subject', 'state_complite_sub', 'complete_deplome_subjects'));
 }
Esempio n. 5
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);
 }
 /**
  * Update the specified resource in storage.
  * @param  Request $request
  * @return Response
  */
 public function update(Request $request, $recording_id = 0, $student_id = 0)
 {
     $recording = QuranRecording::with('student', 'subject')->findOrFail($recording_id);
     $grade_data = ['student_id' => $recording->student_id, 'semester_id' => semester()->id, 'ref_key' => 'quran_recordings', 'ref_value' => $recording->id, 'subject_id' => $recording->subject_id];
     $grade = StudentGrade::firstOrCreate($grade_data);
     $grade->value = $request->input('result');
     $grade->save();
     $recording->update(['user_id' => user()->id]);
     $message = 'تم حفظ التقييم';
     if (request('submit') == 'save') {
         return redirect()->route('evaluate_quran.index')->with('success', $message);
     }
 }
Esempio n. 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->comment(PHP_EOL . 'adding' . PHP_EOL);
     $WiziqApi = new WiziqApi();
     // $report = $WiziqApi->getAttendanceReport(5435948);
     // var_dump($report);
     // exit;
     $sessions = ClassroomSession::select('classroom_sessions.id', 'classroom_sessions.wiziq_id', 'classroom_sessions.title', 'classroom_sessions.classroom_id', 'classroom_sessions.subject_subject_id')->leftJoin('classroom_session_attendances as csa', 'classroom_sessions.id', '=', 'csa.classroom_session_id')->whereNull('csa.id')->with('subject')->groupBy('classroom_sessions.id')->whereCanceled(0)->whereDate('classroom_sessions.start_at', '>', date('2016-10-30'))->where('start_at', '<', date('Y-m-d H:i:s', strtotime('-60 minutes')))->get();
     $this->comment(PHP_EOL . $sessions->count() . PHP_EOL);
     foreach ($sessions as $session) {
         $all_classroom_students = ClassroomStudent::where('classroom_id', $session->classroom_id)->where('semester_id', semester()->id)->pluck('student_id')->toArray();
         // $WiziqApi = new WiziqApi;
         try {
             $report = $WiziqApi->getAttendanceReport($session->wiziq_id);
         } catch (\mikemix\Wiziq\Common\Api\Exception\CallException $e) {
             continue;
         }
         if (empty($report)) {
             continue;
         }
         ClassroomSession::where('id', $session->id)->update(['wiziq_status' => 'completed', 'wiziq_recording_status' => 'available']);
         // $session->wiziq_status = 'completed';
         // $session->wiziq_recording_status = 'available';
         // $session->save();
         $attendances = collect();
         // var_dump($report);
         // exit;
         // dd('out');
         foreach ($report as $attendee) {
             $student_id = NULL;
             $teacher_id = NULL;
             if (empty($attendee['presenter_id']) && !empty($attendee['attendee_id'])) {
                 $student_id = $attendee['attendee_id'];
                 if (!in_array($student_id, $all_classroom_students)) {
                     continue;
                 }
             } elseif (!empty($attendee['presenter_id'])) {
                 $teacher_id = $attendee['presenter_id'];
             } else {
                 continue;
             }
             $data = ['teacher_id' => $teacher_id, 'student_id' => $student_id, 'classroom_session_id' => $session->id, 'entry_time' => Date::parse($attendee['entry_time'])->format('Y-m-d H:i:s'), 'exit_time' => Date::parse($attendee['exit_time'])->format('Y-m-d H:i:s'), 'attended_minutes' => $attendee['attended_minutes']];
             $attendance = ClassroomSessionAttendance::create($data);
             if ($student_id && in_array($student_id, $all_classroom_students)) {
                 $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' => $attendance->attended_minutes, 'session' => $session->title, 'subject' => $session->subject->name]), 'ref_value' => $attendance->id];
                 $StudentGrade = new StudentGrade();
                 $StudentGrade->fill($data)->save();
             } else {
                 // $data['teacher_id'] = $attendance->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]);
             }
             $attendances->push($attendance);
         }
         $student_ids = $attendances->whereLoose('teacher_id', NULL)->pluck('student_id')->toArray();
         $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' => 1, 'valid' => 0];
             event(new StudentAbsentSession($student, $session, $session->subject));
             ClassroomSessionAttendance::create($data);
             // $attendances->push($attendance);
         }
     }
     $this->comment(PHP_EOL . 'added' . PHP_EOL);
 }
Esempio n. 8
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);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // echo 'in';
     if (StudentSubject::count()) {
         // return;
     }
     // $user_subjects = DB::connection('old')
     //   ->table('user_subject')
     //   // ->where('us_userid', 148)
     //   ->get();
     // echo DB::connection('old')->table('user_subject')->count();
     // exit;
     // $this->call("OthersTableSeeder");
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     StudentSubject::where('student_id', '!=', 10000)->delete();
     // StudentSubject::truncate();
     StudentGrade::where('student_id', '!=', 10000)->delete();
     // StudentGrade::truncate();
     $all_user_subjects = DB::connection('old')->table('user_subject')->leftJoin('users', 'users.user_id', '=', 'user_subject.us_userid')->select('users.user_academyid', 'us_state', 'us_subid', 'us_userid', 'us_semid', 'us_result')->get();
     // echo 'got it';
     $new_departments = $new_department = Department::select('ad.id', 'ay.id AS ay_id', 'as.code')->join('academystructure_terms as at', 'at.id', '=', 'ad.term_id')->join('academystructure_years as ay', function ($j) {
         $j->on('at.year_id', '=', 'ay.id');
         // ->where('ay.id', '=',$academy['academy_year']);
     })->join('academystructure_specialties as as', function ($j) {
         $j->on('as.id', '=', 'ad.spec_id');
         // ->where('as.code', '=', $dep_sepcialty_code);
     })->from('academystructure_departments as ad')->get()->toArray();
     $all_old_academies = $academy = DB::connection('old')->table('sub_academy')->select('academy_department', 'academy_year', 'academy_term')->select('academy.*', 'sub_academy.sub_acad_subid')->join('academy', 'sub_acad_academyid', '=', 'academy_id')->get();
     $all_old_academies = array_map(function ($a) {
         return (array) $a;
     }, $all_old_academies);
     $student_subjects = [];
     $student_grades = [];
     // var_dump(count($all_user_subjects));
     foreach ($all_user_subjects as $user_subject) {
         $student_subject = [];
         $student_grade = [];
         $state = $user_subject->us_state == 'sucess' ? 'success' : $user_subject->us_state;
         $state = $state == 'edu' ? 'study' : $state;
         $state = $state == 'equ' ? 'equal' : $state;
         if ($user_subject->us_semid == 9) {
             $academy = array_filter($all_old_academies, function ($a) use($user_subject) {
                 return $user_subject->user_academyid == $a['academy_id'];
             });
         } else {
             $academy = array_filter($all_old_academies, function ($a) use($user_subject) {
                 return $user_subject->us_subid == $a['sub_acad_subid'];
             });
         }
         $academy = current($academy);
         if (empty($academy)) {
             continue;
         }
         $dep_sepcialty_code = 'D';
         if ($academy['academy_department'] == 'اصول الفقة') {
             $dep_sepcialty_code = 'O';
         } elseif ($academy['academy_department'] == 'الدرسات الاسلامية') {
             $dep_sepcialty_code = 'I';
         }
         $new_departments_filtered = array_filter($new_departments, function ($d) use($academy, $dep_sepcialty_code) {
             $exist = $d['ay_id'] == $academy['academy_year'] && $d['code'] == $dep_sepcialty_code;
             if ($exist) {
                 // var_dump($d);
             }
             return $exist;
         });
         if ($academy['academy_term'] == 2) {
             $new_department = array_pop($new_departments_filtered);
         } else {
             $new_department = array_shift($new_departments_filtered);
         }
         $student_subject['student_id'] = $user_subject->us_userid;
         $student_subject['subject_id'] = $user_subject->us_subid;
         $student_subject['semester_id'] = $user_subject->us_semid;
         $student_subject['state'] = $state;
         $student_subject['academystructure_department_id'] = $new_department['id'];
         $student_grade['student_id'] = $user_subject->us_userid;
         $student_grade['subject_id'] = $user_subject->us_subid;
         $student_grade['semester_id'] = $user_subject->us_semid;
         $student_grade['notes'] = "تم جلبها من النظام القديم";
         $student_grade['value'] = $user_subject->us_result;
         $student_grade['created_at'] = new DateTime();
         $student_grade['updated_at'] = new DateTime();
         if ($user_subject->us_result >= 0) {
             $student_grades[] = $student_grade;
         }
         $student_subjects[] = $student_subject;
     }
     foreach (array_chunk($student_subjects, 1000) as $chunk) {
         DB::table('student_subjects')->insert($chunk);
     }
     foreach (array_chunk($student_grades, 1000) as $chunk) {
         DB::table('student_grades')->insert($chunk);
     }
 }
Esempio n. 10
0
 private function generateReport($session)
 {
     $WiziqApi = new WiziqApi();
     $report = $WiziqApi->getAttendanceReport($session->wiziq_id);
     $attendances = collect();
     foreach ($report as $attendee) {
         $data = ['teacher_id' => !empty($attendee['presenter']) ? $attendee['attendee_id'] : NULL, 'student_id' => empty($attendee['presenter']) ? $attendee['attendee_id'] : NULL, 'classroom_session_id' => $session->id, 'entry_time' => Date::parse($attendee['entry_time'])->format('Y-m-d H:i:s'), 'exit_time' => Date::parse($attendee['exit_time'])->format('Y-m-d H:i:s'), 'attended_minutes' => $attendee['attended_minutes']];
         $attendance = ClassroomSessionAttendance::create($data);
         if ($attendance->student_id) {
             $data = ['student_id' => $attendance->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' => $attendance->attended_minutes, 'session' => $session->title, 'subject' => $session->subject->name]), 'ref_value' => $attendance->id];
             $StudentGrade = new StudentGrade();
             $StudentGrade->fill($data)->save();
         }
         $attendances->push($attendance);
     }
     $student_ids = $attendances->whereLoose('teacher_id', NULL)->pluck('student_id')->toArray();
     $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' => 1, 'valid' => 0];
         $attendance = ClassroomSessionAttendance::create($data);
         $attendances->push($attendance);
     }
     return $attendances;
 }
Esempio n. 11
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', 'تم حفظ الدرجه بنجاح');
 }