Major changes - Vote system now finished
This commit is contained in:
@@ -13,6 +13,22 @@ use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class ApplicationController extends Controller
|
||||
{
|
||||
private function canVote($votes)
|
||||
{
|
||||
$allvotes = collect([]);
|
||||
|
||||
foreach ($votes as $vote)
|
||||
{
|
||||
if ($vote->userID == Auth::user()->id)
|
||||
{
|
||||
Log::debug('Match');
|
||||
$allvotes->push($vote);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $allvotes->count() == 1;
|
||||
}
|
||||
|
||||
public function showUserApps()
|
||||
{
|
||||
@@ -33,7 +49,8 @@ class ApplicationController extends Controller
|
||||
'application' => $application,
|
||||
'structuredResponses' => json_decode($application->response->responseData, true),
|
||||
'formStructure' => $application->response->form,
|
||||
'vacancy' => $application->response->vacancy
|
||||
'vacancy' => $application->response->vacancy,
|
||||
'canVote' => $this->canVote($application->votes)
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -96,6 +113,7 @@ class ApplicationController extends Controller
|
||||
{
|
||||
return view('dashboard.appmanagement.peerreview')
|
||||
->with('applications', Application::where('applicationStatus', 'STAGE_PEERAPPROVAL')->get());
|
||||
|
||||
}
|
||||
|
||||
public function renderApplicationForm(Request $request, $vacancySlug)
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Application;
|
||||
use App\Http\Requests\SaveNotesRequest;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Appointment;
|
||||
@@ -84,5 +85,24 @@ class AppointmentController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
// also updates
|
||||
public function saveNotes(SaveNotesRequest $request, $applicationID)
|
||||
{
|
||||
$application = Application::find($applicationID);
|
||||
|
||||
if (!is_null($application))
|
||||
{
|
||||
$application->appointment->meetingNotes = $request->noteText;
|
||||
$application->appointment->save();
|
||||
|
||||
$request->session()->flash('success', 'Meeting notes have been saved.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$request->session()->flash('error', 'Sanity check failed: There\'s no appointment to save notes to!');
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
}
|
||||
|
34
app/Http/Controllers/DevToolsController.php
Normal file
34
app/Http/Controllers/DevToolsController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Application;
|
||||
use App\Events\ApplicationApprovedEvent;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DevToolsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return view('dashboard.administration.devtools')
|
||||
->with('applications', Application::where('applicationStatus', 'STAGE_PEERAPPROVAL')->get());
|
||||
}
|
||||
|
||||
public function forceVoteCount(Request $request)
|
||||
{
|
||||
$application = Application::find($request->application);
|
||||
|
||||
if (!is_null($application))
|
||||
{
|
||||
event(new ApplicationApprovedEvent($application));
|
||||
|
||||
$request->session()->flash('success', 'Event dispatched! Please check the debug logs for more info');
|
||||
}
|
||||
else
|
||||
{
|
||||
$request->session()->flash('error', 'Application doesn\'t exist!');
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
@@ -2,9 +2,43 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Application;
|
||||
use App\Http\Requests\VoteRequest;
|
||||
use App\Jobs\ProcessVoteList;
|
||||
use App\Vote;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class VoteController extends Controller
|
||||
{
|
||||
//
|
||||
|
||||
public function vote(VoteRequest $voteRequest, $applicationID)
|
||||
{
|
||||
$application = Application::find($applicationID);
|
||||
|
||||
if (!is_null($application))
|
||||
{
|
||||
$vote = Vote::create([
|
||||
'userID' => Auth::user()->id,
|
||||
'allowedVoteType' => $voteRequest->voteType,
|
||||
]);
|
||||
|
||||
$vote->application()->attach($applicationID);
|
||||
|
||||
Log::info('User ' . Auth::user()->name . ' has voted in applicant ' . $application->user->name . '\'s application', [
|
||||
'voteType' => $voteRequest->voteType
|
||||
]);
|
||||
|
||||
$voteRequest->session()->flash('success', 'Your vote has been registered! You will now be notified about the outcome of this application.');
|
||||
}
|
||||
else
|
||||
{
|
||||
$voteRequest->session()->flash('error', 'Can\t vote a non existant application!');
|
||||
}
|
||||
|
||||
// Cron job will run command that processes votes
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
30
app/Http/Requests/SaveNotesRequest.php
Normal file
30
app/Http/Requests/SaveNotesRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class SaveNotesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'noteText' => 'required|string'
|
||||
];
|
||||
}
|
||||
}
|
30
app/Http/Requests/VoteRequest.php
Normal file
30
app/Http/Requests/VoteRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class VoteRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'voteType' => 'required|string|in:VOTE_DENY,VOTE_APPROVE'
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user