2020-04-29 17:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-10 16:30:26 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-04-29 17:15:54 +00:00
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-05-08 07:10:25 +00:00
|
|
|
use App\Application;
|
2021-09-03 23:44:54 +00:00
|
|
|
use App\Exceptions\ApplicationNotFoundException;
|
2021-07-25 21:54:15 +00:00
|
|
|
use App\Exceptions\IncompleteApplicationException;
|
|
|
|
use App\Exceptions\UnavailableApplicationException;
|
|
|
|
use App\Exceptions\VacancyNotFoundException;
|
|
|
|
use App\Services\ApplicationService;
|
2020-04-29 17:15:54 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-05-08 07:10:25 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2020-04-29 17:15:54 +00:00
|
|
|
|
|
|
|
class ApplicationController extends Controller
|
|
|
|
{
|
2021-01-29 16:56:29 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
private $applicationService;
|
2021-03-31 18:39:42 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
public function __construct(ApplicationService $applicationService) {
|
2020-05-29 23:20:39 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
$this->applicationService = $applicationService;
|
2020-05-29 23:20:39 +00:00
|
|
|
}
|
2020-04-30 15:38:54 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
|
2020-05-11 15:44:47 +00:00
|
|
|
public function showUserApps()
|
2020-04-30 15:38:54 +00:00
|
|
|
{
|
2020-05-11 15:44:47 +00:00
|
|
|
return view('dashboard.user.applications')
|
|
|
|
->with('applications', Auth::user()->applications);
|
2020-04-30 15:55:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
public function showUserApp(Request $request, Application $application)
|
2020-05-22 02:49:16 +00:00
|
|
|
{
|
2021-07-20 09:32:43 +00:00
|
|
|
$this->authorize('view', $application);
|
|
|
|
|
|
|
|
if (!is_null($application)) {
|
|
|
|
return view('dashboard.user.viewapp')
|
|
|
|
->with(
|
|
|
|
[
|
|
|
|
'application' => $application,
|
|
|
|
'comments' => $application->comments,
|
|
|
|
'structuredResponses' => json_decode($application->response->responseData, true),
|
|
|
|
'formStructure' => $application->response->form,
|
|
|
|
'vacancy' => $application->response->vacancy,
|
2021-07-25 21:54:15 +00:00
|
|
|
'canVote' => $this->applicationService->canVote($application->votes),
|
2021-07-20 09:32:43 +00:00
|
|
|
]
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$request->session()->flash('error', __('The application you requested could not be found.'));
|
2020-05-22 02:49:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-20 09:32:43 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
2020-05-22 02:49:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 02:55:09 +00:00
|
|
|
public function showAllApps(Request $request)
|
2020-07-11 01:43:59 +00:00
|
|
|
{
|
2021-07-20 09:32:43 +00:00
|
|
|
$this->authorize('viewAny', Application::class);
|
2021-03-31 02:55:09 +00:00
|
|
|
|
2021-09-03 23:44:54 +00:00
|
|
|
return view('dashboard.appmanagement.all')
|
|
|
|
->with('applications', Application::all());
|
2021-03-31 02:55:09 +00:00
|
|
|
|
2020-07-11 01:43:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-08 05:06:24 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
public function renderApplicationForm($vacancySlug)
|
2020-05-08 05:06:24 +00:00
|
|
|
{
|
2021-09-03 23:44:54 +00:00
|
|
|
try {
|
|
|
|
return $this->applicationService->renderForm($vacancySlug);
|
|
|
|
}
|
|
|
|
catch (ApplicationNotFoundException $ex) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('error', $ex->getMessage());
|
|
|
|
}
|
2020-05-08 05:06:24 +00:00
|
|
|
}
|
2020-05-08 07:10:25 +00:00
|
|
|
|
|
|
|
public function saveApplicationAnswers(Request $request, $vacancySlug)
|
|
|
|
{
|
2021-07-25 21:54:15 +00:00
|
|
|
try {
|
2020-05-08 07:10:25 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
$this->applicationService->fillForm(Auth::user(), $request->all(), $vacancySlug);
|
2021-07-20 09:32:43 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
} catch (VacancyNotFoundException | IncompleteApplicationException | UnavailableApplicationException $e) {
|
2020-06-26 23:32:33 +00:00
|
|
|
|
2021-03-31 18:39:42 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
2021-07-25 21:54:15 +00:00
|
|
|
->with('error', $e->getMessage());
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 18:39:42 +00:00
|
|
|
return redirect()
|
2021-09-03 23:44:54 +00:00
|
|
|
->to(route('showUserApps'))
|
2021-07-25 21:54:15 +00:00
|
|
|
->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.'));
|
2020-05-08 07:10:25 +00:00
|
|
|
}
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2020-09-02 19:52:56 +00:00
|
|
|
public function updateApplicationStatus(Request $request, Application $application, $newStatus)
|
2020-05-22 02:49:16 +00:00
|
|
|
{
|
2021-03-31 18:39:42 +00:00
|
|
|
$messageIsError = false;
|
2021-07-20 09:32:43 +00:00
|
|
|
$this->authorize('update', Application::class);
|
2021-03-31 18:39:42 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
try {
|
|
|
|
$status = $this->applicationService->updateStatus($application, $newStatus);
|
|
|
|
} catch (\LogicException $ex)
|
|
|
|
{
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('error', $ex->getMessage());
|
2021-03-31 18:39:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('success', $status);
|
2020-05-22 02:49:16 +00:00
|
|
|
}
|
2020-07-12 16:01:33 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
/**
|
|
|
|
* @throws \Illuminate\Auth\Access\AuthorizationException
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2020-07-12 16:01:33 +00:00
|
|
|
public function delete(Request $request, Application $application)
|
|
|
|
{
|
2021-07-20 09:32:43 +00:00
|
|
|
$this->authorize('delete', $application);
|
2021-07-25 21:54:15 +00:00
|
|
|
$this->applicationService->delete($application);
|
2020-07-16 20:21:28 +00:00
|
|
|
|
2021-07-20 09:32:43 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('success', __('Application deleted. Comments, appointments and responses have also been deleted.'));
|
2021-03-31 18:39:42 +00:00
|
|
|
|
2020-07-12 16:01:33 +00:00
|
|
|
}
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|