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:
@@ -38,9 +38,9 @@ class WidgetRegistrator
|
||||
'name' => $widgetName,
|
||||
'description' => $widgetDescription
|
||||
]);
|
||||
}
|
||||
|
||||
// install widget (if neccessary)
|
||||
call_user_func($classname . '::install');
|
||||
// install widget (if neccessary)
|
||||
call_user_func($classname . '::install');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ class EditUploadedFile extends Controller
|
||||
}
|
||||
|
||||
// set values from form
|
||||
$file->name = $request->name;
|
||||
$file->keywords = $request->keywords;
|
||||
$file->description = $request->description;
|
||||
$file->save();
|
||||
|
||||
@@ -12,12 +12,6 @@ class EditWidget extends Controller
|
||||
{
|
||||
$widget = Widget::findOrFail($id);
|
||||
|
||||
// decompose widget settings
|
||||
$settings = json_decode($widget->settings);
|
||||
|
||||
$widget->containerClass = $settings->containerClass;
|
||||
$widget->code = $settings->code;
|
||||
|
||||
$presenter = call_user_func([$widget->widget_type_handler, 'getPresenter']);
|
||||
|
||||
return call_user_func([$presenter, 'renderEditForm'], $widget);
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ class File extends Model
|
||||
$newFile->file_size = $file->getSize();
|
||||
|
||||
// save optional fields
|
||||
$optionalFields = ['description', 'keywords', 'directoryId'];
|
||||
$optionalFields = ['name', 'description', 'keywords', 'directoryId'];
|
||||
foreach ($optionalFields as $field) {
|
||||
if ($request->has($field)) {
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Handlers\Search\Presenters\AdminContent as AdminContentPresenter;
|
||||
use App\Handlers\Search\Presenters\AdminFiles;
|
||||
use App\Models\Template;
|
||||
use App\Widgets\HtmlCode\HtmlCode;
|
||||
use App\Widgets\OrbitSlider\OrbitSlider;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@@ -83,6 +84,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
// register all available widgets
|
||||
$registrator->register(HtmlCode::class);
|
||||
$registrator->register(OrbitSlider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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