Apply fixes from StyleCI

This commit is contained in:
2020-10-10 16:30:26 +00:00
committed by StyleCI Bot
parent b2adcee51e
commit 6541e25a39
238 changed files with 5627 additions and 1878 deletions

View File

@@ -1,5 +1,24 @@
<?php
/*
* Copyright © 2020 Miguel Nogueira
*
* This file is part of Raspberry Staff Manager.
*
* Raspberry Staff Manager is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Raspberry Staff Manager is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Raspberry Staff Manager. If not, see <https://www.gnu.org/licenses/>.
*/
namespace App\Http\Controllers;
use App\Http\Requests\EditTeamRequest;
@@ -16,7 +35,6 @@ use Mpociot\Teamwork\Exceptions\UserNotInTeamException;
use Mpociot\Teamwork\Facades\Teamwork;
use Mpociot\Teamwork\TeamInvite;
class TeamController extends Controller
{
/**
@@ -52,12 +70,13 @@ class TeamController extends Controller
{
$team = Team::create([
'name' => $request->teamName,
'owner_id' => Auth::user()->id
'owner_id' => Auth::user()->id,
]);
Auth::user()->teams()->attach($team->id);
$request->session()->flash('success', 'Team successfully created.');
return redirect()->back();
}
@@ -101,6 +120,7 @@ class TeamController extends Controller
$team->save();
$request->session()->flash('success', 'Team edited successfully.');
return redirect()->to(route('teams.index'));
}
@@ -119,50 +139,34 @@ class TeamController extends Controller
{
$user = User::findOrFail($request->user);
if (!$team->openJoin)
{
if (!Teamwork::hasPendingInvite($user->email, $team))
{
Teamwork::inviteToTeam($user, $team, function(TeamInvite $invite) use ($user) {
if (! $team->openJoin) {
if (! Teamwork::hasPendingInvite($user->email, $team)) {
Teamwork::inviteToTeam($user, $team, function (TeamInvite $invite) use ($user) {
Mail::to($user)->send(new InviteToTeam($invite));
});
$request->session()->flash('success', 'Invite sent! They can now accept or deny it.');
}
else
{
} else {
$request->session()->flash('error', 'This user has already been invited.');
}
}
else
{
} else {
$request->session()->flash('error', 'You can\'t invite users to public teams.');
}
return redirect()->back();
}
public function processInviteAction(Request $request, $action, $token)
{
switch($action)
{
switch ($action) {
case 'accept':
$invite = Teamwork::getInviteFromAcceptToken($token);
if ($invite && $invite->user->is(Auth::user()))
{
if ($invite && $invite->user->is(Auth::user())) {
Teamwork::acceptInvite($invite);
$request->session()->flash('success', 'Invite accepted! You have now joined ' . $invite->team->name . '.');
}
else
{
$request->session()->flash('success', 'Invite accepted! You have now joined '.$invite->team->name.'.');
} else {
$request->session()->flash('error', 'Invalid or expired invite URL.');
}
@@ -172,13 +176,10 @@ class TeamController extends Controller
$invite = Teamwork::getInviteFromDenyToken($token);
if ($invite && $invite->user->is(Auth::user()))
{
if ($invite && $invite->user->is(Auth::user())) {
Teamwork::denyInvite($invite);
$request->session()->flash('success', 'Invite denied! Ask for another invite if this isn\'t what you meant.');
}
else
{
} else {
$request->session()->flash('error', 'Invalid or expired invite URL.');
}
@@ -187,31 +188,25 @@ class TeamController extends Controller
default:
$request->session()->flash('error', 'Sorry, but the invite URL you followed was malformed. Try asking for another invite, or submit a bug report.');
}
// This page will show the user's current teams
return redirect()->to(route('teams.index'));
}
public function switchTeam(Request $request, Team $team)
{
try
{
try {
Auth::user()->switchTeam($team);
$request->session()->flash('success', 'Switched teams! Your team dashboard will now use this context.');
}
catch(UserNotInTeamException $ex)
{
} catch (UserNotInTeamException $ex) {
$request->session()->flash('error', 'You can\'t switch to a team you don\'t belong to.');
}
return redirect()->back();
}
// Since it's a separate form, we shouldn't use the same update method
public function assignVacancies(Request $request, Team $team)
{
@@ -222,41 +217,33 @@ class TeamController extends Controller
$requestVacancies = $request->assocVacancies;
$currentVacancies = $team->vacancies->pluck('id')->all();
if (is_null($requestVacancies))
{
foreach ($team->vacancies as $vacancy)
{
if (is_null($requestVacancies)) {
foreach ($team->vacancies as $vacancy) {
$team->vacancies()->detach($vacancy->id);
}
$request->session()->flash('success', 'Removed all vacancy associations.');
return redirect()->back();
}
$vacancyDiff = array_diff($requestVacancies, $currentVacancies);
$deselectedDiff = array_diff($currentVacancies, $requestVacancies);
if (!empty($vacancyDiff) || !empty($deselectedDiff))
{
foreach ($vacancyDiff as $selectedVacancy)
{
if (! empty($vacancyDiff) || ! empty($deselectedDiff)) {
foreach ($vacancyDiff as $selectedVacancy) {
$team->vacancies()->attach($selectedVacancy);
}
foreach ($deselectedDiff as $deselectedVacancy)
{
foreach ($deselectedDiff as $deselectedVacancy) {
$team->vacancies()->detach($deselectedVacancy);
}
}
else
{
} else {
$team->vacancies()->attach($requestVacancies);
}
$request->session()->flash('success', 'Assignments changed successfully.');
return redirect()->back();
return redirect()->back();
}
}