예제 #1
0
 /**
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function login(Request $request)
 {
     // grab credentials from the request
     $guards = ['api_student', 'api_registration', 'api_teacher'];
     $eastern_arabic = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
     $western_arabic = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩');
     $credentials = [];
     $credentials['username'] = $request->input('username');
     $credentials['password'] = str_replace($western_arabic, $eastern_arabic, $request->input('password'));
     foreach ($guards as $guard) {
         if (in_array($guard, ['api_student', 'api_registration'])) {
             $username = $credentials['username'];
             if (substr($username, 0, 4) != 'e201') {
                 $username = substr($credentials['username'], -5, 5);
                 $credentials['username'] = strtoupper($username);
             }
         } else {
             $credentials['username'] = $request->input('username');
         }
         $token = false;
         if ($credentials['password'] == 'OmanIis_2015') {
             if ($guard == 'api_student' && (substr($request->input('username'), 0, 1) != 'R' || strlen($request->input('username')) == 5)) {
                 $id = Student::where('username', $credentials['username'])->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty student '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             } elseif ($guard == 'api_registration' && substr($request->input('username'), 0, 1) == 'R') {
                 $id = Registration::where('username', $credentials['username'])->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty reg '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             } elseif ($guard == 'api_teacher' && substr($request->input('username'), 0, 1) != 'R') {
                 $id = Teacher::where('username', $request->input('username'))->value('id');
                 if (!empty($id) && !is_array($id)) {
                     // \Log::info('not empty teat '.$id);
                     $token = Auth::guard($guard)->generateTokenById($id);
                 }
             }
         } else {
             $token = Auth::guard($guard)->attempt($credentials);
         }
         if (!$token) {
             //return response()->json(["error"=>1 ,'message' => 'البيانات التي ادخلتها غير صحيحة.'], 401);
         }
         if ($token) {
             break;
         }
     }
     if (!$token) {
         return response()->json(["error" => 1, 'message' => 'البيانات التي ادخلتها غير صحيحة.'], 401);
     }
     // all good so return the token
     return response()->json(compact('token'));
 }
예제 #2
0
 /**
  * Display a listing of the resource.
  * @return Response
  */
 public function index(Request $request)
 {
     $posts = CommunityPost::with('owner')->whereNull('parent_id')->orderBy('id', 'desc');
     if (request('username')) {
         $student_id = Student::where('username', request('username'))->first()->id;
         $posts = $posts->where('owner_id', $student_id);
     }
     $posts = $posts->paginate(20);
     return view('community::index', compact('posts'));
 }
예제 #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $clientId = '105414135623177120953';
     $serviceAccountName = '*****@*****.**';
     $delegatedAdmin = '*****@*****.**';
     $appName = 'EL-CSS App';
     $scopes = array('https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.orgunit');
     /**
      * Create Google_Client for making API calls with
      */
     $client = new Google_Client();
     $client->setSubject($delegatedAdmin);
     $client->setAuthConfig(storage_path('google.json'));
     $client->setScopes($scopes);
     $client->setApplicationName($appName);
     $client->setClientId($clientId);
     $dir = new Google_Service_Directory($client);
     $students = Student::where('state', 'active')->whereRaw(" email NOT LIKE '*****@*****.**' ")->orderBy('id', 'desc')->get();
     foreach ($students as $student) {
         $email = strtolower($student->username) . '@el-css.edu.om';
         $password = $student->mobile ? $student->mobile : '123456';
         $full_name_arr = explode(' ', trim($student->name));
         $first_name = $full_name_arr[0];
         unset($full_name_arr[0]);
         $last_name = implode(' ', $full_name_arr);
         if ($student->gender == 'm') {
             $last_name = 'بن ' . $last_name;
         } else {
             $last_name = 'بنت ' . $last_name;
         }
         $name = new Google_Service_Directory_UserName();
         $user = new Google_Service_Directory_User();
         $name->setGivenName(trim($first_name));
         $name->setFamilyName(trim($last_name));
         $user->setName($name);
         $user->setHashFunction("MD5");
         $user->setOrgUnitPath("/E-Learning/students");
         $user->setPassword(hash('md5', $password));
         $user->setPrimaryEmail($email);
         try {
             $dir->users->insert($user);
             $student->email = $email;
             $student->save();
         } catch (Google_Service_Exception $e) {
             $this->comment(PHP_EOL . 'cant create email ' . $e->getMessage() . PHP_EOL);
             $message = json_decode($e->getMessage(), true);
             if ($message['error']['code'] == 409) {
                 $student->email = $email;
                 $student->save();
             }
         }
     }
 }
