2020-04-29 17:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-05-22 02:49:16 +00:00
|
|
|
use App\Application;
|
2020-05-29 23:20:39 +00:00
|
|
|
use App\Http\Requests\SaveNotesRequest;
|
2020-05-22 02:49:16 +00:00
|
|
|
use Carbon\Carbon;
|
2020-04-29 17:15:54 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-05-22 02:49:16 +00:00
|
|
|
use App\Appointment;
|
2020-06-26 23:32:33 +00:00
|
|
|
use App\Notifications\ApplicationMoved;
|
|
|
|
use App\Notifications\AppointmentScheduled;
|
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',
|
|
|
|
'TEAMSPEAK'
|
|
|
|
|
|
|
|
];
|
|
|
|
|
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-07-16 20:21:28 +00:00
|
|
|
Log::info('User ' . Auth::user()->name . ' has scheduled an appointment with ' . $application->user->name . ' for application ID' . $application->id, [
|
|
|
|
'datetime' => $appointmentDate->toDateTimeString(),
|
|
|
|
'scheduled' => now()
|
|
|
|
]);
|
2020-05-22 02:49:16 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
$application->user->notify(new AppointmentScheduled($appointment));
|
|
|
|
$request->session()->flash('success', 'Appointment successfully scheduled @ ' . $appointmentDate->toDateTimeString());
|
2020-06-27 18:15:33 +00:00
|
|
|
|
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-07-16 20:21:28 +00:00
|
|
|
$this->authorize('update', $application->appointment);
|
2020-06-27 18:15:33 +00:00
|
|
|
|
2020-05-22 02:49:16 +00:00
|
|
|
$validStatuses = [
|
|
|
|
'SCHEDULED',
|
|
|
|
'CONCLUDED'
|
|
|
|
];
|
|
|
|
|
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-05-22 02:49:16 +00:00
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
$request->session()->flash('success', 'Interview finished! Staff members can now vote on it.');
|
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
|
|
|
{
|
|
|
|
if (!is_null($application))
|
|
|
|
{
|
|
|
|
$application->appointment->meetingNotes = $request->noteText;
|
|
|
|
$application->appointment->save();
|
|
|
|
|
|
|
|
$request->session()->flash('success', 'Meeting notes have been saved.');
|
|
|
|
}
|
|
|
|
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-05-22 02:49:16 +00:00
|
|
|
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|