2020-04-29 17:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-21 00:01:41 +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;
|
2020-10-21 00:01:41 +00:00
|
|
|
use App\Http\Requests\SaveNotesRequest;
|
2020-06-26 23:32:33 +00:00
|
|
|
use App\Notifications\ApplicationMoved;
|
|
|
|
use App\Notifications\AppointmentScheduled;
|
2020-10-21 00:01:41 +00:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Http\Request;
|
2020-05-22 02:49:16 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2020-04-29 17:15:54 +00:00
|
|
|
|
|
|
|
class AppointmentController extends Controller
|
|
|
|
{
|
2020-05-22 02:49:16 +00:00
|
|
|
private $allowedPlatforms = [
|
|
|
|
|
|
|
|
'ZOOM',
|
|
|
|
'DISCORD',
|
|
|
|
'SKYPE',
|
|
|
|
'MEET',
|
2020-10-21 00:01:41 +00:00
|
|
|
'TEAMSPEAK',
|
2020-05-22 02:49:16 +00:00
|
|
|
|
|
|
|
];
|
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
public function saveAppointment(Request $request, Application $application)
|
2020-05-22 02:49:16 +00:00
|
|
|
{
|
2020-06-27 18:15:33 +00:00
|
|
|
$this->authorize('create', Appointment::class);
|
2020-07-16 20:21:28 +00:00
|
|
|
$appointmentDate = Carbon::parse($request->appointmentDateTime);
|
2020-06-27 18:15:33 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
$appointment = Appointment::create([
|
|
|
|
'appointmentDescription' => $request->appointmentDescription,
|
|
|
|
'appointmentDate' => $appointmentDate->toDateTimeString(),
|
|
|
|
'applicationID' => $application->id,
|
|
|
|
'appointmentLocation' => (in_array($request->appointmentLocation, $this->allowedPlatforms)) ? $request->appointmentLocation : 'DISCORD',
|
|
|
|
]);
|
|
|
|
$application->setStatus('STAGE_INTERVIEW_SCHEDULED');
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
Log::info('User '.Auth::user()->name.' has scheduled an appointment with '.$application->user->name.' for application ID'.$application->id, [
|
2020-07-16 20:21:28 +00:00
|
|
|
'datetime' => $appointmentDate->toDateTimeString(),
|
2020-10-21 00:01:41 +00:00
|
|
|
'scheduled' => now(),
|
2020-07-16 20:21:28 +00:00
|
|
|
]);
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
$application->user->notify(new AppointmentScheduled($appointment));
|
2020-10-21 00:01:41 +00:00
|
|
|
$request->session()->flash('success', 'Appointment successfully scheduled @ '.$appointmentDate->toDateTimeString());
|
2020-05-22 02:49:16 +00:00
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
public function updateAppointment(Request $request, Application $application, $status)
|
2020-05-22 02:49:16 +00:00
|
|
|
{
|
2020-10-21 00:01:41 +00:00
|
|
|
$this->authorize('update', $application->appointment);
|
2020-06-27 18:15:33 +00:00
|
|
|
|
2020-05-22 02:49:16 +00:00
|
|
|
$validStatuses = [
|
2020-10-21 00:01:41 +00:00
|
|
|
'SCHEDULED',
|
|
|
|
'CONCLUDED',
|
2020-05-22 02:49:16 +00:00
|
|
|
];
|
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
// NOTE: This is a little confusing, refactor
|
|
|
|
$application->appointment->appointmentStatus = (in_array($status, $validStatuses)) ? strtoupper($status) : 'SCHEDULED';
|
|
|
|
$application->appointment->save();
|
2020-07-16 04:24:00 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
$application->setStatus('STAGE_PEERAPPROVAL');
|
|
|
|
$application->user->notify(new ApplicationMoved());
|
2020-07-16 04:24:00 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
$request->session()->flash('success', 'Interview finished! Staff members can now vote on it.');
|
2020-10-21 00:01:41 +00:00
|
|
|
|
2020-05-22 02:49:16 +00:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2020-05-29 23:20:39 +00:00
|
|
|
// also updates
|
2020-09-02 23:11:49 +00:00
|
|
|
public function saveNotes(SaveNotesRequest $request, Application $application)
|
2020-05-29 23:20:39 +00:00
|
|
|
{
|
2020-10-21 00:01:41 +00:00
|
|
|
if (! is_null($application)) {
|
2020-09-02 23:34:35 +00:00
|
|
|
$application->load('appointment');
|
|
|
|
|
2020-05-29 23:20:39 +00:00
|
|
|
$application->appointment->meetingNotes = $request->noteText;
|
|
|
|
$application->appointment->save();
|
|
|
|
|
|
|
|
$request->session()->flash('success', 'Meeting notes have been saved.');
|
2020-10-21 00:01:41 +00:00
|
|
|
} else {
|
2020-07-16 20:21:28 +00:00
|
|
|
$request->session()->flash('error', 'There\'s no appointment to save notes to!');
|
2020-05-29 23:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|