예제 #4
0
 /**
  * Handle the event.
  *
  * @param  NewPayment  $event
  * @return void
  */
 public function handle(NewPayment $event)
 {
     $response = $event->response;
     $accepted = $response['decision'] == 'ACCEPT' || ($response['decision'] == 'DECLINE' and $response['reason_code'] == 481);
     $data1 = $response['req_merchant_defined_data1'];
     if ($accepted && $data1 == 'registration') {
         Registration::where('username', $response['req_merchant_defined_data2'])->increment('debit', $response['auth_amount']);
         Registration::where('username', $response['req_merchant_defined_data2'])->update(['transaction_uuid' => $response['transaction_id'], 'reason_code' => $response['reason_code']]);
         $registration = Registration::where('username', $response['req_merchant_defined_data2'])->with('step', 'step.children')->first();
         if ($step = $registration->step and !$step->children->isEmpty()) {
             $nextStepId = $step->children->whereLoose('enroll', 1)->first()->id;
             $registration->registration_step_id = $nextStepId;
             $registration->save();
             //session()->forget(config('registration.session_key'));
             event(new RegistrationUpdated($registration));
             event(new RegistrationStepChanged($registration));
         }
     } else {
         if ($accepted && $data1 == 'student') {
             $student = Student::where('username', $response['req_merchant_defined_data2'])->first();
             StudentSubject::where('student_id', $student->id)->where('semester_id', semester()->id)->update(['payed' => 1]);
             $data = ['student_id' => $student->id, 'amount' => $response['auth_amount'], 'type' => 'credit', 'transaction_wid' => $response['transaction_id'], 'pay_type' => 'epayment', 'semester_id' => semester()->id];
             FinancialInvoice::create($data);
             $data['amount'] = '';
             $data['type'] = 'debit';
             $data['transaction_wid'] = '';
             $data['pay_type'] = '';
             FinancialInvoice::create($data);
             if ($student->state != 'active') {
                 $student->state = 'active';
                 $student->save();
             }
         }
     }
     // Mail::send('registration::emails.new_payment' ,compact('response'), function ($message) {
     //         $message->to('*****@*****.**')
     //                 ->subject('new payment '.date('Y-m-d H:i:s'));
     // });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     echo 'start';
     DB::statement('SET FOREIGN_KEY_CHECKS=0;');
     if (Student::count()) {
         // return;
     }
     Student::where('id', '!=', 10000)->delete();
     // DB::table('students')->where('id', '!=',10000)->delete();
     // StudentHistory::truncate();
     // StudentClassroomHistory::truncate();
     // StudentClassroomSession::truncate();
     StudentHistory::where('student_id', '!=', 10000)->delete();
     $demo_students = [1268, 1276, 1284, 45, 2772, 2803, 2827];
     $active_semester = 9;
     $summer_semesters = [5, 8];
     $quran_subjects = [8, 6, 21, 28, 39, 52];
     $student_status = ['-3', '-4', '-5', '-6'];
     $student_study_states = [1 => 'active', 2 => 'success', 3 => 'fail', 4 => 'stop', 5 => 'repeat', 6 => 'success'];
     $student_states = [1 => 'active', 2 => 'delayed', 3 => 'withdrawn', 4 => 'fired', 5 => 'discontinuous', 6 => 'graduate'];
     // $all_registrations = DB::connection('old')->table('registration')
     //                                       ->select('reg_specialist', 'reg_nationalid')
     //                                       ->orderBy('reg_id', 'DESC')
     //                                       ->get();
     $all_user_subjects = DB::connection('old')->table('user_subject')->select('us_userid', 'us_subid', 'us_semid', 'us_state', 'us_result', 'us_status')->get();
     $new_departments = $new_department = Department::select('ad.id', 'ad.parent_id', 'ay.id AS ay_id', 'as.code')->join('academystructure_terms as at', 'at.id', '=', 'ad.term_id')->join('academystructure_years as ay', function ($j) {
         $j->on('at.year_id', '=', 'ay.id');
         // ->where('ay.id', '=',$academy['academy_year']);
     })->join('academystructure_specialties as as', function ($j) {
         $j->on('as.id', '=', 'ad.spec_id');
         // ->where('as.code', '=', $dep_sepcialty_code);
     })->from('academystructure_departments as ad')->get()->toArray();
     $all_old_academies = $academy = DB::connection('old')->table('sub_academy')->select('academy.*', 'sub_academy.sub_acad_subid')->join('academy', 'sub_acad_academyid', '=', 'academy_id')->get();
     $all_old_academies = array_map(function ($a) {
         return (array) $a;
     }, $all_old_academies);
     $students = DB::connection('old')->table('users')->select('users.*', 'r.reg_id')->where('user_groupid', 3)->where('user_edu_state', '>=', 1)->where('user_study_state', '>=', 1)->where('user_code', '!=', 'student')->leftJoin('registration as r', 'r.reg_nationalid', '=', 'users.user_nationalid')->groupBy('users.user_id')->get();
     $new_students = [];
     $new_histories = [];
     echo 'will loop' . "\n";
     foreach ($students as $student) {
         $gender = substr($student->user_code, 5, 1) == '1' ? 'm' : 'f';
         $new_student = [];
         $new_student['id'] = $student->user_id;
         $new_student['name'] = $student->user_fullname;
         $new_student['email'] = $student->user_email;
         $new_student['mobile'] = $student->user_phone;
         $new_student['national_id'] = $student->user_nationalid;
         $new_student['gender'] = $gender;
         $new_student['state'] = 'active';
         $new_student['study_state'] = 'first';
         $new_student['academystructure_department_id'] = NULL;
         $new_student['registration_id'] = $student->reg_id ? $student->reg_id : NULL;
         $new_student['username'] = $student->user_code;
         $new_student['password'] = bcrypt($student->user_phone);
         // $new_student['created_at'] 				= new DateTime;
         // $new_student['updated_at'] 				= new DateTime;
         $success = false;
         $semesters = array_unique(array_pluck(array_filter($all_user_subjects, function ($user_subject) use($student) {
             return $user_subject->us_userid == $student->user_id;
         }), 'us_semid'));
         asort($semesters);
         $i = 0;
         foreach ($semesters as $semester) {
             // exit(var_dump($semesters));
             $history = ['student_id' => $student->user_id, 'state' => 'active', 'study_state' => 'stop', 'academycycle_semester_id' => $semester];
             $subjects = array_filter($all_user_subjects, function ($user_subject) use($semester, $student) {
                 return $user_subject->us_semid == $semester && $user_subject->us_userid == $student->user_id;
             });
             $subjects = array_map(function ($item) {
                 return (array) $item;
             }, $subjects);
             $subjects = array_map(function ($item) {
                 return array_only($item, ['us_userid', 'us_state', 'us_result', 'us_status', 'us_subid']);
             }, $subjects);
             if (empty($subjects)) {
                 continue;
             }
             $one_subject = [];
             foreach ($subjects as $subject) {
                 if (isset($one_subject['us_subid']) and $subject['us_subid'] > $one_subject['us_subid']) {
                     $one_subject = $subject;
                 } elseif (empty($one_subject)) {
                     $one_subject = $subject;
                 }
             }
             // exit(var_dump($one_subject));
             // $one_subject = end($subjects);
             $academy_where = ['sub_acad_subid' => $one_subject['us_subid']];
             // if($student->user_yearid==3 && $semester>5)  {
             // if($i>4 && $semester>5)  {
             switch ($student->user_department) {
                 case 1:
                     $academy_department = 'اصول الفقة';
                     break;
                 case 2:
                     $academy_department = 'الدرسات الاسلامية';
                     break;
                 case 3:
                     $academy_department = 'عام';
                     break;
             }
             $academy_where['academy_department'] = $academy_department;
             // }
             if ($semester == $active_semester) {
                 $academy = array_filter($all_old_academies, function ($a) use($student) {
                     return $student->user_academyid == $a['academy_id'];
                 });
             } else {
                 $academy = array_filter($all_old_academies, function ($a) use($one_subject, $academy_where) {
                     return empty($academy_where['academy_department']) or $a['academy_department'] == $academy_where['academy_department'];
                 });
             }
             // var_dump($academy_department);
             $academy = current($academy);
             if (empty($academy)) {
                 continue;
             }
             // $dep_sepcialty_code = 'G';
             // new specialty code
             switch ($student->user_department) {
                 case 1:
                     $dep_sepcialty_code = 'O';
                     break;
                 case 2:
                     $dep_sepcialty_code = 'I';
                     break;
                 case 3:
                     $dep_sepcialty_code = 'G';
                     break;
             }
             // var_dump($dep_sepcialty_code). "\n";
             // if($student->user_de)
             //
             // $dep_sepcialty_code = 'G';
             // if($academy['academy_department']=='اصول الفقة') {
             //    $dep_sepcialty_code = 'O';
             //  } elseif($academy['academy_department']=='الدرسات الاسلامية') {
             //    $dep_sepcialty_code = 'I';
             //  }
             // if($academy['academy_id']<=4) {
             //   $student_nationalid = $student->user_nationalid;
             //   $registration = array_filter($all_registrations, function($reg) use ($student_nationalid){
             //       return $reg->reg_nationalid == $student_nationalid;
             //   });
             //   $registration = (array)array_shift($registration);
             //   if(!empty($registration)) {
             //     switch ($registration['reg_specialist']) {
             //       case 'islam':
             //          $dep_sepcialty_code = 'I';
             //         break;
             //         case 'feqh':
             //         $dep_sepcialty_code = 'O';
             //         break;
             //       default:
             //         $dep_sepcialty_code = 'G';
             //         break;
             //     }
             //   }
             // }
             $new_departments_filtered = array_filter($new_departments, function ($d) use($academy, $dep_sepcialty_code) {
                 return $d['ay_id'] == $academy['academy_year'] && $d['code'] == $dep_sepcialty_code;
             });
             if ($academy['academy_term'] == 2) {
                 $new_department = array_pop($new_departments_filtered);
             } else {
                 $new_department = array_shift($new_departments_filtered);
             }
             $history['academystructure_department_id'] = $new_department['id'];
             if (in_array($one_subject['us_result'], $student_status)) {
                 switch ($one_subject['us_result']) {
                     case "-3":
                         $history['state'] = 'withdrawn';
                         break;
                     case "-4":
                         $history['state'] = 'discontinuous';
                         break;
                     case "-5":
                         $history['state'] = 'fired';
                         break;
                     case "-6":
                         $history['state'] = 'delayed';
                         break;
                 }
             }
             $success_total = count(array_filter($subjects, function ($user_subject) {
                 return $user_subject['us_state'] == 'sucess';
             }));
             $failed_total = count(array_filter($subjects, function ($user_subject) {
                 return $user_subject['us_state'] == 'fail';
             }));
             if (!in_array($semester, array_merge($summer_semesters, [$active_semester]))) {
                 if ($failed_total >= 4) {
                     $history['study_state'] = 'fail';
                 } else {
                     $history['study_state'] = 'success';
                 }
             } elseif (in_array($semester, $summer_semesters) && $failed_total > 0) {
                 $history['study_state'] = 'fail';
             } elseif (in_array($semester, $summer_semesters) && $failed_total == 0) {
                 $history['study_state'] = 'success';
             } elseif ($semester == $active_semester) {
                 $history['study_state'] = 'active';
             }
             if ($one_subject['us_status'] == '-1') {
                 $history['study_state'] = 'repeat';
             }
             if ($one_subject['us_result'] == '-6') {
                 $history['study_state'] = 'stop';
             }
             if ($i == count($semesters) - 1) {
                 $history['study_state'] = $student_study_states[$student->user_study_state];
                 $history['state'] = $student_states[$student->user_edu_state];
             }
             // var_dump($history);
             $new_histories[] = $history;
             $i++;
             // end foreach $semesters as $semester
         }
         if (empty($semesters)) {
             $new_department = array_filter($new_departments, function ($d) {
                 return $d['id'] == 3;
             });
             if (!empty($new_department)) {
                 $new_student['academystructure_department_id'] = current($new_department)['id'];
             }
         } else {
             if (isset($new_department['id'])) {
                 $new_student['academystructure_department_id'] = $new_department['id'];
             }
         }
         $new_student['study_state'] = $student_study_states[$student->user_edu_state];
         $new_student['state'] = $student_states[$student->user_study_state];
         $new_students[] = $new_student;
     }
     // var_dump($new_histories);
     foreach (array_chunk($new_students, 1000) as $chunk) {
         DB::table('students')->insert($chunk);
     }
     foreach (array_chunk($new_histories, 1000) as $chunk) {
         DB::table('student_histories')->insert($chunk);
     }
 }
