FEATURE #1449: assign widget to some widget area
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user