FEATURE #1449: assign widget to some widget area

This commit is contained in:
Michal Kváček
2016-02-15 12:26:12 +01:00
parent 1d553d1a15
commit e8f994ff5f
2 changed files with 138 additions and 0 deletions
@@ -0,0 +1,59 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Models\Widget;
use App\Models\WidgetArea;
use App\Models\WidgetInWidgetArea;
use Illuminate\Database\QueryException;
class AssociateWidget extends Controller
{
public function getList($widgetArea)
{
$area = WidgetArea::findOrFail($widgetArea);
$associatedWidgetIds = WidgetInWidgetArea::getWidgetIdsFromArea($area->id);
$widgets = Widget::paginate(25);
return view('admin.widgets.association', [
'widgetArea' => $area,
'widgets' => $widgets,
'associatedWidgetIds' => $associatedWidgetIds
]);
}
public function makeAssociation($widgetId, $widgetAreaId)
{
try {
WidgetInWidgetArea::create(['widget_id' => $widgetId, 'widget_area_id' => $widgetAreaId]);
} catch (QueryException $e) {
return redirect()
->route('widgets.associate', ['widgetArea' => $widgetAreaId])
->with('error', trans('admin/widgets.associationExists'));
}
return redirect()
->route('widgets.associate', ['widgetArea' => $widgetAreaId])
->with('success', trans('admin/widgets.successfullyAssociated'));
}
public function deleteAssociation($widgetId, $widgetAreaId)
{
$widgetInArea = WidgetInWidgetArea::where('widget_id', $widgetId)
->where('widget_area_id', $widgetAreaId);
if ($widgetInArea->count() == 0) {
return redirect()
->route('widgets.associate', ['widgetArea' => $widgetAreaId])
->with('error', trans('admin/widgets.associationDoesNotExists'));
}
$widgetInArea->delete();
return redirect()
->route('widgets.associate', ['widgetArea' => $widgetAreaId])
->with('success', trans('admin/widgets.successfullyDeassociated'));
}
}