Exemple #1
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]);
     // }
 }
 /**
  * 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);
 }
 public function storeclassroom($subject_id, $student_id, ClassroomStudent $classroomModel, Request $request)
 {
     # code...
     $classroomModel->student_id = $student_id;
     $classroomModel->semester_id = semester()->id;
     $classroomModel->classroom_id = $request->input('classroom_id');
     $classroomModel->save();
     $submit = $request->input('submit');
     $message = 'تمت إضافة الطالب بنجاح';
     if ($submit == 'exit') {
         return redirect()->route('students.subjects.classrooms', $student_id)->with('success', $message);
     }
     return redirect()->back()->with('success', $message);
 }