-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added beheer front-end to manage intro packages.
# Conflicts: # app/Repositories/IntroPackageRepository.php # package-lock.json # package.json # resources/lang/nl/menu.php # routes/web.php # webpack.mix.js
- Loading branch information
1 parent
e06ccfe
commit 574b4e6
Showing
16 changed files
with
614 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\IntroPackage; | ||
use App\repositories\RepositorieFactory; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Support\Facades\Session; | ||
use Illuminate\Validation\ValidationException as ValidationExceptionAlias; | ||
|
||
class IntroPackageController extends Controller | ||
{ | ||
private $_introPackageRepository; | ||
private $_applicationFormRepository; | ||
|
||
|
||
/** | ||
* IntroPackageController constructor. | ||
*/ | ||
public function __construct(RepositorieFactory $repositoryFactory) | ||
{ | ||
$this->_introPackageRepository = $repositoryFactory->getRepositorie(RepositorieFactory::$INTROPACKAGEREPOKEY); | ||
$this->_applicationFormRepository = $repositoryFactory->getRepositorie(RepositorieFactory::$APPLICATIONFORMREPOKEY); | ||
|
||
$this->middleware('auth'); | ||
$this->middleware('authorize:' | ||
. \Config::get('constants.Content_administrator') .',' | ||
. \Config::get('constants.Activity_administrator') | ||
); | ||
} | ||
|
||
/** | ||
* Validate request input | ||
* | ||
* @param Request $request | ||
* @throws ValidationExceptionAlias | ||
*/ | ||
private function validateInput(Request $request){ | ||
$this->validate($request, [ | ||
'NL_text' => 'required', | ||
'EN_text' => 'required', | ||
'deadline' => 'required|date', | ||
'application_form_id' => 'required|integer', | ||
]); | ||
} | ||
|
||
/** | ||
* Display a listing of intro packages. | ||
* | ||
* @return Response | ||
*/ | ||
public function index() | ||
{ | ||
$packages = $this->_introPackageRepository->all(); | ||
|
||
return view('beheer.intro.packages.index', [ | ||
'packages' => $packages, | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new intro package. | ||
* | ||
* @return Response | ||
*/ | ||
public function create() | ||
{ | ||
$applicationForms = $this->_applicationFormRepository->all(array("name","id")); | ||
|
||
return view('beheer.intro.packages.create_edit', [ | ||
'package' => null, | ||
'applicationForms' => $applicationForms, | ||
]); | ||
} | ||
|
||
/** | ||
* Store a newly created intro package in storage. | ||
* | ||
* @param Request $request | ||
* @return Response | ||
* @throws ValidationExceptionAlias | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$this->validateInput($request); | ||
$this->_introPackageRepository->create($request->all()); | ||
|
||
Session::flash("message", trans('intro.packageAdded')); | ||
|
||
return redirect()->route('beheer.intro.packages.index'); | ||
} | ||
|
||
/** | ||
* Display the specified intro package. | ||
* | ||
* @param IntroPackage $package | ||
* @return Response | ||
*/ | ||
public function show(IntroPackage $package) | ||
{ | ||
return view('beheer.intro.packages.show', [ | ||
'package' => $package, | ||
]); | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified intro package. | ||
* | ||
* @param IntroPackage $package | ||
* @return Response | ||
*/ | ||
public function edit(IntroPackage $package) | ||
{ | ||
$applicationForms = $this->_applicationFormRepository->all(array("name","id")); | ||
|
||
return view('beheer.intro.packages.create_edit', [ | ||
'package' => $package, | ||
'applicationForms' => $applicationForms, | ||
]); | ||
} | ||
|
||
/** | ||
* Update the specified intro package in storage. | ||
* | ||
* @param Request $request | ||
* @param IntroPackage $package | ||
* @return Response | ||
* @throws ValidationExceptionAlias | ||
*/ | ||
public function update(Request $request, IntroPackage $package) | ||
{ | ||
$this->validateInput($request); | ||
$this->_introPackageRepository->update($package->id, $request->all()); | ||
|
||
Session::flash("message", trans('intro.packageEdited')); | ||
|
||
return redirect()->route('beheer.intro.packages.index'); | ||
} | ||
|
||
/** | ||
* Remove the specified intro package from storage. | ||
* | ||
* @param IntroPackage $package | ||
* @return Response | ||
*/ | ||
public function destroy(IntroPackage $package) | ||
{ | ||
$this->_introPackageRepository->delete($package->id); | ||
|
||
Session::flash("message", trans('intro.packageDeleted')); | ||
|
||
return redirect()->route('beheer.intro.packages.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class IntroPackage extends Model | ||
{ | ||
protected $casts = [ | ||
'deadline' => 'date', | ||
]; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'deadline', | ||
'application_form_id', | ||
]; | ||
|
||
public function packageName() | ||
{ | ||
return $this->hasOne(Text::class, 'id', 'name'); | ||
} | ||
|
||
public function applicationForm() | ||
{ | ||
return $this->belongsTo(ApplicationForm::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\repositories; | ||
|
||
|
||
use App\IntroPackage; | ||
use Carbon\Carbon; | ||
|
||
class IntroPackageRepository implements IRepository | ||
{ | ||
private $_textRepository; | ||
|
||
public function __construct(TextRepository $textRepository) | ||
{ | ||
$this->_textRepository = $textRepository; | ||
} | ||
|
||
public function create(array $data) | ||
{ | ||
$text = $this->_textRepository->create($data); | ||
|
||
$data['deadline'] = Carbon::createFromFormat('d-m-Y', $data['deadline']); | ||
|
||
$package = new IntroPackage($data); | ||
$package->name = $text->id; | ||
$package->save(); | ||
|
||
return $package; | ||
} | ||
|
||
public function update($id, array $data) | ||
{ | ||
$package = $this->find($id); | ||
|
||
$data['deadline'] = Carbon::createFromFormat('d-m-Y', $data['deadline']); | ||
|
||
$package->update($data); | ||
$this->_textRepository->update($package->name, $data); | ||
|
||
return $package; | ||
} | ||
|
||
public function delete($id) | ||
{ | ||
$package = $this->find($id); | ||
$package->delete(); | ||
$this->_textRepository->delete($package->name); | ||
|
||
} | ||
|
||
public function find($id, $columns = array('*')) | ||
{ | ||
return $this->findBy('id', $id, $columns)->first(); | ||
} | ||
|
||
public function findBy($field, $value, $columns = array('*')) | ||
{ | ||
return IntroPackage::where($field, '=', $value)->get($columns); | ||
} | ||
|
||
public function all($columns = array('*')) | ||
{ | ||
return IntroPackage::all($columns); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
database/migrations/2019_11_24_132959_create_intro_packages_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateIntroPackagesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('intro_packages', function (Blueprint $table) { | ||
$table->increments('id'); | ||
|
||
$table->integer('name')->unsigned(); | ||
$table->date('deadline'); | ||
$table->integer('application_form_id')->unsigned(); | ||
|
||
$table->timestamps(); | ||
|
||
$table->foreign('name')->references('id')->on('texts'); | ||
$table->foreign('application_form_id')->references('id')->on('application_forms'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('intro_packages'); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
"packageCreate" => "New introduction package", | ||
"packageName" => "Name", | ||
"packageDeadline" => "Registration deadline", | ||
"packageEdit" => "Edit package", | ||
"packageShow" => "Show package", | ||
"packageForm" => "Registration form", | ||
"packageAdded" => "Introduction package has been created.", | ||
"packageEdited" => "Introduction package has been edited.", | ||
"packageDeleted" => "Introduction package has been removed.", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
"packageCreate" => "Nieuw intro pakket", | ||
"packageName" => "Naam", | ||
"packageDeadline" => "Inschrijf deadline", | ||
"packageEdit" => "Pakket aanpassen", | ||
"packageShow" => "Pakket weergeven", | ||
"packageForm" => "Inchrijfformulier", | ||
"packageAdded" => "Intro pakket is aangemaakt.", | ||
"packageEdited" => "Intro pakket is aangepast.", | ||
"packageDeleted" => "Intro pakket is verwijderd.", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.