Exemplo n.º 1
0
 public function Index()
 {
     $settings_value = Settings::all();
     $expiresAt = Carbon::now()->addMinutes(10);
     if (Cache::has('TimeControlling')) {
         $previous_renew_time = Cache::get('TimeControlling');
         $diffMinutes = $previous_renew_time->diffInMinutes();
         if ($diffMinutes >= 10) {
             Cache::put('TimeControlling', Carbon::now(), $expiresAt);
         }
     } else {
         Cache::add('TimeControlling', Carbon::now(), $expiresAt);
         $diffMinutes = 0;
     }
     $subject_list_1 = SubjectList::where('subject_id', '<', 20000)->get();
     for ($i = 0; $i < 9; $i++) {
         if (Cache::has($subject_list_1[$i]->subject_id)) {
             if ($diffMinutes >= 10) {
                 Cache::put($subject_list_1[$i]->subject_id, RegisterSubjects::where('reg_subject_1', $subject_list_1[$i]->subject_id)->count(), $expiresAt);
             }
             $subject_count_1[$subject_list_1[$i]->subject_id] = Cache::get($subject_list_1[$i]->subject_id, '請重新整理一次');
         } else {
             Cache::add($subject_list_1[$i]->subject_id, RegisterSubjects::where('reg_subject_1', $subject_list_1[$i]->subject_id)->count(), $expiresAt);
             $subject_count_1[$subject_list_1[$i]->subject_id] = Cache::get($subject_list_1[$i]->subject_id, '請重新整理一次');
         }
     }
     $subject_list_2 = SubjectList::where('subject_id', '>', 20000)->get();
     for ($i = 0; $i < 5; $i++) {
         if (Cache::has($subject_list_2[$i]->subject_id)) {
             if ($diffMinutes >= 10) {
                 Cache::put($subject_list_2[$i]->subject_id, RegisterSubjects2::where('reg_subject_2', $subject_list_2[$i]->subject_id)->count(), $expiresAt);
             }
             $subject_count_2[$subject_list_2[$i]->subject_id] = Cache::get($subject_list_2[$i]->subject_id, '請重新整理一次');
         } else {
             Cache::add($subject_list_2[$i]->subject_id, RegisterSubjects2::where('reg_subject_2', $subject_list_2[$i]->subject_id)->count(), $expiresAt);
             $subject_count_2[$subject_list_2[$i]->subject_id] = Cache::get($subject_list_2[$i]->subject_id, '請重新整理一次');
         }
     }
     return view('index', compact('subject_list_1', 'subject_list_2', 'subject_count_1', 'subject_count_2', 'settings_value'));
 }
