FEATURE #1522: add orbit slider
Had to change some things in global widgets management and also in html code widget. Sorry for this ugly commit..
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
namespace App\Widgets\OrbitSlider;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Directory;
|
||||
use App\Models\Widget;
|
||||
use App\Widgets\Contracts\PublicWidget;
|
||||
use App\Widgets\Contracts\WidgetRenderer;
|
||||
use App\Widgets\Exceptions\WidgetExistsException;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class OrbitSlider implements PublicWidget
|
||||
{
|
||||
const DIRECTORY_NAME = 'orbit-slider-data';
|
||||
const CONFIG_FILENAME = 'orbit-slider-directory-id';
|
||||
|
||||
/**
|
||||
* Name getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getName()
|
||||
{
|
||||
return 'widgets/orbitSlider.widgetName';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for description
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getDescription()
|
||||
{
|
||||
return 'widgets/orbitSlider.widgetDescription';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Widget $widget
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws WidgetExistsException
|
||||
*
|
||||
* @return Widget
|
||||
*/
|
||||
public static function save(Widget $widget, Request $request)
|
||||
{
|
||||
$settings = json_decode($widget->settings);
|
||||
$parentDirectoryId = Storage::get(self::CONFIG_FILENAME);
|
||||
$directoryId = isset($settings->directoryId) ? $settings->directoryId : null;
|
||||
$edit = false;
|
||||
|
||||
// check if directory does not exists
|
||||
$exists = Directory::where('name', $request->name)
|
||||
->where('parent_id', $parentDirectoryId);
|
||||
|
||||
if ($directoryId) {
|
||||
$edit = true;
|
||||
$exists = $exists->where('id', '!=', $directoryId);
|
||||
}
|
||||
|
||||
$exists = $exists->exists();
|
||||
|
||||
if ($exists) {
|
||||
throw new WidgetExistsException($request->name);
|
||||
}
|
||||
|
||||
$directory = new Directory;
|
||||
|
||||
if ($edit) {
|
||||
$directory = Directory::find($directoryId);
|
||||
}
|
||||
|
||||
// setup some information about directory
|
||||
$directory->user_id = Auth::user()->id;
|
||||
$directory->parent_id = $parentDirectoryId;
|
||||
$directory->name = $request->name;
|
||||
$directory->description = $request->description;
|
||||
$directory->save();
|
||||
|
||||
$settings = [
|
||||
'directoryId' => $directory->id,
|
||||
'sliderClass' => isset($request->containerClass) ? $request->containerClass : '',
|
||||
'code' => $request->code
|
||||
];
|
||||
|
||||
$widget->settings = json_encode($settings);
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for presenter/renderer of this widget
|
||||
*
|
||||
* @return WidgetRenderer
|
||||
*/
|
||||
public static function getPresenter()
|
||||
{
|
||||
return Presenters\OrbitSlider::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for installing given widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
$directory = Directory::where('name', self::DIRECTORY_NAME)
|
||||
->first();
|
||||
|
||||
if (!count($directory)) {
|
||||
$directory = Directory::create([
|
||||
'name' => self::DIRECTORY_NAME,
|
||||
'hidden' => true
|
||||
]);
|
||||
}
|
||||
|
||||
Storage::put(self::CONFIG_FILENAME, $directory->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for uninstalling widget
|
||||
*/
|
||||
public static function uninstall()
|
||||
{
|
||||
// TODO: Implement uninstall() method.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user