/** * 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); }
/** * Register the service provider. * * @return void */ public function register() { //Teacher Teacher::created(function ($teacher) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]); }); Teacher::updated(function ($teacher) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]); }); Teacher::deleted(function ($teacher) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_teacher', 'reference_id' => $teacher->id]); }); //TeacherFund TeacherFund::created(function ($fund) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]); }); TeacherFund::updated(function ($fund) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]); }); TeacherFund::deleted(function ($fund) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_fund', 'reference_id' => $fund->id]); }); //TeacherGuide TeacherGuide::created(function ($guide) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]); }); TeacherGuide::updated(function ($guide) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]); }); TeacherGuide::deleted(function ($guide) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_guide', 'reference_id' => $guide->id]); }); //TeacherMessage TeacherMessage::created(function ($message) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]); }); TeacherMessage::updated(function ($message) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]); }); TeacherMessage::deleted(function ($message) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_message', 'reference_id' => $message->id]); }); //TeacherMessageAttachment TeacherMessageAttachment::created(function ($messageattach) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]); }); TeacherMessageAttachment::updated(function ($messageattach) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]); }); TeacherMessageAttachment::deleted(function ($messageattach) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_messageattach', 'reference_id' => $messageattach->id]); }); //TeacherSubject TeacherSubject::created(function ($subject) { UserLog::create(['operation' => 'create', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]); }); TeacherSubject::updated(function ($subject) { UserLog::create(['operation' => 'update', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]); }); TeacherSubject::deleted(function ($subject) { UserLog::create(['operation' => 'delete', 'user_id' => user() ? user()->id : NULL, 'reference_key' => 'Teachers_subject', 'reference_id' => $subject->id]); }); }
/** * @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); } } } } }