/** * Run the database seeds. * * @return void */ public function run() { $league = \App\Models\League::where(['name' => 'Bundesliga'])->first(); if ($league) { if (\App\Models\Team::where(['leagueId' => $league->id])->count() > 2) { return false; } DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Schalke 04', 'logoPath' => 'teams-logo/schalke04.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Hertha BSC', 'logoPath' => 'teams-logo/hertha.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => '1. FC Köln', 'logoPath' => 'teams-logo/koln.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'FC Ingolstadt 04', 'logoPath' => 'teams-logo/ingolstadt.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Bayer Leverkusen', 'logoPath' => 'teams-logo/leverkusen.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => '1. FSV Mainz 05', 'logoPath' => 'teams-logo/mainz.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'VfL Wolfsburg', 'logoPath' => 'teams-logo/wolfsburg.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'SV Darmstadt 98', 'logoPath' => 'teams-logo/darmstadt.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Hamburger SV', 'logoPath' => 'teams-logo/hamburger.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Eintracht Frankfurt', 'logoPath' => 'teams-logo/eintracht.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Borussia Mönchengladbach', 'logoPath' => 'teams-logo/munchengladbach.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Werder Bremen', 'logoPath' => 'teams-logo/werder.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Hoffenheim', 'logoPath' => 'teams-logo/hoffenheim.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'FC Augsburg', 'logoPath' => 'teams-logo/augsburg.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Hannover 96', 'logoPath' => 'teams-logo/hannover.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'VfB Stuttgart', 'logoPath' => 'teams-logo/stuttgart.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); } else { $league = \App\Models\League::firstOrNew(['name' => 'Bundesliga', 'logoPath' => 'leagues-logo/bundesliga.png']); $league->save(); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'FC Bayern Munich', 'logoPath' => 'teams-logo/bayern.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); DB::table('teams')->insert(['leagueId' => $league->id, 'name' => 'Borussia Dortmund', 'logoPath' => 'teams-logo/dortmund.png', 'created_at' => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()]); } }
public function invite(Request $request) { $limits = array(0, 2, 3, 99999999999, 0); $user = $request->user(); $userId = $user->id; $userRole = $user->type; /** * Check if user has right to invite. * User has right if has no parent_user, has available limit and inviting email not registered */ if ($user->parent_user) { $request->session()->flash('error', "Sorry you have no right to create team."); return redirect('team'); } $email = $request->get('email'); $member = User::where('email', '=', $email)->first(); if ($member) { if (!$member->activation) { $request->session()->flash('error', "The invitation is already sent"); return redirect('team'); } $request->session()->flash('error', "Sorry, you can't send request to registered users."); return redirect('team'); } else { $member = TeamInvitation::where('accept_email', '=', $request->get('email'))->first(); if ($member) { $request->session()->flash('error', "Sorry, you can't send request to invited user."); return redirect('team'); } } $existingMembers = Team::where('member_id', '=', $userId)->get(); $expiredLimit = count($existingMembers) - 1; $invitedMembers = TeamInvitation::where('request_id', '=', $userId)->get(); $expiredLimit += count($invitedMembers); if ($limits[$userRole] <= $expiredLimit) { $request->session()->flash('error', "Sorry, your limit is expired."); return redirect('team'); } elseif ($request->user()->type == 4 || $request->user()->parent_user) { $request->session()->flash('error', "you can't invite team members"); return redirect('team'); } /** * Need create record in team_invitation */ $teamInvitation = new TeamInvitation(); $teamInvitation->request_id = $userId; $teamInvitation->request_user_email = $user->email; $activationCode = str_random(80); $teamInvitation->accept_id = $activationCode; $teamInvitation->accept_email = $email; $teamInvitation->status = 0; $teamInvitation->save(); /** * Sending invitation email */ // $this->sendEmail($user->name, $user->email, $activationCode); $request->session()->flash('message', "Invitation successfully sent."); return redirect('team'); }
public function postCreateTeam(LoggedInRequest $request) { if (Team::where('abb', $request->input('teamAbb'))->first()) { $request->session()->flash('msg', 'That abbreviation has been taken!!'); return $this->getCreateTeam($request); } $hash = self::generateRandomInt(); while (Team::where('team_key', $hash)->first() != null) { $hash = self::generateRandomInt(); } $team = new Team(); $team->team_key = $hash; $team->name = $request->input('teamName'); $team->abb = strtoupper($request->input('teamAbb')); $team->save(); $request->session()->flash('msg', 'Team ' . $team->name . ' created!'); return $this->getEditTeam($request); }
public function updateMe(Request $request) { $user = Auth::user(); $data = $request->all(); foreach ($data as $key => $value) { //update the user info if (in_array($key, ['email', 'first_name', 'last_name', 'phone'])) { $user->{$key} = $value; $user->save(); } } $hasApplication = false; if (isset($data['application'])) { $hasApplication = true; //update the application $application = self::getApplication()['application']; foreach ($data['application'] as $key => $value) { if (in_array($key, ['age', 'grad_year', 'gender', 'major', 'diet', 'diet_restrictions', 'tshirt', 'github', 'essay1', 'essay2', 'resume_filename', 'resume_uploaded', 'travellingFrom', 'isTravellingFromSchool'])) { $application->{$key} = $value; } if ($key == "team_code") { $team = Team::where("code", $value)->get()->first(); if ($team) { //todo return status of this $application->team_id = $team->id; } } if ($key == "school") { if (isset($value['id'])) { $application->school_id = $value['id']; } else { $application->school_id = NULL; } } } $application->save(); } if ($hasApplication) { return ['application' => $application, 'validation' => $application->validationDetails(), 'phase' => intval(getenv('APP_PHASE')), 'status' => 'ok']; } return ['status' => 'ok']; }
public function getGame($winner, $loser) { $winner = Team::where("abb", $winner)->first(); if ($winner != null) { $winner->wins++; $winner->games++; $winner->save(); $winnerKey = $winner->team_key; } $loser = Team::where("abb", $loser)->first(); if ($loser != null) { $loser->games++; $loser->save(); $loserKey = $loser->team_key; } if ($winner != null && $loser != null) { $game = new Game(); $game->winner = $winnerKey; $game->loser = $loserKey; $game->save(); } return "Ok"; }
public function accountIsActive($code) { $user = User::where('activation_code', '=', $code)->first(); if ($user) { $user->activation = 1; $user->activation_code = ''; $user->type = 4; $user->save(); if ($user->parent_user) { $teamMember = Team::where('member_id', '=', $user->id)->first(); $teamMember->status = 2; if ($teamMember->save()) { $teamInvaiteMember = TeamInvitation::where('accept_email', '=', $user->email)->first(); $teamInvaiteMember->delete(); } } if ($user->save()) { \Auth::login($user); } return true; } return false; }
/** * A user announced his availability for a certain plan * * @param plan_id integer * @param available boolean * * (This is an API type call) */ public function available($plan_id, $available) { $bool = $available == 'true' ? True : False; // get current plan $plan = Plan::with('teams')->find($plan_id); if ($plan->count()) { $user_id = Auth::user()->id; // check if this user is already part of this plan $team = Team::where('plan_id', $plan_id)->where('user_id', $user_id)->first(); if ($team) { // if the user has already be assigned a role, we only change their availability if ($team->role_id || $team->confirmed || $bool) { $team->update(['available' => $bool]); } else { // if the user wasn't assigned a role yet, we can delete the record altogether. $team->delete(); } } else { // create a new team member record for this plan $team = new Team(['user_id' => $user_id, 'available' => $bool]); $plan->teams()->save($team); } return response()->json("User's availability changed to " . $available, 200); } return response()->json("requested failed, no changes made!", 404); }
| | 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) { return ['student_id' => $faker->unique()->randomNumber(5), 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'sex' => $faker->boolean, 'surname' => $faker->firstName, 'email' => $faker->safeEmail, 'phone' => '03.12.34.56.78', 'postal_code' => $faker->randomNumber(5), 'city' => $faker->city, 'country' => $faker->country, 'branch' => $faker->randomElement(array('AII', 'ISI', 'MP', 'MTE', 'SI', 'SM', 'SRT', 'TC')), 'level' => $faker->randomNumber(1), 'facebook' => $faker->url, 'referral' => $faker->boolean, 'referral_text' => $faker->text, 'referral_max' => $faker->numberBetween(1, 5), 'referral_validated' => $faker->boolean, 'ce' => $faker->boolean, 'team_id' => function () { $team = Team::orderByRaw("RAND()")->take(1)->get()->first(); if ($team) { return $team->id; } else { return null; }
/** * Trigger certain actions when leader or teacher of a plan was changed * * a) send notification to each invovled * b) change the team accordingly * * @param Request $request all data from the HTTP request (the new data) * @param EloquentModel $plan (the old data) */ function checkIfLeaderOrTeacherWasChanged($request, $plan) { $msg = false; // check if LEADER was changed if ($plan->leader_id != $request->leader_id) { // check if reason was given for the change if (!$request->has('reasonForChange')) { flashError('Please provide reason for the change of leader!'); return false; } // find the corresponding team record for the leader $leader = Team::where([['plan_id', $plan->id], ['role_id', env('LEADER_ID', 4)]]); if ($leader->count()) { // update the team record $leader->update(['user_id' => $request->leader_id]); } else { // create a new team member... $plan->leader_id = $request->leader_id; addDefaultRolesAndResourcesToPlan($plan); } // affected users must be notified of this change accordingly $new_leader = User::find($request->leader_id); $recipient = $new_leader->id; $subject = 'Leader changed for Event on ' . Carbon::parse($plan->date)->format('l, jS \\of F Y'); $msg = Auth::user()->name . ' changed the leader for this ' . $plan->type->name . ' from ' . $plan->leader->name . ' to ' . $new_leader->name; } // check if TEACHER was changed if ($plan->teacher_id != $request->teacher_id) { // check if a reason was given for the change if (!$request->has('reasonForChange')) { flashError('Please provide reason for the change of teacher!'); return false; } // find the corresponding team record for the teacher $teacher = Team::where([['plan_id', $plan->id], ['role_id', env('TEACHER_ID', 5)]]); if ($teacher->count()) { // update the team record $teacher->update(['user_id' => $request->teacher_id]); } else { // create a new team member... $plan->teacher_id = $request->teacher_id; addDefaultRolesAndResourcesToPlan($plan); } // affected users must be notified of this change accordingly $new_teacher = User::find($request->teacher_id); $recipient = $new_teacher->id; $subject = 'Teacher changed for Event on ' . Carbon::parse($plan->date)->format('l, jS \\of F Y'); $msg = Auth::user()->name . ' changed the teacher for this ' . $plan->type->name . ' from ' . $plan->teacher->name . ' to ' . $new_teacher->name; } if ($msg) { // send internal notification and message sendInternalMessage($subject, $msg, $recipient); Log::info($subject . ' - ' . $msg); // also create a history record for this change $history = new History(['user_id' => Auth::user()->id, 'changes' => $subject . "\n" . $msg, 'reason' => $request->reasonForChange]); $plan->histories()->save($history); } return true; }
/** * Remove season. * * @param int $id * @return Response */ public function destroy($season_id) { Season::destroy($season_id); Team::where('season_id', $season_id)->delete(); Fixture::where('season_id', $season_id)->delete(); LeagueTable::where('season_id', $season_id)->delete(); return response()->json(['success' => true]); }
public function addToTeam(User $member, $parentUser) { $teamInvitation = TeamInvitation::where('accept_email', '=', $member->email)->where('request_id', '=', $parentUser)->first(); if (!$teamInvitation) { die("Something went wrong.You have no invitation"); } $userTeam = Team::where('member_id', '=', $parentUser)->first(); if (!$userTeam) { $userTeam = new Team(); $userTeam->member_id = $parentUser; $userTeam->status = 2; $userTeam->save(); $userTeam->team_id = $userTeam->id; $userTeam->save(); } $teamId = $userTeam->team_id; $teamInvitation->status = 1; $teamInvitation->save(); $team = new Team(); $team->team_id = $teamId; $team->member_id = $member->id; $team->status = 1; //user is not activated $team->save(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $coatch = Coatch::findOrFail($id); $team = Team::where('TRENER_ID_TRENER', $id)->first(); if (!empty($team)) { $text = 'Nie mozna usunac - posiada przypisaną druzynę (' . $team->NAZWA . ')'; return redirect()->route('coatches.index')->with('message', $text); } $coatch->delete(); return redirect()->route('coatches.index')->with('message', 'Item deleted successfully.'); }