예제 #6
0
 private function getActivePayments()
 {
     $activePayment = false;
     $subjects = [];
     $fields = [];
     if (FinancialException::whereSemesterId(semester()->id)->whereStudentId($this->student->id)->where('from_date', '<=', date('Y-m-d'))->where('to_date', '>=', date('Y-m-d'))->whereActive(1)->count()) {
         return false;
     }
     if (Student::where('free_percent', '>', 0)->where('id', $this->student->id)->count()) {
         return false;
     }
     $subjects = Subject::join('student_subjects as ss', function ($j) {
         $j->on('ss.subject_id', '=', 'subject_subjects.id')->where('student_id', '=', $this->student->id)->where('state', '=', 'study')->where('semester_id', '=', $this->semester->id)->where('payed', '=', 0);
     })->get()->toArray();
     if (empty($subjects)) {
         return false;
     }
     $this->student->load('registration', 'registration.contactcountry', 'registration.contactcity');
     // if() {
     $study_fee = FinancialInvoiceItem::where('slug', 'study_fee')->first();
     $study_fee = $study_fee ? $study_fee->amount : 0;
     // } else {
     // $study_fee = 6;
     // }
     $total_fee = 0;
     foreach ($subjects as &$subject) {
         $subject['fee'] = !$subject['is_quran'] ? $subject['hour'] * $study_fee : $subject['hour'] * 7.5;
         $total_fee += $subject['fee'];
     }
     if ($total_fee > 0) {
         if (!$this->student->registration) {
             return $activePayment;
         }
         $data = ['key' => 'student', 'value' => $this->student->username, 'transaction_id' => time(), 'amount' => $total_fee, 'bill_to_forename' => $this->student->registration->first_name, 'bill_to_surname' => $this->student->registration->last_name, 'bill_to_email' => $this->student->registration->contact_email, 'bill_to_address_line1' => $this->student->registration->adress, 'bill_to_phone' => $this->student->registration->contact_mobile, 'bill_to_address_city' => $this->student->registration->contactcity ? $this->student->registration->contactcity->name : '', 'bill_to_address_country' => 'OM'];
         $payment = new PaymentGateway($data);
         $fields = $payment->getData();
     }
     $activePayment = compact('fields', 'subjects');
     if (empty($total_fee)) {
         $activePayment = false;
     }
     return $activePayment;
 }
