2018-01-29 03:19:35 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Requests\CreateAwardRequest;
|
|
|
|
use App\Http\Requests\UpdateAwardRequest;
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Controller;
|
2018-01-29 03:19:35 +08:00
|
|
|
use App\Repositories\AwardRepository;
|
2018-03-18 01:17:38 +08:00
|
|
|
use App\Services\AwardService;
|
2018-01-29 03:19:35 +08:00
|
|
|
use Flash;
|
2018-03-20 09:50:40 +08:00
|
|
|
use Illuminate\Http\Request;
|
2018-01-29 03:19:35 +08:00
|
|
|
use Prettus\Repository\Criteria\RequestCriteria;
|
|
|
|
use Response;
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
class AwardController extends Controller
|
2018-01-29 03:19:35 +08:00
|
|
|
{
|
|
|
|
/** @var AwardRepository */
|
2018-03-18 01:17:38 +08:00
|
|
|
private $awardRepository,
|
2018-03-20 09:50:40 +08:00
|
|
|
$awardSvc;
|
2018-01-29 03:19:35 +08:00
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
/**
|
|
|
|
* AwardController constructor.
|
|
|
|
* @param AwardRepository $awardRepo
|
|
|
|
* @param AwardService $awardSvc
|
|
|
|
*/
|
2018-03-18 01:17:38 +08:00
|
|
|
public function __construct(
|
|
|
|
AwardRepository $awardRepo,
|
|
|
|
AwardService $awardSvc
|
|
|
|
)
|
2018-01-29 03:19:35 +08:00
|
|
|
{
|
|
|
|
$this->awardRepository = $awardRepo;
|
2018-03-18 01:17:38 +08:00
|
|
|
$this->awardSvc = $awardSvc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getAwardClassesAndDescriptions(): array
|
|
|
|
{
|
|
|
|
$awards = [
|
|
|
|
'' => '',
|
|
|
|
];
|
|
|
|
|
|
|
|
$descriptions = [];
|
|
|
|
|
|
|
|
$award_classes = $this->awardSvc->findAllAwardClasses();
|
2018-03-20 09:50:40 +08:00
|
|
|
foreach ($award_classes as $class_ref => $award) {
|
2018-03-18 01:17:38 +08:00
|
|
|
$awards[$class_ref] = $award->name;
|
|
|
|
$descriptions[$class_ref] = $award->param_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2018-03-20 09:50:40 +08:00
|
|
|
'awards' => $awards,
|
2018-03-18 01:17:38 +08:00
|
|
|
'descriptions' => $descriptions,
|
|
|
|
];
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the Fare.
|
|
|
|
* @param Request $request
|
|
|
|
* @return Response
|
2018-03-18 00:39:51 +08:00
|
|
|
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
2018-01-29 03:19:35 +08:00
|
|
|
*/
|
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$this->awardRepository->pushCriteria(new RequestCriteria($request));
|
|
|
|
$awards = $this->awardRepository->all();
|
|
|
|
|
2018-03-18 00:39:51 +08:00
|
|
|
return view('admin.awards.index', [
|
|
|
|
'awards' => $awards,
|
|
|
|
]);
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new Fare.
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2018-03-18 01:17:38 +08:00
|
|
|
$class_refs = $this->getAwardClassesAndDescriptions();
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-03-18 01:17:38 +08:00
|
|
|
return view('admin.awards.create', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'award_classes' => $class_refs['awards'],
|
2018-03-18 01:17:38 +08:00
|
|
|
'award_descriptions' => $class_refs['descriptions'],
|
|
|
|
]);
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created Fare in storage.
|
2018-03-18 00:39:51 +08:00
|
|
|
* @param CreateAwardRequest $request
|
2018-01-29 03:19:35 +08:00
|
|
|
* @return Response
|
2018-03-18 00:39:51 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2018-01-29 03:19:35 +08:00
|
|
|
*/
|
|
|
|
public function store(CreateAwardRequest $request)
|
|
|
|
{
|
|
|
|
$input = $request->all();
|
|
|
|
$award = $this->awardRepository->create($input);
|
|
|
|
Flash::success('Award saved successfully.');
|
|
|
|
|
|
|
|
return redirect(route('admin.awards.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified Fare.
|
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2018-03-18 00:39:51 +08:00
|
|
|
$award = $this->awardRepository->findWithoutFail($id);
|
2018-01-29 03:19:35 +08:00
|
|
|
if (empty($award)) {
|
|
|
|
Flash::error('Award not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-29 03:19:35 +08:00
|
|
|
return redirect(route('admin.awards.index'));
|
|
|
|
}
|
|
|
|
|
2018-03-18 00:39:51 +08:00
|
|
|
return view('admin.awards.show', [
|
|
|
|
'award' => $award,
|
|
|
|
]);
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-18 00:39:51 +08:00
|
|
|
* Show the form for editing the specified award.
|
2018-01-29 03:19:35 +08:00
|
|
|
* @param int $id
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$award = $this->awardRepository->findWithoutFail($id);
|
|
|
|
if (empty($award)) {
|
|
|
|
Flash::error('Award not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-29 03:19:35 +08:00
|
|
|
return redirect(route('admin.awards.index'));
|
|
|
|
}
|
|
|
|
|
2018-03-18 01:17:38 +08:00
|
|
|
$class_refs = $this->getAwardClassesAndDescriptions();
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-03-18 00:39:51 +08:00
|
|
|
return view('admin.awards.edit', [
|
2018-03-20 09:50:40 +08:00
|
|
|
'award' => $award,
|
|
|
|
'award_classes' => $class_refs['awards'],
|
2018-03-18 01:17:38 +08:00
|
|
|
'award_descriptions' => $class_refs['descriptions'],
|
2018-03-18 00:39:51 +08:00
|
|
|
]);
|
2018-01-29 03:19:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-03-18 00:39:51 +08:00
|
|
|
* Update the specified award in storage.
|
2018-03-20 09:50:40 +08:00
|
|
|
* @param int $id
|
2018-03-18 00:39:51 +08:00
|
|
|
* @param UpdateAwardRequest $request
|
2018-01-29 03:19:35 +08:00
|
|
|
* @return Response
|
2018-03-18 00:39:51 +08:00
|
|
|
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
2018-01-29 03:19:35 +08:00
|
|
|
*/
|
|
|
|
public function update($id, UpdateAwardRequest $request)
|
|
|
|
{
|
|
|
|
$award = $this->awardRepository->findWithoutFail($id);
|
|
|
|
if (empty($award)) {
|
|
|
|
Flash::error('Award not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-29 03:19:35 +08:00
|
|
|
return redirect(route('admin.awards.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$award = $this->awardRepository->update($request->all(), $id);
|
|
|
|
Flash::success('Award updated successfully.');
|
|
|
|
|
|
|
|
return redirect(route('admin.awards.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified Fare from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$award = $this->awardRepository->findWithoutFail($id);
|
|
|
|
if (empty($award)) {
|
|
|
|
Flash::error('Fare not found');
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-01-29 03:19:35 +08:00
|
|
|
return redirect(route('admin.awards.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->awardRepository->delete($id);
|
|
|
|
Flash::success('Fare deleted successfully.');
|
|
|
|
|
|
|
|
return redirect(route('admin.awards.index'));
|
|
|
|
}
|
|
|
|
}
|