FEATURE #1528: add button for creating slider from gallery
This commit is contained in:
@@ -50,6 +50,24 @@ class Gallery implements AppHandler
|
||||
return History::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Content $content
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function loadExtraData(Content $content)
|
||||
{
|
||||
if (is_string($content->module_settings)) {
|
||||
$content->module_settings = json_decode($content->module_settings);
|
||||
}
|
||||
|
||||
$extra = [
|
||||
'slider' => isset($content->module_settings->slider) ? $content->module_settings->slider : false
|
||||
];
|
||||
|
||||
return $extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save module-specific values into database
|
||||
*
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php namespace Modules\Gallery\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\Content;
|
||||
use App\Models\Widget;
|
||||
use App\Models\WidgetType;
|
||||
use App\Widgets\OrbitSlider\OrbitSlider;
|
||||
use Pingpong\Modules\Routing\Controller;
|
||||
|
||||
class CreateOrbitSlider extends Controller
|
||||
{
|
||||
/**
|
||||
* @var Widget
|
||||
*/
|
||||
private $widget;
|
||||
|
||||
/**
|
||||
* CreateOrbitSlider constructor.
|
||||
*
|
||||
* @param Widget $widget
|
||||
*/
|
||||
public function __construct(Widget $widget)
|
||||
{
|
||||
$this->widget = $widget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load gallery or redirect user back to content edit form
|
||||
*
|
||||
* @param $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getGallery($id)
|
||||
{
|
||||
$content = Content::where('module_handler', config('gallery.handler'))
|
||||
->findOrFail($id);
|
||||
$content->module_settings = json_decode($content->module_settings);
|
||||
|
||||
// check if gallery has assigned some directory id
|
||||
if (!isset($content->module_settings->directoryId)) {
|
||||
return redirect()
|
||||
->route('content.edit', ['id' => $id])
|
||||
->with('error', trans('gallery::admin/content.invalidGallery'));
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load widget type for Orbit Slider. In case it does not exist, redirect user back to content edit form.
|
||||
*
|
||||
* @param $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getOrbitSliderWidgetType($id)
|
||||
{
|
||||
// try to load widget type for slider
|
||||
$widgetType = WidgetType::where('handler', OrbitSlider::class)
|
||||
->first();
|
||||
|
||||
// check if widget type exists
|
||||
if (!$widgetType) {
|
||||
return redirect()
|
||||
->route('content.edit', ['id' => $id])
|
||||
->with('error', trans('gallery::admin/content.orbitSliderMissing'));
|
||||
}
|
||||
|
||||
return $widgetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for creating slider from photogallery
|
||||
*
|
||||
* @param $id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function createNew($id)
|
||||
{
|
||||
// try to find gallery with specified ID
|
||||
$content = $this->getGallery($id);
|
||||
|
||||
// load info about orbit slider widget
|
||||
$widgetType = $this->getOrbitSliderWidgetType($id);
|
||||
|
||||
// create slider basic config
|
||||
$sliderSettings = (object)[
|
||||
'name' => $content->title,
|
||||
'description' => $content->meta_description,
|
||||
'directoryId' => $content->module_settings->directoryId,
|
||||
'useExistingDirectory' => true,
|
||||
];
|
||||
|
||||
// try to create the slider
|
||||
try {
|
||||
$slider = $this->widget->createNew($widgetType, $sliderSettings);
|
||||
} catch (\Exception $e) {
|
||||
return redirect()
|
||||
->route('content.edit', ['id' => $id])
|
||||
->with('error', trans('gallery::admin/content.sliderFailed', ['message' => $e->getMessage()]));
|
||||
}
|
||||
|
||||
// update gallery info
|
||||
$content->module_settings->slider = $slider->id;
|
||||
$content->module_settings = json_encode($content->module_settings);
|
||||
$content->save();
|
||||
|
||||
return redirect()
|
||||
->route('content.edit', ['id' => $id])
|
||||
->with('success', trans('gallery::admin/content.sliderCreated'));
|
||||
}
|
||||
}
|
||||
@@ -1 +1,11 @@
|
||||
<?php
|
||||
Route::group([
|
||||
'middleware' => ['web', 'auth', 'adminMenu'],
|
||||
'namespace' => 'Modules\Gallery\Http\Controllers\Admin',
|
||||
'prefix' => 'admin/gallery'
|
||||
], function () {
|
||||
|
||||
// method for creating slider from photogallery
|
||||
Route::get('makeSlider/{id}', 'CreateOrbitSlider@createNew')
|
||||
->name('gallery.makeSlider');
|
||||
});
|
||||
@@ -1,5 +1,11 @@
|
||||
<?php
|
||||
return [
|
||||
'upload' => 'Upload photos',
|
||||
'uploadAfterSavingGallery' => 'Uploading for this gallery is not available yet. You must create the gallery first and upload later.'
|
||||
'uploadAfterSavingGallery' => 'Uploading for this gallery is not available yet. You must create the gallery first and upload later.',
|
||||
'makeSlider' => 'Make slider from this photogallery',
|
||||
'orbitSliderMissing' => 'Cannot create slider. Widget for slider is not installed.',
|
||||
'invalidGallery' => 'This content page is not a valid gallery page.',
|
||||
'sliderFailed' => 'Slider could not be created. Reason: :message',
|
||||
'sliderCreated' => 'Slider successfully created.',
|
||||
'sliderEdit' => 'Slider settings',
|
||||
];
|
||||
@@ -1,3 +1,12 @@
|
||||
<div class="row column">
|
||||
<a href="{{route('upload.overview', ['id' => $page->module_settings->directoryId])}}" class="button large expanded success">@lang('gallery::admin/content.upload')</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row column text-center">
|
||||
@if (!$extraData['slider'])
|
||||
<a href="{{route('gallery.makeSlider', ['id' => $page->id])}}" class="button primary">@lang('gallery::admin/content.makeSlider')</a>
|
||||
@else
|
||||
<a href="{{route('widgets.edit', ['id' => $extraData['slider']])}}" class="button secondary">@lang('gallery::admin/content.sliderEdit')</a>
|
||||
@endif
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
Reference in New Issue
Block a user