Esempio n. 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]);
     // }
 }
Esempio n. 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->comment(PHP_EOL . 'adding' . PHP_EOL);
     $sessions = ClassroomSession::select('classroom_sessions.wiziq_id', 'classroom_sessions.id', 'classroom_sessions.classroom_id')->whereDate('classroom_sessions.start_at', '>', date('Y-m-d'))->with(['classroom' => function ($query) {
         return $query->select('classrooms.id');
     }, 'classroom.students' => function ($query) {
         return $query->select('students.id', 'students.name');
     }, 'studentsSessions' => function ($query) {
         return $query->select('student_id', 'classroom_session_id');
     }])->get();
     foreach ($sessions as $session) {
         $classroomId = $session->wiziq_id;
         $error = 0;
         $WiziqApi = new WiziqApi();
         // var_dump($session->classroom->students->count());
         foreach ($session->classroom->students as $student) {
             $exist = $session->studentsSessions->filter(function ($value) use($student) {
                 return $value->student_id == $student->id;
             });
             if ($exist->count()) {
                 continue;
             }
             $this->comment(PHP_EOL . ' not exist ' . PHP_EOL);
             try {
                 $attendees = Attendees::build()->add($student->id, $student->name, 'ar-SA');
                 // add more if needed
                 $response = $WiziqApi->addAttendeesToClass($classroomId, $attendees);
                 $data = ['student_link' => $response[0]['url'], 'attendee_id' => $response[0]['id'], 'classroom_session_id' => $session->id, 'student_id' => $student->id, 'semester_id' => semester()->id];
                 StudentClassroomSession::create($data);
             } catch (\mikemix\Wiziq\Common\Api\Exception\CallException $e) {
                 $this->comment(PHP_EOL . ' call exception ' . PHP_EOL);
                 $error = 1;
             } catch (\mikemix\Wiziq\Common\Http\Exception\InvalidResponseException $e) {
                 $this->comment(PHP_EOL . ' invalid response exception ' . PHP_EOL);
                 $error = 1;
             } catch (\ErrorException $e) {
                 $this->comment(PHP_EOL . ' error exception ' . PHP_EOL);
                 $error = 1;
             }
         }
     }
     $this->comment(PHP_EOL . 'added' . PHP_EOL);
 }
 private function createStudentsSessions($students, $session)
 {
     $classroomId = $session->wiziq_id;
     $error = 0;
     $WiziqApi = new WiziqApi();
     //Log::info("adding attendeees");
     foreach ($students as $student) {
         try {
             $attendees = Attendees::build()->add($student->id, $student->name, 'ar-SA');
             // add more if needed
             //Log::info("added attendees");
             $response = $WiziqApi->addAttendeesToClass($classroomId, $attendees);
             //Log::info($response);
             $data = ['student_link' => $response[0]['url'], 'attendee_id' => $response[0]['id'], 'classroom_session_id' => $session->id, 'student_id' => $student->id, 'semester_id' => semester()->id];
             //Log::info($data);
             StudentClassroomSession::create($data);
             //Log::info(var_dump($response));
         } catch (\mikemix\Wiziq\Common\Api\Exception\CallException $e) {
             // Log::warning($e->getMessage());
             $error = 1;
         } catch (\mikemix\Wiziq\Common\Http\Exception\InvalidResponseException $e) {
             // Log::warning($e->getMessage());
             $error = 1;
         } catch (\ErrorException $e) {
             $error = 1;
         }
     }
     return $error;
 }