FEATURE: add functionality for rendering widgets via shortcode [widget]
This commit is contained in:
@@ -19,6 +19,7 @@ class Widget extends Model
|
||||
'settings',
|
||||
'language',
|
||||
'description',
|
||||
'viewed',
|
||||
'deletable'
|
||||
];
|
||||
protected $guarded = [];
|
||||
|
||||
+14
-10
@@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
/**
|
||||
@@ -11,7 +10,7 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
*/
|
||||
class WidgetArea extends Model
|
||||
{
|
||||
public $timestamps = true;
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
@@ -20,14 +19,19 @@ class WidgetArea extends Model
|
||||
];
|
||||
protected $guarded = [];
|
||||
|
||||
public function getWidgets($uniqueCode)
|
||||
public function getWidgets($uniqueCode = false)
|
||||
{
|
||||
return DB::table('widget_areas')
|
||||
->select('widget_areas.*', 'widgets.widget_type_handler', 'widgets.name as widget_name', 'widgets.settings')
|
||||
->where('code', $uniqueCode)
|
||||
->join('widget_in_widget_area', 'widget_in_widget_area.widget_area_id', '=', 'widget_areas.id')
|
||||
->join('widgets', 'widget_in_widget_area.widget_id', '=', 'widgets.id')
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->orderBy('widget_in_widget_area.position');
|
||||
$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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user