FEATURE: change directory structure

This commit is contained in:
Michal Kváček
2016-10-17 00:07:21 +02:00
parent 87f1920373
commit 2ded2924a1
242 changed files with 742 additions and 1171 deletions
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace App\Models\Widgets;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Event;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
/**
* Class Widget
*/
class Widget extends Model
{
public $timestamps = true;
protected $fillable = [
'widget_type_handler',
'user_id',
'name',
'settings',
'language',
'description',
'viewed',
'deletable'
];
protected $guarded = [];
/**
* Create new widget of given type
*
* @param WidgetType $widgetType
* @param $data
*
* @return Widget
*/
public function createNew(WidgetType $widgetType, $data)
{
// convert array or whatever into object
if (!is_object($data)) {
$data = (object)$data;
}
// create new widget
$widget = new Widget();
$widget->widget_type_handler = $widgetType->handler;
$widget->language = LaravelLocalization::getCurrentLocale();
$widget->user_id = \Auth::user()->id;
$widget->name = $data->name;
$widget->container_class = $data->containerClass;
$widget->container_id = empty($data->containerId) ? null : $data->containerId;
// save description if available
if (isset($data->description)) {
$widget->description = $data->description;
}
$widget = call_user_func([$widgetType->handler, 'save'], $widget, $data);
// save into database
$widget->save();
// fire event with newly created widget
Event::fire(new \App\Events\CreateNewWidget($widget));
return $widget;
}
}