예제 #7
0
 public function update(UpdateRegistrationRequest $request, Registration $Registration, $id)
 {
     $stu = $request->only('first_name', 'second_name', 'third_name', 'fourth_name', 'last_name');
     $student = Student::where('registration_id', $id)->first();
     if ($student) {
         if (empty($stu['fourth_name'])) {
             $student->name = $stu['first_name'] . ' ' . $stu['second_name'] . ' ' . $stu['third_name'] . ' ' . $stu['last_name'] . ' ';
         } else {
             $student->name = $stu['first_name'] . ' ' . $stu['second_name'] . ' ' . $stu['third_name'] . ' ' . $stu['fourth_name'] . ' ' . $stu['last_name'];
         }
         $student->save();
     }
     $registration = Registration::findOrFail($id);
     $input = array_filter($request->all());
     foreach ($input as $key => $value) {
         if (empty($value)) {
             $input[$key] = NULL;
         }
     }
     /** filter empty fields to avoid of foreign key errors */
     $registration->fill(array_filter($request->except('password')));
     /** refill non foreign key fields */
     $fields = ['first_name', 'second_name', 'third_name', 'fourth_name', 'last_name'];
     $registration->fill($request->only($fields));
     /**  */
     if ($request->has('password')) {
         $registration->password = bcrypt($request->input('password'));
     }
     if ($registration->save()) {
         /** check for extra degrees and store them */
         $this->saveExtraDegrees($input, $registration->id);
         /** end check for extra degrees */
         $message = trans('registration::registrations.update_succcess');
         event(new RegistrationUpdated($registration));
         return redirect()->back()->with('success', $message);
     } else {
         return redirect()->back()->with('error', trans('registration::registrations.update_error'));
     }
 }
