24 lines
1.0 KiB
PHP
24 lines
1.0 KiB
PHP
<?php
|
|
namespace App\Models\Widgets\ModelTraits;
|
|
|
|
use App\Models\Widgets\Widget;
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
|
|
trait 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;
|
|
}
|
|
} |