diff --git a/app/Http/Controllers/IntroPackageController.php b/app/Http/Controllers/IntroPackageController.php new file mode 100644 index 00000000..0912b2c4 --- /dev/null +++ b/app/Http/Controllers/IntroPackageController.php @@ -0,0 +1,155 @@ +_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'); + } +} diff --git a/app/IntroPackage.php b/app/IntroPackage.php new file mode 100644 index 00000000..829576d4 --- /dev/null +++ b/app/IntroPackage.php @@ -0,0 +1,28 @@ + '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); + } +} diff --git a/app/Repositories/IntroPackageRepository.php b/app/Repositories/IntroPackageRepository.php new file mode 100644 index 00000000..90ccf8e2 --- /dev/null +++ b/app/Repositories/IntroPackageRepository.php @@ -0,0 +1,65 @@ +_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); + } +} diff --git a/app/Repositories/RepositorieFactory.php b/app/Repositories/RepositorieFactory.php index ab7b3f8c..c81088a0 100644 --- a/app/Repositories/RepositorieFactory.php +++ b/app/Repositories/RepositorieFactory.php @@ -27,6 +27,7 @@ class RepositorieFactory{ public static $BOOKREPOKEY = "BookRepository"; public static $PHOTOALBUMREPOKEY = "PhotoAlbum"; public static $PHOTOREPOKEY = "Photo"; + public static $INTROPACKAGEREPOKEY = "IntroPackage"; public function __construct() { @@ -45,6 +46,7 @@ public function __construct() { RepositorieFactory::$BOOKREPOKEY => new BookRepository($textRepository), RepositorieFactory::$PHOTOALBUMREPOKEY => new PhotoAlbumRepository(), RepositorieFactory::$PHOTOREPOKEY => new PhotoRepository(), + RepositorieFactory::$INTROPACKAGEREPOKEY => new IntroPackageRepository($textRepository), ]; } diff --git a/database/migrations/2019_11_24_132959_create_intro_packages_table.php b/database/migrations/2019_11_24_132959_create_intro_packages_table.php new file mode 100644 index 00000000..f2f7e37c --- /dev/null +++ b/database/migrations/2019_11_24_132959_create_intro_packages_table.php @@ -0,0 +1,39 @@ +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'); + } +} diff --git a/package-lock.json b/package-lock.json index b7e8b532..44866337 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "axios": "^0.27.2", "blueimp-load-image": "5.16.0", "bootstrap": "^4.4.1", + "bootstrap-select": "^1.13.12", "browser-sync": "^2.27.10", "browser-sync-webpack-plugin": "^2.3.0", "datatables.net": "^1.12.1", @@ -2976,6 +2977,16 @@ "popper.js": "^1.16.1" } }, + "node_modules/bootstrap-select": { + "version": "1.13.18", + "resolved": "https://registry.npmjs.org/bootstrap-select/-/bootstrap-select-1.13.18.tgz", + "integrity": "sha512-V1IzK4rxBq5FrJtkzSH6RmFLFBsjx50byFbfAf8jYyXROWs7ZpprGjdHeoyq2HSsHyjJhMMwjsQhRoYAfxCGow==", + "dev": true, + "peerDependencies": { + "bootstrap": ">=3.0.0", + "jquery": "1.9.1 - 3" + } + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -12841,6 +12852,13 @@ "dev": true, "requires": {} }, + "bootstrap-select": { + "version": "1.13.18", + "resolved": "https://registry.npmjs.org/bootstrap-select/-/bootstrap-select-1.13.18.tgz", + "integrity": "sha512-V1IzK4rxBq5FrJtkzSH6RmFLFBsjx50byFbfAf8jYyXROWs7ZpprGjdHeoyq2HSsHyjJhMMwjsQhRoYAfxCGow==", + "dev": true, + "requires": {} + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", diff --git a/package.json b/package.json index 80990fcd..dc48f1f5 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "axios": "^0.27.2", "blueimp-load-image": "5.16.0", "bootstrap": "^4.4.1", + "bootstrap-select": "^1.13.12", "browser-sync": "^2.27.10", "browser-sync-webpack-plugin": "^2.3.0", "datatables.net": "^1.12.1", diff --git a/resources/lang/en/intro.php b/resources/lang/en/intro.php new file mode 100644 index 00000000..a5e7f30b --- /dev/null +++ b/resources/lang/en/intro.php @@ -0,0 +1,13 @@ + "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.", +]; diff --git a/resources/lang/nl/intro.php b/resources/lang/nl/intro.php new file mode 100644 index 00000000..dac483bc --- /dev/null +++ b/resources/lang/nl/intro.php @@ -0,0 +1,13 @@ + "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.", +]; diff --git a/resources/lang/nl/menu.php b/resources/lang/nl/menu.php index fe28e73d..61d308b6 100644 --- a/resources/lang/nl/menu.php +++ b/resources/lang/nl/menu.php @@ -38,4 +38,6 @@ "become_member" => "Word lid", "activities" => "Activiteiten", "content" => "Content", + "intro" => "Intro", + "introPackages" => "Intro pakketten", ]; diff --git a/resources/views/beheer/intro/packages/create_edit.blade.php b/resources/views/beheer/intro/packages/create_edit.blade.php new file mode 100644 index 00000000..d07a1023 --- /dev/null +++ b/resources/views/beheer/intro/packages/create_edit.blade.php @@ -0,0 +1,111 @@ +@extends('layouts.beheer') + +@push('styles') + + +@endpush + +@php +$create = $package == null; +@endphp + +@section('title') +{{ $create ? trans('intro.packageCreate') : trans('intro.packageEdit') }} +@endsection + +@section('content') + @if(Session::has('message')) + + @endif + @if ($errors->any()) + + @endif + +
+
+

{{ $create ? trans('intro.packageCreate') : trans('intro.packageEdit') }}

+
+
+ {!! Form::open(['method' => $create ? 'POST' : 'PATCH', 'url' => route('beheer.intro.packages.' . ($create ? 'store' : 'update'), $package)]) !!} +
+
+ {!! Form::label('NL_text', trans('intro.packageName') . ' NL') !!} + {!! Form::text('NL_text', $create ? '' : $package->packageName->NL_text, ['class' => 'form-control','required' => 'required']) !!} +
+
+ {!! Form::label('EN_text', trans('intro.packageName') . ' EN') !!} + {!! Form::text('EN_text', $create ? '' : $package->packageName->EN_text, ['class' => 'form-control','required' => 'required']) !!} +
+
+
+
+ {!! Form::label('startDate', trans('intro.packageDeadline')) !!} +
+ +
+
+
+
+
+
+ {!! Form::label('startDate', trans('intro.packageForm')) !!} +
+ +
+
+
+
+
+ +
+ {!! Form::submit(trans('menu.save'), ['class'=> 'btn btn-primary'] ) !!} + {!! Form::close() !!} + {{trans('menu.cancel')}} +
+@endsection + +@push('scripts') + + + + + +@endpush diff --git a/resources/views/beheer/intro/packages/index.blade.php b/resources/views/beheer/intro/packages/index.blade.php new file mode 100644 index 00000000..ffc4e9f7 --- /dev/null +++ b/resources/views/beheer/intro/packages/index.blade.php @@ -0,0 +1,66 @@ +@extends('layouts.beheer') + +@section('title') +{{ trans("menu.introPackages") }} +@endsection + +@section('content') + @if(Session::has('message')) + + @endif + +
+
+

{{ trans("menu.introPackages") }}

+
+ +
+ +
+
+ + + + + + + + + + + @foreach ($packages as $package) + + + + + + @endforeach + +
+ {{trans('intro.packageName')}} + + {{trans('intro.packageDeadline')}} + + {{trans('menu.action')}} +
{{ $package->packageName->text() }}{{ $package->deadline->format('d-m-Y') }} + + +
+@endsection + +@push('scripts') + + +@endpush diff --git a/resources/views/beheer/intro/packages/show.blade.php b/resources/views/beheer/intro/packages/show.blade.php new file mode 100644 index 00000000..e34e73bf --- /dev/null +++ b/resources/views/beheer/intro/packages/show.blade.php @@ -0,0 +1,82 @@ +@extends('layouts.beheer') + +@section('title') +{{ trans("menu.introPackages") }} +@endsection + +@section('content') + @if(Session::has('message')) + + @endif + +
+
+

{{trans("menu.introPackages")}}

+
+ +
+
+ + {{trans("menu.edit")}} + + + {{trans("menu.back")}} + + {{ Form::open(array('url' => route('beheer.intro.packages.destroy', $package), 'method' => 'delete')) }} + + {{ Form::close() }} +
+
+
+
+
+

{{ trans("menu.introPackages") }}

+
+
+
+
+ @lang('intro.packageName') NL +
+
+ @lang('intro.packageName') EN +
+
+
+
+ {{ $package->packageName->NL_text }} +
+
+ {{ $package->packageName->EN_text }} +
+
+
+
+ @lang('intro.packageDeadline') +
+
+ @lang('intro.packageForm') +
+
+
+
+ {{ $package->deadline->format('d-m-Y') }} +
+
+ {{ $package->applicationForm->applicationFormName->text() }} +
+
+
+
+ +@endsection + +@push('scripts') + + +@endpush diff --git a/resources/views/layouts/beheer.blade.php b/resources/views/layouts/beheer.blade.php index b1506918..95e01aaa 100644 --- a/resources/views/layouts/beheer.blade.php +++ b/resources/views/layouts/beheer.blade.php @@ -84,6 +84,16 @@ @endif + @if(\Illuminate\Support\Facades\Auth::user()->hasRole(Config::get('constants.Content_administrator'),Config::get('constants.Activity_administrator'))) + + @endif @if(\Illuminate\Support\Facades\Auth::user()->hasRole(Config::get('constants.Content_administrator')))