Add ability to edit Vacancies
This commit is contained in:
@@ -15,15 +15,12 @@ class HomeController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// TODO: Relationships for Applications, Users and Responses
|
||||
// Also prevent apps if user already has one in the space of 30d
|
||||
// Display apps in the relevant menus
|
||||
|
||||
$positions = DB::table('vacancies')
|
||||
->where('vacancyStatus', 'OPEN')
|
||||
->where('vacancyCount', '!=', 0)
|
||||
->get();
|
||||
|
||||
$positions = Vacancy::where('vacancyStatus', 'OPEN')
|
||||
->where('vacancyCount', '<>', 0)
|
||||
->get();
|
||||
|
||||
|
||||
return view('home')
|
||||
->with('positions', $positions);
|
||||
}
|
||||
|
@@ -3,12 +3,13 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\VacancyRequest;
|
||||
use App\Http\Requests\VacancyEditRequest;
|
||||
|
||||
use App\Vacancy;
|
||||
use App\User;
|
||||
use App\Form;
|
||||
|
||||
use App\Notifications\VacancyClosed;
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -34,11 +35,16 @@ class VacancyController extends Controller
|
||||
|
||||
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.
|
||||
*/
|
||||
Vacancy::create([
|
||||
|
||||
'vacancyName' => $request->vacancyName,
|
||||
'vacancyDescription' => $request->vacancyDescription,
|
||||
'vacancyFullDescription' => Markdown::convertToHTML($request->vacancyFullDescription),
|
||||
'vacancyFullDescription' => $request->vacancyFullDescription,
|
||||
'vacancySlug' => Str::slug($request->vacancyName),
|
||||
'permissionGroupName' => $request->permissionGroup,
|
||||
'discordRoleID' => $request->discordRole,
|
||||
@@ -105,4 +111,27 @@ class VacancyController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
public function edit(Request $request, Vacancy $position)
|
||||
{
|
||||
return view('dashboard.administration.editposition')
|
||||
->with('vacancy', $position);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function update(VacancyEditRequest $request, Vacancy $position)
|
||||
{
|
||||
|
||||
$position->vacancyFullDescription = $request->vacancyFullDescription;
|
||||
$position->vacancyDescription = $request->vacancyDescription;
|
||||
$position->vacancyCount = $request->vacancyCount;
|
||||
|
||||
$position->save();
|
||||
|
||||
$request->session()->flash('success', 'Vacancy successfully updated.');
|
||||
return redirect()->back();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
34
app/Http/Requests/VacancyEditRequest.php
Normal file
34
app/Http/Requests/VacancyEditRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
class VacancyEditRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::user()->can('admin.hiring.vacancy.edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'vacancyDescription' => 'required|string',
|
||||
'vacancyFullDescription' => 'nullable|string',
|
||||
'vacancyCount' => 'required|integer|min:1'
|
||||
];
|
||||
}
|
||||
}
|
@@ -6,12 +6,13 @@ use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
use App\Vacancy;
|
||||
|
||||
class VacancyClosed extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
use Queueable, SerializesModels;
|
||||
|
||||
protected $vacancy;
|
||||
|
||||
|
64
app/Observers/VacancyObserver.php
Normal file
64
app/Observers/VacancyObserver.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Vacancy;
|
||||
|
||||
|
||||
class VacancyObserver
|
||||
{
|
||||
/**
|
||||
* Handle the vacancy "created" event.
|
||||
*
|
||||
* @param \App\Vacancy $vacancy
|
||||
* @return void
|
||||
*/
|
||||
public function created(Vacancy $vacancy)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vacancy "updated" event.
|
||||
*
|
||||
* @param \App\Vacancy $vacancy
|
||||
* @return void
|
||||
*/
|
||||
public function updated(Vacancy $vacancy)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vacancy "deleted" event.
|
||||
*
|
||||
* @param \App\Vacancy $vacancy
|
||||
* @return void
|
||||
*/
|
||||
public function deleted(Vacancy $vacancy)
|
||||
{
|
||||
// TODO: Handle deletion of children's data
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vacancy "restored" event.
|
||||
*
|
||||
* @param \App\Vacancy $vacancy
|
||||
* @return void
|
||||
*/
|
||||
public function restored(Vacancy $vacancy)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the vacancy "force deleted" event.
|
||||
*
|
||||
* @param \App\Vacancy $vacancy
|
||||
* @return void
|
||||
*/
|
||||
public function forceDeleted(Vacancy $vacancy)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@@ -53,7 +53,7 @@ class VacancyPolicy
|
||||
*/
|
||||
public function update(User $user, Vacancy $vacancy)
|
||||
{
|
||||
return $user->hasRole('admin', 'hiringManager');
|
||||
return $user->hasAnyRole('admin', 'hiringManager');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -6,6 +6,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use GrahamCampbell\Markdown\Facades\Markdown;
|
||||
|
||||
|
||||
class Vacancy extends Model
|
||||
{
|
||||
public $fillable = [
|
||||
@@ -22,6 +25,26 @@ class Vacancy extends Model
|
||||
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Get the HTML variant of the vacancyFullDescription attribute.
|
||||
*
|
||||
* @param string $value The original value
|
||||
* @return string
|
||||
*/
|
||||
public function getVacancyFullDescriptionAttribute($value)
|
||||
{
|
||||
if (!is_null($value))
|
||||
{
|
||||
return Markdown::convertToHTML($value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function forms()
|
||||
{
|
||||
return $this->belongsTo('App\Form', 'vacancyFormID', 'id');
|
||||
|
Reference in New Issue
Block a user