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-22 02:49:16 +00:00
|
|
|
use App\Application;
|
|
|
|
use App\Appointment;
|
2021-07-25 21:54:15 +00:00
|
|
|
use App\Exceptions\InvalidAppointmentException;
|
|
|
|
use App\Exceptions\InvalidAppointmentStatusException;
|
2020-10-10 16:30:26 +00:00
|
|
|
use App\Http\Requests\SaveNotesRequest;
|
2021-07-25 21:54:15 +00:00
|
|
|
use App\Services\AppointmentService;
|
|
|
|
use App\Services\MeetingNoteService;
|
2020-10-10 16:30:26 +00:00
|
|
|
use Carbon\Carbon;
|
2021-07-25 21:54:15 +00:00
|
|
|
use Illuminate\Auth\Access\AuthorizationException;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
2020-10-10 16:30:26 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-04-29 17:15:54 +00:00
|
|
|
|
|
|
|
class AppointmentController extends Controller
|
|
|
|
{
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
private $appointmentService;
|
|
|
|
private $meetingNoteService;
|
2020-05-22 02:49:16 +00:00
|
|
|
|
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
public function __construct(AppointmentService $appointmentService, MeetingNoteService $meetingNoteService) {
|
2020-06-27 18:15:33 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
$this->appointmentService = $appointmentService;
|
|
|
|
$this->meetingNoteService = $meetingNoteService;
|
|
|
|
}
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
public function saveAppointment(Request $request, Application $application): RedirectResponse
|
|
|
|
{
|
|
|
|
$this->authorize('create', Appointment::class);
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
$appointmentDate = Carbon::parse($request->appointmentDateTime);
|
|
|
|
$this->appointmentService->createAppointment($application, $appointmentDate, $request->appointmentDescription, $request->appointmentLocation);
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('success',__('Appointment successfully scheduled @ :appointmentTime', ['appointmentTime', $appointmentDate->toDateTimeString()]));
|
2020-05-22 02:49:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
/**
|
|
|
|
* @throws AuthorizationException
|
|
|
|
*/
|
|
|
|
public function updateAppointment(Application $application, $status): RedirectResponse
|
2020-05-22 02:49:16 +00:00
|
|
|
{
|
2020-10-10 16:30:26 +00:00
|
|
|
$this->authorize('update', $application->appointment);
|
2020-06-27 18:15:33 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
try {
|
|
|
|
$this->appointmentService->updateAppointment($application, $status);
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('success', __("Interview finished! Staff members can now vote on it."));
|
2020-07-16 04:24:00 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
}
|
|
|
|
catch (InvalidAppointmentStatusException $ex) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('error', $ex->getMessage());
|
|
|
|
}
|
2020-07-16 04:24:00 +00:00
|
|
|
|
2020-10-10 16:30:26 +00:00
|
|
|
|
2020-05-22 02:49:16 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 23:11:49 +00:00
|
|
|
public function saveNotes(SaveNotesRequest $request, Application $application)
|
2020-05-29 23:20:39 +00:00
|
|
|
{
|
2021-07-25 21:54:15 +00:00
|
|
|
try {
|
2020-09-02 23:34:35 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
$this->meetingNoteService->addToApplication($application, $request->noteText);
|
2020-05-29 23:20:39 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('success', 'Saved notes.');
|
2020-05-29 23:20:39 +00:00
|
|
|
|
2021-07-25 21:54:15 +00:00
|
|
|
} catch (InvalidAppointmentException $ex) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('error', $ex->getMessage());
|
|
|
|
}
|
2020-05-29 23:20:39 +00:00
|
|
|
}
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|