55 lines
2.0 KiB
PHP
55 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\CMS\Repositories\Widgets;
|
|
|
|
use App\Events\CreateNewWidgetArea;
|
|
use App\Http\Requests\Request;
|
|
use App\Models\Widgets\Widget;
|
|
use App\Models\Widgets\WidgetArea as WidgetAreaModel;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
|
|
class WidgetArea
|
|
{
|
|
public function getWidgets($uniqueCode = false)
|
|
{
|
|
$widgets = Widget::select('widgets.*', 'widgets.widget_type_handler', 'widget_areas.code as widget_area_code', 'widgets.name as widget_name', 'widgets.settings')
|
|
->join('widget_in_widget_area', 'widget_in_widget_area.widget_id', '=', 'widgets.id')
|
|
->join('widget_areas', 'widget_in_widget_area.widget_area_id', '=', 'widget_areas.id')
|
|
->where('language', LaravelLocalization::getCurrentLocale())
|
|
->orderBy('widget_in_widget_area.position');
|
|
if (!$uniqueCode) {
|
|
$widgets = $widgets->where('widget_areas.viewed', '>=', setting('preloadFrequentedWidgetAreasTreshold', 10));
|
|
} else {
|
|
$widgets = $widgets->where('code', $uniqueCode);
|
|
}
|
|
|
|
return $widgets;
|
|
}
|
|
|
|
public function update(\App\Models\Widgets\WidgetArea $area, Request $request) {
|
|
$area->name = $request->name;
|
|
$area->description = $request->description;
|
|
$area->save();
|
|
|
|
// fire event with new widget area
|
|
Event::fire(new \App\Events\EditWidgetArea($area));
|
|
}
|
|
|
|
/**
|
|
* Create new instance of widget area
|
|
*
|
|
* @param Request $request
|
|
*/
|
|
public function create(Request $request)
|
|
{
|
|
$area = WidgetAreaModel::create([
|
|
'code' => $request->code,
|
|
'name' => $request->name,
|
|
'description' => $request->description
|
|
]);
|
|
|
|
// fire event with new widget area
|
|
Event::fire(new CreateNewWidgetArea($area));
|
|
}
|
|
} |