/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $this->comment(PHP_EOL . 'modifiyng' . PHP_EOL);
     $sessions = ClassroomSession::select('id', 'teacher_id', 'admin_link', 'subject_subject_id', 'interval_id', 'title', 'wiziq_id', 'duration', 'start_at')->whereDate('start_at', '=', date('Y-m-d'))->with('subject', 'interval', 'teacher')->get();
     foreach ($sessions as $session) {
         try {
             $classroom = WiziqClassroom::build($session->interval->title . " - " . $session->subject->name, new \DateTime($session->start_at))->withDuration($session->duration)->withPresenter($session->teacher->id, $session->teacher->name)->withAttendeeLimit(config("classrooms.attendee_limit"))->withReturnUrl('')->withCreateRecording(true)->withPresenterDefaultControls('audio, video')->withTimeZone("Asia/Muscat")->withStatusPingUrl("https://www.google.com")->withLanguageCultureName("ar-SA");
             $WiziqApi = new WiziqApi();
             $WiziqApi->modify($session->wiziq_id, $classroom);
             $attendees = Attendees::build()->add(9999999999.0, 'النظام', 'ar-SA');
             $response = $WiziqApi->addAttendeesToClass($session->wiziq_id, $attendees);
             $session->admin_link = $response[0]['url'];
             $session->save();
         } catch (\mikemix\Wiziq\Common\Api\Exception\CallException $e) {
             Mail::send('emails.classrooms_modify', ['error' => $e->getMessage(), 'time' => $session->start_at], function ($m) {
                 $m->to('*****@*****.**', 'علي اليزيدي')->to('*****@*****.**', 'محسن بخيش')->subject('حدث مشكل اثناء تعديل الفصول');
             });
             $this->comment(PHP_EOL . $e->getMessage() . " - " . $session->id . ' - ' . $session->start_at . PHP_EOL);
         } catch (\mikemix\Wiziq\Common\Http\Exception\InvalidResponseException $e) {
             Mail::send('emails.classrooms_modify', ['error' => $e->getMessage(), 'time' => $session->start_at], function ($m) {
                 $m->to('*****@*****.**', 'علي اليزيدي')->to('*****@*****.**', 'محسن بخيش')->subject('حدث مشكل اثناء تعديل الفصول');
             });
             $this->comment(PHP_EOL . $e->getMessage() . " - " . $session->id . ' - ' . $session->start_at . PHP_EOL);
         }
     }
     $this->comment(PHP_EOL . 'finished modifiyng' . PHP_EOL);
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $sessions = $this->sessions;
     $WiziqApi = new WiziqApi();
     foreach ($sessions as $session) {
         if ($WiziqApi->cancel($session->wiziq_id)) {
             $session->update(['canceled' => 1]);
         }
     }
 }
Esempio n. 3
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;
 }
Esempio n. 5
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. 6
0
 public function attendeeurl(ClassroomSession $session)
 {
     $url = Cache::remember('session_url_for_admin' . $session->wiziq_id, 360, function () use($session) {
         $classroomId = $session->wiziq_id;
         $error = 0;
         $WiziqApi = new WiziqApi();
         $attendees = Attendees::build()->add(9999999999.0, 'النظام', 'ar-SA');
         // add more if needed
         //Log::info("added attendees");
         try {
             $response = $WiziqApi->addAttendeesToClass($classroomId, $attendees);
             return $response[0]['url'];
         } catch (\mikemix\Wiziq\Common\Http\Exception\InvalidResponseException $e) {
             return back()->with('error', 'وقع خلل');
         }
     });
     return redirect($url);
 }
Esempio n. 7
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();
     }
 }