Exemplo n.º 2
0
 public function setSelect()
 {
     /*
      * Priority all selected.
      */
     $subject_list = SubjectList::where('subject_id', '<', 20000)->get();
     foreach ($subject_list as $subject_first_day) {
         $all_capacity = $subject_first_day->subject_normal;
         $subject_code = $subject_first_day->subject_id;
         $priority_count = RegisterSubjects::where('reg_subject_1', $subject_code)->where('priority', '1')->update(['already_pick_1' => 1, 'ps' => 'PRIORITY']);
         $left_capacity = $all_capacity - $priority_count;
         $far = $left_capacity / 2;
         $reg_data = RegisterSubjects::where('reg_subject_1', $subject_code)->where('already_pick_1', '!=', '1')->get();
         foreach ($reg_data as $reg_data_details) {
             $user_details = RegisterDetails::where('account_id', $reg_data_details->account_id)->get();
             $user_far = FarSchool::where('sf_school_id', $user_details[0]->school)->count();
             if ($user_far == 1) {
                 RegisterSubjects::where('account_id', $reg_data_details->account_id)->update(['already_pick_1' => 1, 'ps' => 'FAR']);
                 $far--;
             }
             if ($far == 0) {
                 break;
             }
         }
         $count = RegisterSubjects::where('reg_subject_1', $subject_code)->where('already_pick_1', 1)->count();
         $normal = $all_capacity - $count;
         $reg_data = RegisterSubjects::where('reg_subject_1', $subject_code)->where('already_pick_1', '!=', '1')->get();
         foreach ($reg_data as $reg_data_details) {
             RegisterSubjects::where('account_id', $reg_data_details->account_id)->update(['already_pick_1' => 1, 'ps' => 'P_NORMAL']);
             $normal--;
             if ($normal == 0) {
                 break;
             }
         }
     }
     $subject_list = SubjectList::where('subject_id', '>', 20000)->get();
     foreach ($subject_list as $subject_second_day) {
         $all_capacity = $subject_second_day->subject_normal;
         $subject_code = $subject_second_day->subject_id;
         $priority_count = RegisterSubjects2::where('reg_subject_2', $subject_code)->where('priority', '1')->update(['already_pick_2' => 1, 'ps' => 'PRIORITY']);
         $left_capacity = $all_capacity - $priority_count;
         $far = $left_capacity / 2;
         $reg_data = RegisterSubjects2::where('reg_subject_2', $subject_code)->where('already_pick_2', '!=', '1')->get();
         foreach ($reg_data as $reg_data_details) {
             $user_details = RegisterDetails::where('account_id', $reg_data_details->account_id)->get();
             $user_far = FarSchool::where('sf_school_id', $user_details[0]->school)->count();
             if ($user_far == 1) {
                 RegisterSubjects2::where('account_id', $reg_data_details->account_id)->update(['already_pick_2' => 1, 'ps' => 'FAR']);
                 $far--;
             }
             if ($far == 0) {
                 break;
             }
         }
         $count = RegisterSubjects2::where('reg_subject_2', $subject_code)->where('already_pick_2', 1)->count();
         $normal = $all_capacity - $count;
         $reg_data = RegisterSubjects2::where('reg_subject_2', $subject_code)->where('already_pick_2', '!=', '1')->get();
         foreach ($reg_data as $reg_data_details) {
             RegisterSubjects2::where('account_id', $reg_data_details->account_id)->update(['already_pick_2' => 1, 'ps' => 'P_NORMAL']);
             $normal--;
             if ($normal == 0) {
                 break;
             }
         }
     }
     /* Giving Registration Number */
     $subject_list = SubjectList::where('subject_id', '<', 20000)->get();
     foreach ($subject_list as $subject_first_day) {
         if ($subject_first_day->subject_id == 10001) {
             $first_one = RegisterSubjects::where('reg_subject_1', $subject_first_day->subject_id)->where('already_pick_1', 1)->where('ps', 'PRIORITY')->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'A' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
             $first_one = RegisterSubjects::where('reg_subject_1', $subject_first_day->subject_id)->where('already_pick_1', 1)->where('ps', '!=', 'PRIORITY')->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'B' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 10004) {
             $first_one = RegisterSubjects::where('reg_subject_1', $subject_first_day->subject_id)->where('already_pick_1', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'E' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 10009 || $subject_first_day->subject_id == 10006 || $subject_first_day->subject_id == 10007 || $subject_first_day->subject_id == 10008) {
             $first_one = RegisterSubjects::where('reg_subject_1', 10009)->where('already_pick_1', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'F' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
             $first_one = RegisterSubjects::where('reg_subject_1', 10008)->where('already_pick_1', 1)->get();
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'F' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
             $first_one = RegisterSubjects::where('reg_subject_1', 10007)->where('already_pick_1', 1)->get();
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'F' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
             $first_one = RegisterSubjects::where('reg_subject_1', 10006)->where('already_pick_1', 1)->get();
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'E' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 10002) {
             $first_one = RegisterSubjects::where('reg_subject_1', $subject_first_day->subject_id)->where('already_pick_1', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'H' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 10002) {
             $first_one = RegisterSubjects::where('reg_subject_1', $subject_first_day->subject_id)->where('already_pick_1', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'H' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 10003) {
             $first_one = RegisterSubjects::where('reg_subject_1', $subject_first_day->subject_id)->where('already_pick_1', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'G' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 10005) {
             $first_one = RegisterSubjects::where('reg_subject_1', $subject_first_day->subject_id)->where('already_pick_1', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'L' . $value;
                 RegisterSubjects::where('account_id', $first_one_things->account_id)->where('reg_subject_1', $first_one_things->reg_subject_1)->update(['stu_id' => $value]);
             }
         }
     }
     $subject_list = SubjectList::where('subject_id', '>', 20000)->get();
     foreach ($subject_list as $subject_first_day) {
         if ($subject_first_day->subject_id == 20004) {
             $first_one = RegisterSubjects2::where('reg_subject_2', $subject_first_day->subject_id)->where('already_pick_2', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'C' . $value;
                 RegisterSubjects2::where('account_id', $first_one_things->account_id)->where('reg_subject_2', $first_one_things->reg_subject_2)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 20001) {
             $first_one = RegisterSubjects2::where('reg_subject_2', $subject_first_day->subject_id)->where('already_pick_2', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'D' . $value;
                 RegisterSubjects2::where('account_id', $first_one_things->account_id)->where('reg_subject_2', $first_one_things->reg_subject_2)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 20005) {
             $first_one = RegisterSubjects2::where('reg_subject_2', $subject_first_day->subject_id)->where('already_pick_2', 1)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'I' . $value;
                 RegisterSubjects2::where('account_id', $first_one_things->account_id)->where('reg_subject_2', $first_one_things->reg_subject_2)->update(['stu_id' => $value]);
             }
         }
         if ($subject_first_day->subject_id == 20002 || $subject_first_day->subject_id == 20003) {
             $first_one = RegisterSubjects2::where('ps', 'PRIORITY')->where('already_pick_2', 1)->where('reg_subject_2', '>=', 20002)->where('reg_subject_2', '<=', 20003)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'J' . $value;
                 RegisterSubjects2::where('account_id', $first_one_things->account_id)->where('reg_subject_2', $first_one_things->reg_subject_2)->update(['stu_id' => $value]);
             }
             $first_one = RegisterSubjects2::where('ps', '!=', 'PRIORITY')->where('already_pick_2', 1)->where('reg_subject_2', '>=', 20002)->where('reg_subject_2', '<=', 20003)->get();
             $reg = 0;
             foreach ($first_one as $first_one_things) {
                 $reg++;
                 $value = str_pad($reg, 3, '0', STR_PAD_LEFT);
                 $value = 'K' . $value;
                 RegisterSubjects2::where('account_id', $first_one_things->account_id)->where('reg_subject_2', $first_one_things->reg_subject_2)->update(['stu_id' => $value]);
             }
         }
     }
     return 'SUCCESS';
 }
Exemplo n.º 3
0
 public function selectSubject()
 {
     $user_data = RegisterUsers::where('email', Auth::user()->email)->get();
     $user_details = RegisterDetails::where('account_id', $user_data[0]->id)->get();
     $user_reg_subject_1 = RegisterSubjects::where('account_id', $user_data[0]->id)->get();
     $user_reg_subject_1_displayName = SubjectList::where('subject_id', isset($user_reg_subject_1[0]) ? $user_reg_subject_1[0]->reg_subject_1 : 0)->get();
     $user_reg_subject_2 = RegisterSubjects2::where('account_id', $user_data[0]->id)->get();
     $user_reg_subject_2_displayName = SubjectList::where('subject_id', isset($user_reg_subject_2[0]) ? $user_reg_subject_2[0]->reg_subject_2 : 0)->get();
     $settings_value = Settings::all();
     if ($settings_value[0]->value <= Carbon::now() && $settings_value[1]->value >= Carbon::now()) {
         return view('general.select-subject', compact('user_details', 'user_data', 'user_reg_subject_1', 'user_reg_subject_2', 'user_reg_subject_1_displayName', 'user_reg_subject_2_displayName'));
     } else {
         return view('errors.RegisterInValid');
     }
 }
Exemplo n.º 4
0
 public function Console()
 {
     $subject_list_1 = SubjectList::where('subject_id', '<', 20000)->get();
     for ($i = 0; $i < 9; $i++) {
         $subject_count_1[$subject_list_1[$i]->subject_id] = RegisterSubjects::where('reg_subject_1', $subject_list_1[$i]->subject_id)->count();
         $subject_count_1[$subject_list_1[$i]->subject_id] = RegisterSubjects::where('reg_subject_1', $subject_list_1[$i]->subject_id)->count();
     }
     $subject_list_2 = SubjectList::where('subject_id', '>', 20000)->get();
     for ($i = 0; $i < 5; $i++) {
         $subject_count_2[$subject_list_2[$i]->subject_id] = RegisterSubjects2::where('reg_subject_2', $subject_list_2[$i]->subject_id)->count();
         $subject_count_2[$subject_list_2[$i]->subject_id] = RegisterSubjects2::where('reg_subject_2', $subject_list_2[$i]->subject_id)->count();
     }
     $meat_count = RegisterHabits::where('meat_veg', 1)->count();
     $veg_count = RegisterHabits::where('meat_veg', 0)->count();
     $total_count = RegisterUsers::where('type', '<>', 'super')->count();
     $total_count_with_reg_complete = RegisterDetails::where('phone', '!=', '')->count() - 1;
     $settings_value = Settings::all();
     return view('console.index', compact('settings_value', 'total_count_with_reg_complete', 'meat_count', 'veg_count', 'subject_list_1', 'subject_list_2', 'subject_count_1', 'subject_count_2', 'total_count'));
 }