/** * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function postRegister(Request $request) { $validator = $this->validator($request->all()); $post = $request->all(); $value = $post['regNo']; $determiner = Student::where('studentNo', $value)->pluck('studentNo'); $determiner1 = Management::where('id', $value)->pluck('id'); if ($validator->fails()) { $this->throwValidationException($request, $validator); } elseif ($determiner == null && $determiner1 == null) { return 'The registration number (' . $value . ') that you have entered does not exist in our database'; } Auth::login($this->create($request->all())); return redirect($this->redirectPath()); }
/** * return courses of the given school * This Method is used in user Registration * @return Response */ public function getCourseDetails(Request $request) { if (!isset($request->course_school_id)) { return; } $students = Student::where('course_school_id', $request->course_school_id)->orderBy('roll_no')->get(); $count = $students->count(); $users = []; foreach ($students as $key => $student) { array_push($users, $student->user); } $courseDetails = ['count' => $count, 'users' => $users, 'students' => $students]; return $courseDetails; if (isset($course)) { return collect($course)->toJson(); } else { return; } }
use App\Models\Team; use App\Models\Student; /* |-------------------------------------------------------------------------- | Model Factories |-------------------------------------------------------------------------- | | Here you may define all of your model factories. Model factories give | you a convenient way to create models for testing and seeding your | database. Just tell the factory how a default model should look. | */ $factory->define(App\Models\Newcomer::class, function (Faker\Generator $faker) { return ['first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'sex' => $faker->boolean, 'birth' => $faker->date, 'branch' => $faker->randomElement(array('AII', 'ISI', 'MP', 'MTE', 'SI', 'SM', 'SRT', 'TC')), 'registration_email' => $faker->safeEmail, 'registration_cellphone' => '06.12.34.56.78', 'registration_phone' => '03.12.34.56.78', 'postal_code' => 10000, 'country' => $faker->randomElement(array('france', 'FRANCE', 'CAMEROUN')), 'ine' => '1000000000A', 'referral_id' => function () { $student = Student::where('referral_validated', 1)->orderByRaw("RAND()")->take(1)->get()->first(); if ($student) { return $student->student_id; } else { return null; } }, 'team_id' => function () { $team = Team::where('validated', 1)->orderByRaw("RAND()")->take(1)->get()->first(); if ($team) { return $team->id; } else { return null; } }, 'remember_token' => str_random(10)]; }); $factory->define(App\Models\Student::class, function (Faker\Generator $faker) {
/** * Execute the console command. * * @return mixed */ public function handle() { // Find email that are ready to be started $emails = Email::where('started', 0)->whereNotNull('scheduled_for')->where('scheduled_for', '<=', DB::RAW('NOW()'))->get(); // set every email as started foreach ($emails as $email) { $email->started = 1; $email->save(); } foreach ($emails as $email) { // Generate email list // To add more email list edit this file and `App/Models/Email.php $list = []; $students = []; $newcomers = []; switch ($email->list) { case Email::STUPRELISTE: $list['*****@*****.**'] = ['name' => 'STUPRE-liste', 'user' => null]; break; case Email::VOLUNTEERS: $students = Student::where('volunteer', 1)->get(); break; case Email::CE_VALIDATED: $students = Student::where('ce', 1)->whereNotNull('team_id')->where('team_accepted', 1)->get(); break; case Email::REFERRALS_VALIDATED: $students = Student::where('referral', 1)->where('referral_validated', 1)->get(); break; case Email::REFERRALS_INCOMPLETE: $students = Student::where('referral', 1)->where('referral_validated', 0)->where(function ($query) { $query->where('phone', '')->orWhereNull('phone')->orWhere('email', '')->orWhereNull('email')->orWhere('referral_text', '')->orWhereNull('referral_text'); })->get(); break; case Email::REFERRALS_VALIDATED_BRANCH: $students = Student::where('referral', 1)->where('referral_validated', 1)->where('branch', '<>', 'tc')->get(); break; case Email::REFERRALS_VALIDATED_TC: $students = Student::where('referral', 1)->where('referral_validated', 1)->where('branch', '=', 'tc')->get(); break; case Email::ORGA: $students = Student::where('orga', 1)->get(); break; case Email::ADMIN: $students = Student::where('admin', 100)->get(); break; case Email::NEWCOMERS_ALL: $newcomers = Newcomer::all(); break; case Email::NEWCOMERS_ALL_TC: $newcomers = Newcomer::where('branch', 'TC')->get(); break; case Email::NEWCOMERS_ALL_BRANCH: $newcomers = Newcomer::where('branch', '<>', 'TC')->where('branch', '<>', 'MP')->get(); break; case Email::NEWCOMERS_ALL_MASTER: $newcomers = Newcomer::where('branch', 'MP')->get(); break; case Email::NEWCOMERS_FILLED: $newcomers = Newcomer::where('email', '<>', '')->whereNotNull('email')->get(); break; case Email::NEWCOMERS_FILLED_TC: $newcomers = Newcomer::where('branch', 'TC')->where('email', '<>', '')->whereNotNull('email')->get(); break; case Email::NEWCOMERS_FILLED_BRANCH: $newcomers = Newcomer::where('branch', '<>', 'TC')->where('branch', '<>', 'MP')->where('email', '<>', '')->whereNotNull('email')->get(); break; case Email::NEWCOMERS_FILLED_MASTER: $newcomers = Newcomer::where('branch', 'MP')->where('email', '<>', '')->whereNotNull('email')->get(); break; default: echo 'Error : Unknown email list id'; break; } // Select email to put in the list foreach ($students as $student) { $list[$student->email] = ['name' => $student->first_name . ' ' . $student->last_name, 'user' => $student]; } foreach ($newcomers as $newcomer) { if (!empty($newcomer->email)) { $list[$newcomer->email] = ['name' => $newcomer->first_name . ' ' . $newcomer->last_name, 'user' => $newcomer]; } elseif (!empty($newcomer->registration_email)) { $list[$newcomer->registration_email] = ['name' => $newcomer->first_name . ' ' . $newcomer->last_name, 'user' => $newcomer]; } } // Set count in db $email->done = 0; $email->total = count($list); $email->save(); // Send emails $delay = 0; foreach ($list as $dest => $val) { $this->currentUser = $val['user']; $view = $email->template; if ($email->is_plaintext) { $view = preg_replace_callback('/{{([A-Z0-9_]+)}}/i', array($this, 'replaceCallback'), $view); $view = nl2br(e($view)); } else { $view = preg_replace_callback('/{{([A-Z0-9_]+)}}/i', array($this, 'replaceCallback'), $view); } $job = new SendEmail($email, $view, $dest, $val['name']); $job->delay($delay); $this->dispatch($job); $delay += 5; } } }
/** * Match all newcomer without a referral to a referral * * In this algorithme, we first try to match godsons to referral of the same branch * Then we try to match them we other branch if there is no space left. * * Current algorithme as 7 big steps : * * * STEP 1 : Creation of $counts and $counts2 arrays. * $counts is used in steps 2 and 3 to lower the number of queries to DB. * And $counts2 is used in steps X, X and X to lower the number of queries to DB. * The only difference between theses two arrays is that user are grouped by branch in the first one. * * * STEP 2 : Calculate the future number of godson for each referrals. * We get the number of newcomers and we add one to each referral until reaching their wanted maximum. * If there is still newcomers when all maximums are reached, we increment the maximum * (with $counts[branch]['+1']) for everyone except thoses with a maximum at 5 (6 godsons is really too much) * and we do it again until reaching the $MAXIMUM_OVERFLOW. * * * STEP 3 : Give godsons to referrals according to the calculated value in * precedent step and according to referral and godsons location. * For every newcomers, we take all referrals of his branch that have place left * and we try to match them by full postal_code and country. If there is a match * We associate them, if there is a multiple match, we take a random referral in the list * If there is no match we pass this newcomer and try with another one. At the * end of the newcomer list, we try agains with the newcomer that we have passed * with another matching solution. We do this again with all theses matching solution : * * Full postal code * * French departement code * * French region * * Country * If there is still no match, we try to match newcomers with everyone of his branch * * * STEP 4 : Remove PMOM and Master from left newcomers * We will now try to match newcomers with referral from other branches. * So we remove PMOM and masters because we don't want to associate them * with other branch referrals. * * * STEP 5 : Calculate the future number of godson for each referrals. * It's like the step 2 but we match newcomers with all branches * * STEP 6 : Give godsons to referrals according to the calculated value in * It's like the step 3 but we match newcomers with all branches * * * STEP 7 : If everyone has now a referral we save everything to DB * * Good luck if you want to edit this algo :) * */ public static function matchReferrals() { // Settings you can tweak $MAXIMUM_OVERFLOW = 2; // Maximum of godson that can be added to a referral original max /*********************************************************************** * STEP 1 : Creation of $counts and $counts2 arrays. **********************************************************************/ // This array is created to minimize the number of query to db /*$counts = [ 'TC' => [ 42 => [ // 42 is a referral id 'current' => XX, // Current number of godson 'future' => XX, // Number of godson that will be associated at the end of the next step 'max' => XX, // Maximum number of godson asked by referral '+1' => X, // Number of godson that can be added to `max` because there is not enough referrals. Used in step 2 '+1r2' => X, // Number of godson that can be added to `max` because there is not enough referrals. Used in step X 'student' => X, // Instance of the referral ] // referrals are deleted from the array once they reach the maximum ] ]; $counts2 = [ 42 => [ // 42 is a referral id 'current' => XX, // Current number of godson 'future' => XX, // Number of godson that will be associated at the end of the next step 'max' => XX, // Maximum number of godson asked by referral '+1' => X, // Number of godson that can be added to `max` because there is not enough referrals. Used in step 2 '+1r2' => X, // Number of godson that can be added to `max` because there is not enough referrals. Used in step X 'student' => X, // Instance of the referral ] // referrals are deleted from the array once they reach the maximum ];*/ $counts = []; $counts2 = []; $referrals = Student::where(['referral' => 1, 'referral_validated' => 1])->get(); foreach ($referrals as $referral) { if (!isset($counts[$referral->branch])) { $counts[$referral->branch] = []; } if ($referral->branch != 'MP') { // Remove masters $counts[$referral->branch][$referral->student_id] = ['current' => $referral->newcomers->count(), 'future' => $referral->newcomers->count(), 'max' => $referral->referral_max, '+1' => 0, '+1r2' => 0, 'student' => $referral]; } // This array is used when there is no place left in some branches and we put godson from a branch to a referral from another if ($referral->branch != 'TC' && $referral->branch != 'MM' && $referral->branch != 'MP') { // Remove masters because they cannot have an engineer godson $counts2[$referral->student_id] =& $counts[$referral->branch][$referral->student_id]; } } /*********************************************************************** * STEP 2 : Calculate the future number of godson for each referrals **********************************************************************/ foreach ($counts as $branch => $data) { // Get number of newcomers for this branch $newcomers = Newcomer::where(['branch' => $branch, 'referral_id' => null])->count(); $currentGoal = 1; $overflow = 0; // Is true when we decide to add one to each maximum (but still < 5) while ($newcomers > 0 && $currentGoal <= 5) { // Randomize the foreach $student_ids = array_keys($data); shuffle($student_ids); foreach ($student_ids as $student_id) { $referral_array =& $counts[$branch][$student_id]; if ($referral_array['future'] < $currentGoal && $currentGoal <= $referral_array['max'] + $referral_array['+1'] && $newcomers > 0) { $transfer = $currentGoal - $referral_array['future']; $referral_array['future'] += $transfer; $newcomers -= $transfer; } } $currentGoal++; // Check if need to go over maximums and add +1 if ($currentGoal > 5 && $overflow < $MAXIMUM_OVERFLOW && $newcomers > 0) { foreach ($data as $student_id => $tmp) { if ($counts[$branch][$student_id]['max'] < 5) { $counts[$branch][$student_id]['+1']++; } } $overflow++; $currentGoal = 1; } } // Debugging snippet to see repartition and set the $MAXIMUM_OVERFLOW var /* $future = 0; foreach ($data as $student_id => $tmp) { $future += $counts[$branch][$student_id]['future']; } echo '-----'.$branch.'-----'."\n"; echo 'Nombre de nouveaux : '.(Newcomer::where(['branch' => $branch])->count())."\n"; echo 'Nombre de nouveaux qui ont trouvé un parrain : '.$future . " (peut être superieur au nombre de nouveaux si des parrains de cette branche ont parrainé des nouveaux d'autres branches)\n"; print_r($counts[$branch]); */ } /*********************************************************************** * STEP 3 : Give godsons to referrals according to the calculated value * in precedent step and according to referral and godsons location **********************************************************************/ $round = 0; $allNewcomers = Newcomer::whereNull('referral_id')->get(); $newcomers = []; foreach ($allNewcomers as $value) { $newcomers[] = $value; } $branchNotFound = []; // Newcomers in this array will have referral from other branches while (count($newcomers) > 0) { foreach ($newcomers as $key => $newcomer) { // Create array of users that are matching with the newcomer $matchingArray = []; if (isset($counts[$newcomer->branch])) { foreach ($counts[$newcomer->branch] as $student_id => $array) { if ($array['current'] >= $array['future']) { unset($counts[$newcomer->branch][$student_id]); } else { switch ($round) { case 0: // Match if newcomer and referral have same postal_code and country if ($newcomer->postal_code == $array['student']->postal_code && strtolower($newcomer->country) == strtolower($array['student']->country)) { $matchingArray[] = $student_id; } break; case 1: // Match if newcomer and referral have same french departement (postal_code/1000) and country if (floor($newcomer->postal_code / 1000) == floor($array['student']->postal_code / 1000) && strtolower($newcomer->country) == strtolower($array['student']->country)) { $matchingArray[] = $student_id; } break; case 2: // Match if newcomer and referral have same french region (region[postal_code/1000]) and country if (isset(self::REGION[floor($newcomer->postal_code / 1000)]) && isset(self::REGION[floor($array['student']->postal_code / 1000)]) && self::REGION[floor($newcomer->postal_code / 1000)] == self::REGION[floor($array['student']->postal_code / 1000)] && strtolower($newcomer->country) == strtolower($array['student']->country)) { $matchingArray[] = $student_id; } break; case 3: // Match if newcomer and referral have same country if (trim(strtolower($newcomer->country)) == trim(strtolower($array['student']->country))) { $matchingArray[] = $student_id; } break; default: // Match if newcomer and referral have nothing in common $matchingArray[] = $student_id; } } } // Take a random student in the matched referral list if (count($matchingArray)) { $student_id = $matchingArray[array_rand($matchingArray)]; $newcomer->referral_id = $student_id; $counts[$newcomer->branch][$student_id]['current']++; // Debugging snippet /* $student = $counts[$newcomer->branch][$student_id]['student']; echo $round.' '. $newcomer->first_name . ' '.$newcomer->last_name.' ('.$newcomer->branch.'|'.$newcomer->postal_code.','.$newcomer->country.') => ' .$student->first_name . ' '.$student->last_name.' ('.$student->branch.'|'.$student->postal_code.','.$student->country.')' .' '.$counts[$newcomer->branch][$student_id]['current'].'/'.$counts[$newcomer->branch][$student_id]['future']."\n"; */ unset($newcomers[$key]); } elseif ($round >= 4) { $branchNotFound[] = $newcomers[$key]; unset($newcomers[$key]); } } else { $branchNotFound[] = $newcomers[$key]; unset($newcomers[$key]); } } $round++; } /*********************************************************************** * STEP 4 : Remove PMOM and Master from left newcomers **********************************************************************/ foreach ($branchNotFound as $key => $value) { if ($value->branch == 'MM' || $value->branch == 'MP') { unset($branchNotFound[$key]); } } /*********************************************************************** * STEP 5 : Calculate the future number of godson for each referrals **********************************************************************/ $newcomers = count($branchNotFound); $currentGoal = 1; $overflow = 0; // Is true when we decide to add one to each maximum (but still <= 5) while ($newcomers > 0 && $currentGoal <= 5) { // Randomize $student_ids = array_keys($counts2); shuffle($student_ids); foreach ($student_ids as $student_id) { // unset($counts2[$student_id]['student']); // Uncomment this to debug $referral_array =& $counts2[$student_id]; if ($referral_array['future'] < $currentGoal && $currentGoal <= $referral_array['max'] + $referral_array['+1r2'] && $newcomers > 0) { $transfer = $currentGoal - $referral_array['future']; $referral_array['future'] += $transfer; $newcomers -= $transfer; } } $currentGoal++; // Check if need to go over maximums and add +1 if ($currentGoal > 5 && $overflow < $MAXIMUM_OVERFLOW && $newcomers > 0) { foreach ($counts2 as $student_id => $tmp) { if ($counts2[$student_id]['max'] < 5) { $counts2[$student_id]['+1r2']++; } } $overflow++; $currentGoal = 1; } } /*********************************************************************** * STEP 6 : Give godsons to referrals according to the calculated value * in precedent step and according to referral and godsons location **********************************************************************/ $round = 0; $newcomers = $branchNotFound; while (count($newcomers) > 0) { foreach ($newcomers as $key => $newcomer) { // Create array of users that are matching with the newcomer $matchingArray = []; if (isset($counts2)) { foreach ($counts2 as $student_id => $array) { if ($array['current'] >= $array['future']) { unset($counts2[$student_id]); } else { switch ($round) { case 0: // Match if newcomer and referral have same postal_code and country if ($newcomer->postal_code == $array['student']->postal_code && strtolower($newcomer->country) == strtolower($array['student']->country)) { $matchingArray[] = $student_id; } break; case 1: // Match if newcomer and referral have same french departement (postal_code/1000) and country if (floor($newcomer->postal_code / 1000) == floor($array['student']->postal_code / 1000) && strtolower($newcomer->country) == strtolower($array['student']->country)) { $matchingArray[] = $student_id; } break; case 2: // Match if newcomer and referral have same french region (region[postal_code/1000]) and country if (isset(self::REGION[floor($newcomer->postal_code / 1000)]) && isset(self::REGION[floor($array['student']->postal_code / 1000)]) && self::REGION[floor($newcomer->postal_code / 1000)] == self::REGION[floor($array['student']->postal_code / 1000)] && strtolower($newcomer->country) == strtolower($array['student']->country)) { $matchingArray[] = $student_id; } break; case 3: // Match if newcomer and referral have same country if (trim(strtolower($newcomer->country)) == trim(strtolower($array['student']->country))) { $matchingArray[] = $student_id; } break; default: // Match if newcomer and referral have nothing in common $matchingArray[] = $student_id; } } } // Take a random student in the matched referral list if (count($matchingArray)) { $student_id = $matchingArray[array_rand($matchingArray)]; $newcomer->referral_id = $student_id; $counts2[$student_id]['current']++; // Debugging code /* $student = $counts2[$student_id]['student']; echo $round.' '. $newcomer->first_name . ' '.$newcomer->last_name.' ('.$newcomer->branch.'|'.$newcomer->postal_code.','.$newcomer->country.') => ' .$student->first_name . ' '.$student->last_name.' ('.$student->branch.'|'.$student->postal_code.','.$student->country.')' .' '.$counts2[$student_id]['current'].'/'.$counts2[$student_id]['future']."\n"; */ unset($newcomers[$key]); } elseif ($round >= 4) { // Warning not all student have referral !! $branchNotFound[] = $newcomers[$key]; unset($newcomers[$key]); } } else { // Warning not all student have referral !! $branchNotFound[] = $newcomers[$key]; unset($newcomers[$key]); } } $round++; } /*********************************************************************** * Debugging snippet that synthetise referral matching **********************************************************************/ /* $referralList = []; foreach ($allNewcomers as $newcomer) { $referralList[$newcomer->referral_id][] = $newcomer; } foreach ($referralList as $referral_id => $array) { if (isset($array[0]->referral)) { echo '<h3>'.$array[0]->referral->first_name.' '.$array[0]->referral->last_name.'</h3>'; echo '<p>max: '.$array[0]->referral->referral_max.', '.$array[0]->referral->branch.$array[0]->referral->level.', '.$array[0]->referral->postal_code.', '.$array[0]->referral->country.'</p><ul>'; } else { echo '<h3>Aucun</h3><ul>'; } foreach ($array as $godson) { echo '<li>'.$godson->first_name.' '.$godson->last_name.' : '.$godson->branch.', '.$godson->postal_code.', '.$godson->country.', '; if (isset($godson->referral)) { if ($godson->postal_code == $godson->referral->postal_code && strtolower($godson->country) == strtolower($godson->referral->country)) { echo 'CP'; } elseif (floor($godson->postal_code/1000) == floor($godson->referral->postal_code/1000) && strtolower($godson->country) == strtolower($godson->referral->country)) { echo 'departement'; } elseif (isset(self::REGION[floor($godson->postal_code/1000)]) && isset(self::REGION[floor($godson->referral->postal_code/1000)]) && self::REGION[floor($godson->postal_code/1000)] == self::REGION[floor($godson->referral->postal_code/1000)] && strtolower($godson->country) == strtolower($godson->referral->country)) { echo 'region'; } elseif (trim(strtolower($godson->country)) == trim(strtolower($godson->referral->country))) { echo 'pays'; } } echo '</li>'; } echo '</ul>'; } */ /*********************************************************************** * STEP 7 : If everyone has now a referral we save everything to DB **********************************************************************/ // If we cannot match everyone, we cancel everything if (count($newcomers) > 0) { return false; } // Save it to DB foreach ($allNewcomers as $newcomer) { $newcomer->save(); } return true; }
public function exportStudentList() { // work on the export $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject()); $csv->setOutputBOM(Reader::BOM_UTF8); $dbColumn = Input::get('hdndbColumn'); $value = Input::get('hdnvalue'); if ($dbColumn != "all") { $infos = Student::where($dbColumn, '=', $value)->orderBy('lname', 'asc')->get(); } else { $infos = Student::all(); } $headers = Schema::getColumnListing('student_record'); $notInclude = ["id", "created_at", "updated_at"]; $x = 0; foreach ($headers as $header) { if (in_array($header, $notInclude)) { unset($headers[$x]); } $x++; } $csv->insertOne($headers); foreach ($infos as $info) { $data = array(); foreach ($headers as $header) { if ($header == "section") { $data[count($data)] = $this->secInfo($info[$header])['description']; } elseif ($header == "year_lvl") { $data[count($data)] = $this->yearInfo($info[$header])['description']; } else { $data[count($data)] = $info[$header]; } } $csv->insertOne($data); } $date_now = date('Y-m-d-H:i:s'); $filename = 'student_record(' . $date_now . ').csv'; $csv->output($filename); }
public function find($id) { return $this->student->where('id', (int) $id)->first(); }
/** * Todo: Add validator to check wether current course has not been registered nor existed * @param Request $request * @return $this */ public function saveenrollment(Request $request) { $input = $request->all(); $validator = $this->enrollment_validator($input); if ($validator->fails()) { $this->throwValidationException($request, $validator); } //get data from the form $enrollment = new Enrollment(); $enrollment->kode_seksi = $input['kode_seksi']; //query noreg from current user $user = Auth::user(); $noreg = Student::where('id_user', $user->id)->first()->Noreg; $enrollment->noreg = $noreg; $enrollment->save(); return $this->enrollmhs(); }
public function slidesBranch() { return View::make('dashboard.referrals.slides', ['referrals' => Student::where('referral', 1)->where('referral_validated', 1)->where('branch', '<>', 'TC')->orderBy('last_name')->get()]); }