Merge branch 'dev' into widget_menu
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace App\Widgets\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class WidgetExistsException extends \Exception
|
||||
{
|
||||
public function __construct($message = "", $code = 0, Exception $previous = null)
|
||||
{
|
||||
$message = trans('admin/widgets.widgetExists', ['id' => $message]);
|
||||
|
||||
parent::__construct($message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ class HtmlCode implements WidgetRenderer
|
||||
*/
|
||||
public static function renderEditForm(Widget $widget)
|
||||
{
|
||||
return view('admin.widgets.htmlCode.edit', ['widget' => $widget]);
|
||||
$settings = json_decode($widget->settings);
|
||||
return view('admin.widgets.htmlCode.edit', ['widget' => $widget, 'settings' => $settings]);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace App\Widgets\OrbitSlider\Presenters;
|
||||
|
||||
use App\Models\File;
|
||||
use App\Models\Widget;
|
||||
use App\Models\WidgetType;
|
||||
use App\Widgets\Contracts\WidgetRenderer;
|
||||
|
||||
class OrbitSlider implements WidgetRenderer
|
||||
{
|
||||
/**
|
||||
* Method used for displaying widget.
|
||||
*
|
||||
* This method renders some HTML code for displaying.
|
||||
*
|
||||
* @param object $settings
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function render($settings)
|
||||
{
|
||||
$directoryId = $settings->directoryId;
|
||||
|
||||
$images = File::where('directory_id', $directoryId)
|
||||
->where('mime_type', 'LIKE', 'image%')
|
||||
->get();
|
||||
|
||||
return view('widgets.orbitSlider.element', ['images' => $images, 'settings' => $settings]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for creating new instance of widget
|
||||
*
|
||||
* @param WidgetType $type
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderAddForm(WidgetType $type)
|
||||
{
|
||||
return view('admin.widgets.orbitSlider.new', ['type' => $type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display form for editing already existing widget
|
||||
*
|
||||
* @param Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function renderEditForm(Widget $widget)
|
||||
{
|
||||
$settings = json_decode($widget->settings);
|
||||
|
||||
return view('admin.widgets.orbitSlider.edit', ['widget' => $widget, 'settings' => $settings]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user