2020-04-29 17:15:54 +00:00
|
|
|
<?php
|
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
namespace App\Http\Controllers;
|
2020-07-11 19:34:26 +00:00
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
use App\Http\Requests\VacancyRequest;
|
2020-10-21 00:29:50 +00:00
|
|
|
use App\Http\Requests\VacancyEditRequest;
|
|
|
|
|
2020-10-21 00:01:41 +00:00
|
|
|
use App\Vacancy;
|
2020-10-21 00:29:50 +00:00
|
|
|
use App\User;
|
|
|
|
use App\Form;
|
|
|
|
|
|
|
|
use App\Notifications\VacancyClosed;
|
|
|
|
|
2020-04-29 17:15:54 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-05-08 05:06:24 +00:00
|
|
|
use Illuminate\Support\Str;
|
2020-10-21 00:29:50 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
2020-07-11 04:34:12 +00:00
|
|
|
|
2020-04-29 17:15:54 +00:00
|
|
|
class VacancyController extends Controller
|
|
|
|
{
|
2020-05-03 04:04:26 +00:00
|
|
|
public function index()
|
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
$this->authorize('viewAny', Vacancy::class);
|
2020-05-07 23:24:56 +00:00
|
|
|
return view('dashboard.administration.positions')
|
|
|
|
->with([
|
|
|
|
'forms' => Form::all(),
|
2020-10-21 00:29:50 +00:00
|
|
|
'vacancies' => Vacancy::all()
|
2020-05-07 23:24:56 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function store(VacancyRequest $request)
|
|
|
|
{
|
2020-06-27 18:15:33 +00:00
|
|
|
$this->authorize('create', Vacancy::class);
|
2020-05-07 23:24:56 +00:00
|
|
|
$form = Form::find($request->vacancyFormID);
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
if (!is_null($form))
|
|
|
|
{
|
|
|
|
/* note: since we can't convert HTML back to Markdown, we'll have to do the converting when the user requests a page,
|
|
|
|
* and leave the database with Markdown only so it can be used and edited everywhere.
|
|
|
|
* for several vacancies, this would require looping through all of them and replacing MD with HTML, which is obviously not the most clean solution;
|
|
|
|
* however, the Model can be configured to return MD instead of HTML on that specific field saving us from looping.
|
|
|
|
*/
|
2020-05-07 23:24:56 +00:00
|
|
|
Vacancy::create([
|
|
|
|
|
|
|
|
'vacancyName' => $request->vacancyName,
|
|
|
|
'vacancyDescription' => $request->vacancyDescription,
|
2020-07-11 19:34:26 +00:00
|
|
|
'vacancyFullDescription' => $request->vacancyFullDescription,
|
2020-05-08 05:06:24 +00:00
|
|
|
'vacancySlug' => Str::slug($request->vacancyName),
|
2020-05-07 23:24:56 +00:00
|
|
|
'permissionGroupName' => $request->permissionGroup,
|
|
|
|
'discordRoleID' => $request->discordRole,
|
|
|
|
'vacancyFormID' => $request->vacancyFormID,
|
2020-10-21 00:29:50 +00:00
|
|
|
'vacancyCount' => $request->vacancyCount
|
2020-05-07 23:24:56 +00:00
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
$request->session()->flash('success', 'Vacancy successfully opened. It will now show in the home page.');
|
2020-10-21 00:29:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-07 23:24:56 +00:00
|
|
|
$request->session()->flash('error', 'You cannot create a vacancy without a valid form.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-05-07 23:24:56 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 20:21:28 +00:00
|
|
|
public function updatePositionAvailability(Request $request, $status, Vacancy $vacancy)
|
2020-05-07 23:24:56 +00:00
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-06-27 18:15:33 +00:00
|
|
|
$this->authorize('update', $vacancy);
|
2020-05-07 23:24:56 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
if (!is_null($vacancy))
|
|
|
|
{
|
2020-05-07 23:24:56 +00:00
|
|
|
$type = 'success';
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
switch ($status)
|
|
|
|
{
|
2020-05-07 23:24:56 +00:00
|
|
|
case 'open':
|
|
|
|
$vacancy->open();
|
2020-10-21 00:29:50 +00:00
|
|
|
$message = "Position successfully opened!";
|
2020-05-07 23:24:56 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'close':
|
|
|
|
$vacancy->close();
|
2020-10-21 00:29:50 +00:00
|
|
|
$message = "Position successfully closed!";
|
|
|
|
|
|
|
|
foreach(User::all() as $user)
|
|
|
|
{
|
|
|
|
if ($user->isStaffMember())
|
|
|
|
{
|
|
|
|
$user->notify(new VacancyClosed($vacancy));
|
|
|
|
}
|
2020-06-26 23:32:33 +00:00
|
|
|
}
|
2020-05-07 23:24:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$message = "Please do not tamper with the button's URLs. To report a bug, please contact an administrator.";
|
|
|
|
$type = 'error';
|
|
|
|
|
|
|
|
}
|
2020-10-21 00:29:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-07 23:24:56 +00:00
|
|
|
$message = "The position you're trying to update doesn't exist!";
|
2020-10-21 00:29:50 +00:00
|
|
|
$type = "error";
|
2020-05-07 23:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$request->session()->flash($type, $message);
|
|
|
|
return redirect()->back();
|
2020-05-03 04:04:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-09-03 01:50:19 +00:00
|
|
|
public function edit(Request $request, Vacancy $vacancy)
|
2020-07-11 19:34:26 +00:00
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
$this->authorize('update', $vacancy);
|
2020-07-11 19:34:26 +00:00
|
|
|
return view('dashboard.administration.editposition')
|
2020-09-03 01:52:21 +00:00
|
|
|
->with('vacancy', $vacancy);
|
2020-07-11 19:34:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
|
|
|
|
|
2020-07-25 00:20:43 +00:00
|
|
|
public function update(VacancyEditRequest $request, Vacancy $vacancy)
|
2020-07-11 19:34:26 +00:00
|
|
|
{
|
2020-10-21 00:29:50 +00:00
|
|
|
$this->authorize('update', $vacancy);
|
2020-07-11 19:34:26 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
$vacancy->vacancyFullDescription = $request->vacancyFullDescription;
|
|
|
|
$vacancy->vacancyDescription = $request->vacancyDescription;
|
|
|
|
$vacancy->vacancyCount = $request->vacancyCount;
|
2020-07-11 19:34:26 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
$vacancy->save();
|
2020-07-11 19:34:26 +00:00
|
|
|
|
2020-10-21 00:29:50 +00:00
|
|
|
$request->session()->flash('success', 'Vacancy successfully updated.');
|
|
|
|
return redirect()->back();
|
2020-07-11 19:34:26 +00:00
|
|
|
|
|
|
|
}
|
2020-10-21 00:29:50 +00:00
|
|
|
|
2020-04-29 17:15:54 +00:00
|
|
|
}
|