37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
|
|
/**
|
|
* Class WidgetArea
|
|
*/
|
|
class WidgetArea extends Model
|
|
{
|
|
public $timestamps = false;
|
|
protected $fillable = [
|
|
'name',
|
|
'code',
|
|
'description',
|
|
'deletable'
|
|
];
|
|
protected $guarded = [];
|
|
|
|
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;
|
|
}
|
|
} |