private function createFromExcel() { $semester_id = semester()->id; $results = Excel::load($this->filename)->get()->all(); // dd(get_class_methods($results)); $subjects_codes = []; $teachers_usernames = []; $classrooms_codes = []; foreach ($results as $sheet) { $item = $sheet->all(); if (empty($item[1]) || empty($item[2]) || empty($item[3])) { continue; } $teachers_usernames[] = $item[2]; $subjects_codes[] = $item[1]; $classrooms_codes[] = $item[3]; } $teachers = Teacher::whereIn('username', $teachers_usernames)->pluck('id', 'username')->toArray(); $subjects = Subject::whereIn('code', $subjects_codes)->pluck('id', 'code')->toArray(); $classrooms = Classroom::whereIn('code', $classrooms_codes)->inCurrentSemester()->pluck('id', 'code')->toArray(); $new_classrooms = []; foreach ($results as $sheet) { $item = $sheet->all(); if (empty($item[1]) || empty($item[2]) || empty($item[3])) { continue; } if (!isset($classrooms[$item[3]]) && isset($teachers[$item[2]]) && isset($subjects[$item[1]]) && in_array($item[5], ['m', 'f', 'b'])) { $new_classrooms[] = ['code' => $item[3], 'day' => $item[4] - 1, 'gender' => $item[5], 'teacher_id' => $teachers[$item[2]], 'subject_subject_id' => $subjects[$item[1]], 'semester_id' => $semester_id, 'attendees_limit' => 100, 'created_at' => new DateTime(), 'updated_at' => new DateTime()]; } } if (!empty($new_classrooms)) { Classroom::insert($new_classrooms); } event(new CreateClassroomsFromExcelFinished()); }
public function index() { $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)); $department->subjects = Subject::whereIn('id', $subject_ids)->get(); } } $specialities->makeHidden(['subject_ids']); return response()->json($specialities, 200, [], JSON_NUMERIC_CHECK); }
public function getGrades() { $student = Student::select('students.*')->with('registration', 'registration.nationalitycountry')->joinTermName()->findOrFail($this->student_id); $registration = $student->registration; $semesters = get_student_grades($student->id); // $gpa = GPA($semesters); $gpa = GPA($semesters); $valuation = check_final_valuation($gpa); $subject_ids = Department::where('spec_id', $student->specialty_id)->pluck('subject_ids'); $subject_ids = array_unique(json_decode(str_replace("][", ",", implode("", json_decode($subject_ids, TRUE))), TRUE)); $success_subjects = StudentSubject::whereIn('subject_id', $subject_ids)->where('state', 'success')->groupBy('subject_id')->where('student_id', $student->id)->pluck('subject_id'); $studied_subjects = StudentSubject::whereIn('subject_id', $subject_ids)->whereIn('state', ['success', 'fail'])->where('student_id', $student->id)->pluck('subject_id'); $student_hours = Subject::whereIn("id", $subject_ids)->sum('hour'); $fail_hours = Subject::whereIn("id", $studied_subjects)->sum('hour'); $success_hours = Subject::whereIn("id", $success_subjects)->sum('hour'); /** setup pdf library for arabic content */ $pdf = $this->preparePdf(); // test some inline CSS $pdf->SetFontSize(22); // $html = '<table border="0" width="100%"><tbody><tr><td>كشف درجات الطالب : '.$student->name.'</td></tr></tbody></table>'; // $pdf->writeHTMLCell(210,20,0,10,$html, 0, 0, false, true, "C"); if ($student->gender == 'f') { $name = $student->registration->first_name . ' بنت ' . $student->registration->second_name . ' بن ' . $student->registration->third_name . ' ' . $student->registration->last_name; } else { $name = $name = $student->registration->first_name . ' بن ' . $student->registration->second_name . ' بن ' . $student->registration->third_name . ' ' . $student->registration->last_name; } $html = '<table cellspacing="0" cellpadding="2" border="1"> <tbody> <tr> <td bgcolor="#D9DEE4" align="center">اسم الطالب</td> <td align="center" colspan="2">' . $name . '</td> <td bgcolor="#D9DEE4" align="center">الجنسية</td> <td align="center">' . (!empty($registration->nationalitycountry) ? $registration->nationalitycountry->name : 'غير محدد') . '</td> <td bgcolor="#D9DEE4" align="center">تاريخ الميلاد</td> <td align="center">' . ($registration ? $registration->birthday : "") . '</td> </tr> <tr> <td bgcolor="#D9DEE4" align="center">التخصص</td> <td align="center" colspan="2">' . $student->specialty_name . '</td> <td bgcolor="#D9DEE4" align="center">الرقم الجامعي</td> <td align="center">' . $student->code . '</td> <td bgcolor="#D9DEE4" align="center">الحالة الدراسية</td> <td align="center">' . config('students.state.' . $student->state) . '</td> </tr> <tr> <td bgcolor="#D9DEE4" align="center">الساعات المعتمدة</td> <td align="center">' . $student_hours . '</td> <td bgcolor="#D9DEE4" align="center">الساعات المكتسبة</td> <td align="center">' . $success_hours . '</td> <td bgcolor="#D9DEE4" align="center" colspan="2">المعدل التراكمي</td> <td align="center">' . $gpa . '</td> </tr> <tr> <td bgcolor="#D9DEE4" align="center">الساعات المسجلة</td> <td align="center">' . $fail_hours . '</td> <td bgcolor="#D9DEE4" align="center">الساعات المحولة</td> <td align="center"> ... </td> <td bgcolor="#D9DEE4" align="center" colspan="2">التقدير العام</td> <td align="center">' . $valuation . '</td> </tr> </tbody> </table>'; $pdf->SetFontSize(11); $chunks = $semesters->groupBy('year_name'); $accumulation_points = 0; $accumulation_hours = 0; $break = 1; $j = 1; // for each year $all_before_failed_subjects = []; $before_hours = 0; $before_points = 0; foreach ($chunks as $i => $chunk) { // for each sem foreach ($chunk as $term_index => $term) { if ($term->semester_id == Semester()->id) { break; } // donot calculate quran hour if sem <= 7 $hours = $term->subjects->sum(function ($s) use($term, &$all_before_failed_subjects, &$before_hours, &$before_points) { if ($s->subject_state == 'fail' && ($term->semester_id >= 7 && $s->is_quran || !$s->is_quran)) { $plus_hours = 0; $plus_points = 0; if (isset($all_before_failed_subjects[$s->subject_id])) { $plus_hours = $all_before_failed_subjects[$s->subject_id]['hours']; $plus_points = $all_before_failed_subjects[$s->subject_id]['points']; } $all_before_failed_subjects[$s->subject_id] = ['hours' => $s->subject_hours + $plus_hours, 'points' => $s->details->points + $plus_points]; } else { if (in_array($s->subject_id, array_keys($all_before_failed_subjects)) && $s->subject_state == 'success') { $before_hours += $all_before_failed_subjects[$s->subject_id]['hours']; $before_points += $all_before_failed_subjects[$s->subject_id]['points']; unset($all_before_failed_subjects[$s->subject_id]); } } return $term->semester_id >= 7 && $s->is_quran || !$s->is_quran ? $s->subject_hours : 0; }); $points = number_format($term->subjects->sum(function ($s) use($term) { return $term->semester_id >= 7 && $s->is_quran || !$s->is_quran ? $s->details->points : 0; }), 2); // var_dump($before_hours, $before_points); $accumulation_hours += $hours - $before_hours; $accumulation_points += $points - $before_points; $before_points = 0; $before_hours = 0; // first or second sem in page if ($break % 2 == 1) { $pdf->writeHTMLCell(180, 20, 15, 50, $html, 0, 0, false, true, "C"); $pdf->writeHTMLCell(180, 20, 15, 85, view('students::documents._semesters', ["term" => $term, 'accumulation_hours' => $accumulation_hours, 'accumulation_points' => $accumulation_points])->render(), 0, 0, false, true, "C"); } else { $pdf->writeHTMLCell(180, 20, 15, 85 * 2 + 10, view('students::documents._semesters', ["term" => $term, 'accumulation_hours' => $accumulation_hours, 'accumulation_points' => $accumulation_points])->render(), 0, 0, false, true, "C"); } if ($break % 2 == 0 && $term->semester_id != Semester()->id - 1) { $pdf->AddPage(); } $break++; } $j++; } // exit; // dd($all_before_failed_subjects); // print signeture $pdf->SetFontSize(20); $html = '<table border="0" width="100%"><tbody><tr><td>القبول و التسجيل</td></tr></tbody></table>'; $pdf->writeHTMLCell(40, 5, 15, 245, $html, 0, 0, false, true, "C"); $html = '<table border="0" width="100%"><tbody><tr><td>المشرف العام على التعليم عن بعد</td></tr> <tr><td>مستشار معالي وزير الأوقاف والشؤون الدينية</td></tr></tbody></table>'; $pdf->writeHTMLCell(130, 5, 80, 245, $html, 0, 0, false, true, "C"); ob_clean(); return $pdf; }
/** * Handle the event. * * @param RegistrationStepChanged $event * @return void */ public function handle(RegistrationStepChanged $event) { $registration = $event->registration; $semester = semester(); $finish = $semester ? $semester->finish_at : date('Y-m-d'); if ($semester->order != 'first') { $semester = Semester::where('order', 'first')->where('start_at', '>', $finish)->orderBy('start_at', 'ASC')->first(); } if (empty($semester)) { return false; } $registration->load('step', 'student', 'contactcountry', 'files'); if ($registration->step->enroll == 1 && !$registration->student) { $equation_subjects_ids = RegistrationEquationSubject::whereNotNull('subject_id')->where('status', 'accepted')->whereHas('equation', function ($w) use($registration) { $w->where('registration_id', $registration->id); })->pluck('subject_id')->toArray(); $subject_ids = []; $i = 0; $department = 0; while (count(array_diff($subject_ids, $equation_subjects_ids)) == 0) { $department = Department::where('spec_id', $registration->academystructure_specialty_id)->where(function ($w) use($department) { $w->orWhere('parent_id', !empty($department->id) ? $department->id : 0); $w->orWhereNull('parent_id'); })->first(); $subject_ids = json_decode($department->subject_ids, TRUE); $i++; if ($i == 20) { break; } } if (empty($subject_ids)) { return false; } $subjects = Subject::whereIn('id', $subject_ids)->get(); $mobile = ($registration->contactcountry ? $registration->contactcountry->calling_code : "968") . $registration->contact_mobile; $data = ['username' => $registration->username, 'username_prefix' => $registration->enroll_code, 'password' => bcrypt($registration->contact_mobile), 'name' => $registration->fullname, 'email' => $registration->contact_email, 'mobile' => $mobile, 'state' => 'active', 'study_state' => 'active', 'national_id' => $registration->national_id, 'gender' => $registration->gender, 'registration_id' => $registration->id, 'academystructure_department_id' => $department->id, 'registration_type_id' => $registration->registration_type_id]; if ($registration->files) { $photo = $registration->files->first(function ($key, $value) { return $key == 'photo'; }); if ($photo) { // $data['photo'] = asset($photo->file->url()); } } Eloquent::unguard(); $student = Student::create($data); $invoiceItem = FinancialInvoiceItem::where('slug', 'study_fee')->first(); $study_fee = $registration->study_fee > 0 ? $registration->study_fee : $invoiceItem->amount; $total_amount = $subjects->sum(function ($s) use($equation_subjects_ids, $study_fee) { $amount = 0; if (!in_array($s->id, $equation_subjects_ids)) { $amount = !$s->is_quran ? $s->hour * (int) $study_fee : $s->hour * ((int) $study_fee / 2); } return $amount; }); if ($student) { if ($registration->debit && $invoiceItem) { $invoiceData = ['ref_key' => 'registrations', 'ref_value' => $registration->id, 'student_id' => $student->id, 'amount' => $registration->debit, 'type' => 'credit', 'item_id' => $invoiceItem->id, 'pay_type' => 'epay', 'bank_code' => $registration->reason_code, 'transaction_wid' => $registration->transaction_uuid, 'note' => 'ايصال دفع مصاريف التسجيل.']; FinancialInvoice::create($invoiceData); // create debit invoice $invoiceData = ['ref_key' => 'registrations', 'ref_value' => $registration->id, 'student_id' => $student->id, 'amount' => $total_amount, 'type' => 'debit', 'item_id' => $invoiceItem->id, 'pay_type' => 'epay', 'note' => 'فاتةورة التسجيل.']; FinancialInvoice::create($invoiceData); } foreach ($subjects as $subject) { $subject_state = in_array($subject->id, $equation_subjects_ids) ? 'equal' : 'study'; $subject_payed = in_array($subject->id, $equation_subjects_ids) ? 0 : 1; if (!$registration->debit && $registration->step->make_payment) { $subject_payed = 0; } $data = ['student_id' => $student->id, 'subject_id' => $subject->id, 'semester_id' => $semester->id, 'academystructure_department_id' => $department->id, 'state' => $subject_state, 'note' => '', 'payed' => $subject_payed]; $studentSubject = StudentSubject::create($data); } $historyData = ['student_id' => $student->id, 'state' => 'active', 'study_state' => 'active', 'academycycle_semester_id' => $semester->id, 'academystructure_department_id' => $department->id]; StudentHistory::create($historyData); $this->createStudentEmail($student, $registration->contact_mobile); try { if (!empty($photo)) { $student->photo = $photo; $student->save(); } } catch (\Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException $e) { } } //\Log::info('turn to student '.$response); } }
/** * Execute the job. * * @return void */ public function handle() { $student = Student::find($this->student_id); $currentSemester = semester(); $summerSemester = Semester::where('id', '>', $currentSemester->id)->where('order', 'summer')->orderBy('id', 'ASC')->first(); // Log::info($student->id, $currentSemester->id, $summerSemester->id); if ($student && $currentSemester && $summerSemester) { $nextSemester = Semester::where('id', '>', $currentSemester->id)->where('order', '!=', 'summer')->orderBy('id', 'ASC')->first(); if (!$nextSemester) { return false; } $current_department_id = $student->academystructure_department_id; if ($currentSemester->order != 'summer') { $nextDepartment = Department::where('parent_id', $student->academystructure_department_id)->first(); if ($nextDepartment) { $student->state = 'active'; $student->study_state = 'success'; $student->academystructure_department_id = $nextDepartment->id; } } $history = StudentHistory::where('student_id', $student->id)->orderBy('id', 'desc')->where('academycycle_semester_id', $currentSemester->id)->first(); if ($history) { $history->study_state = 'success'; $history->save(); } if ($student->save()) { // get current semester subjects and make them fail or success for current semester $subjects = StudentSubject::selectRaw("subsub.id as subject_id,SUM(stugr.value) AS subject_points,student_subjects.state as subject_state,subsub.name AS subject_name, subsub.hour AS subject_hours")->join('subject_subjects AS subsub', function ($join) { $join->on('subsub.id', '=', 'student_subjects.subject_id'); })->where('student_subjects.student_id', $student->id)->leftJoin('student_grades AS stugr', function ($join) use($currentSemester, $student) { $join->on('stugr.subject_id', '=', 'subsub.id')->where('stugr.semester_id', '=', $currentSemester->id)->where('stugr.student_id', '=', $student->id); })->whereIn('state', ['study'])->where('student_subjects.semester_id', '=', $currentSemester->id)->where('student_subjects.student_id', $student->id)->groupBy('subsub.id')->get(); $failed_subjects_ids = []; $passed_subjects_ids = []; foreach ($subjects as $subject) { if ($subject->subject_points < 50) { $failed_subjects_ids[] = $subject->subject_id; } elseif ($subject->subject_points >= 50) { $passed_subjects_ids[] = $subject->subject_id; } } StudentSubject::where('student_id', $student->id)->whereIn('subject_id', $failed_subjects_ids)->update(['state' => 'fail']); StudentSubject::where('student_id', $student->id)->whereIn('subject_id', $passed_subjects_ids)->update(['state' => 'success']); // end success and fail if ($currentSemester->order != 'summer' && $nextDepartment) { $next_subject_ids = json_decode($nextDepartment->subject_ids, TRUE); $equal_subject_ids = EqualSubject::whereHas('order', function ($w) use($student) { $w->where('student_id', $student->id); })->pluck('equal_subject_id')->toArray(); $next_subject_study_ids = array_diff($next_subject_ids, $equal_subject_ids); $next_subject_equal_ids = array_intersect($next_subject_ids, $equal_subject_ids); $student->subjects()->attach($next_subject_study_ids, ['semester_id' => $nextSemester->id, 'academystructure_department_id' => $nextDepartment->id, 'state' => 'study']); $student->subjects()->attach($next_subject_equal_ids, ['semester_id' => $nextSemester->id, 'academystructure_department_id' => $nextDepartment->id, 'state' => 'equal']); $data = ['state' => 'active', 'study_state' => 'active', 'academycycle_semester_id' => $nextSemester->id, 'academystructure_department_id' => $nextDepartment->id]; $student->histories()->create($data); // create invoice for student if ($next_subject_equal_ids) { $item = FinancialInvoiceItem::where('slug', 'study_fee')->first(); $subjects_count = Subject::whereIn('id', $next_subject_equal_ids)->where('is_quran', 0)->count(); $data = ['student_id' => $student->id, 'type' => 'debit', 'item_id' => $item->id, 'pay_type' => NULL, 'semester_id' => $nextSemester->id, 'amount' => $subjects_count * $item->amount]; FinancialInvoice::create($data); } } // move any failed subjects if less than 3 to summer semester $all_failed_subjects = StudentSubject::groupBy('subject_id')->where('state', 'fail')->pluck('subject_id')->toArray(); $all_passed_subjects = StudentSubject::groupBy('subject_id')->where('state', 'success')->pluck('subject_id')->toArray(); $failed_subjects = array_diff($all_failed_subjects, $all_passed_subjects); if (COUNT($failed_subjects) <= 3) { $summerSemester = Semester::where('id', '>', $currentSemester->id)->where('order', 'summer')->orderBy('id', 'ASC')->first(); $student->subjects()->attach($failed_subjects, ['semester_id' => $summerSemester->id, 'academystructure_department_id' => $current_department_id, 'state' => 'study']); $data = ['state' => 'active', 'study_state' => 'active', 'academycycle_semester_id' => $summerSemester->id, 'academystructure_department_id' => $current_department_id]; $student->histories()->create($data); } } } }
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(); } }