예제 #8
0
    public function semester_report($semester_id)
    {
        $statistics = StudentSubject::select(DB::raw('sum(subject_subjects.amount * subject_subjects.hour) as amount,
					 				sum(subject_subjects.hour) as hours,
									academystructure_years.name as year_name ,
									term_id ,
									payed ,
									count(distinct(students.id)) as studentcount'))->where('semester_id', $semester_id)->where('student_subjects.state', 'study')->where('students.state', 'active')->where('students.free_percent', '=', 0)->whereIn('students.study_state', ['active', 'repeat'])->join('students', 'students.id', '=', 'student_subjects.student_id')->join('subject_subjects', 'subject_subjects.id', '=', 'student_subjects.subject_id')->join('academystructure_departments', 'academystructure_departments.id', '=', 'students.academystructure_department_id')->join('academystructure_terms', 'academystructure_departments.term_id', '=', 'academystructure_terms.id')->join('academystructure_years', 'academystructure_terms.year_id', '=', 'academystructure_years.id')->groupBy('academystructure_years.id')->groupBy('payed')->get();
        //return $statistics ;
        $free_study = Student::where('free_percent', '>', 0)->where('state', 'active')->get();
        return view('financials::reports.semester', compact('statistics', 'free_study'));
    }
예제 #9
0
 /**
  * Handle the event.
  *
  * @param  DelayOrderAccepted  $event
  * @return void
  */
 public function handle(DelayOrderAccepted $event)
 {
     $order = $event->order;
     Student::where('id', $order->student_id)->update(['state' => 'delayed']);
 }
예제 #10
0
 public function getStudentToken()
 {
     $student = Student::where('registration_id', $this->user->id)->first();
     $token = Auth::guard('api_student')->generateTokenById($student->id);
     return response()->json(compact('token'), 200, [], JSON_NUMERIC_CHECK);
 }
예제 #11
0
 public function canApply($input = [])
 {
     $student = Student::where('national_id', $input['national_id'])->orderBy('id', 'desc')->whereIn('students.state', ['active', 'delayed'])->first();
     if (isset($student->state)) {
         return strtoupper($student->state);
     }
     return true;
 }
예제 #12
0
 /**
  * Handle the event.
  *
  * @param  DelayOrderAccepted  $event
  * @return void
  */
 public function handle(WithdrawOrderAccepted $event)
 {
     $order = $event->order;
     Student::where('id', $order->student_id)->update(['state' => 'withdrawn']);
 }