Skip to content

Commit

Permalink
Added beheer front-end to manage intro packages.
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/Repositories/IntroPackageRepository.php
#	package-lock.json
#	package.json
#	resources/lang/nl/menu.php
#	routes/web.php
#	webpack.mix.js
  • Loading branch information
marijnvanderhorst committed Jun 3, 2022
1 parent e06ccfe commit 574b4e6
Show file tree
Hide file tree
Showing 16 changed files with 614 additions and 2 deletions.
155 changes: 155 additions & 0 deletions app/Http/Controllers/IntroPackageController.php
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');
}
}
28 changes: 28 additions & 0 deletions app/IntroPackage.php
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);
}
}
65 changes: 65 additions & 0 deletions app/Repositories/IntroPackageRepository.php
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);
}
}
2 changes: 2 additions & 0 deletions app/Repositories/RepositorieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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),
];
}

Expand Down
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');
}
}
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions resources/lang/en/intro.php
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.",
];
13 changes: 13 additions & 0 deletions resources/lang/nl/intro.php
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.",
];
2 changes: 2 additions & 0 deletions resources/lang/nl/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@
"become_member" => "Word lid",
"activities" => "Activiteiten",
"content" => "Content",
"intro" => "Intro",
"introPackages" => "Intro pakketten",
];
Loading

0 comments on commit 574b4e6

Please sign in to comment.