FEATURE #1523: add subpages for content
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class SetupDatabase extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'db:setup {host} {user} {password} {database}';
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Setup database credentials';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new command instance.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
echo "zpracovavam";
|
||||||
|
$host = $this->argument('host');
|
||||||
|
$user = $this->argument('user');
|
||||||
|
$password = $this->argument('password');
|
||||||
|
$database = $this->argument('database');
|
||||||
|
|
||||||
|
// try to connect with this settings
|
||||||
|
// @todo add credentials verification
|
||||||
|
|
||||||
|
// if pass, proceed to creating .env file
|
||||||
|
$parameters = [
|
||||||
|
'DB_HOST' => $host,
|
||||||
|
'DB_USERNAME' => $user,
|
||||||
|
'DB_PASSWORD' => $password,
|
||||||
|
'DB_DATABASE' => $database
|
||||||
|
];
|
||||||
|
|
||||||
|
$envPath = base_path('.env');
|
||||||
|
$env = file_get_contents($envPath);
|
||||||
|
if (!file_exists($envPath))
|
||||||
|
$env = file_get_contents($envPath.'.example');
|
||||||
|
|
||||||
|
foreach ($parameters as $parameter => $value) {
|
||||||
|
$env = preg_replace('/'.$parameter.'=(.*)/i', $parameter.'='.$value, $env);
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($envPath, $env);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ use App\Http\Requests\CreateNewContentRequest;
|
|||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\Module;
|
use App\Models\Module;
|
||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@@ -39,6 +38,7 @@ class CreateNewContent extends Controller
|
|||||||
'templates' => $templates,
|
'templates' => $templates,
|
||||||
'moduleId' => $moduleId,
|
'moduleId' => $moduleId,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
|
'rootPages' => $page->rootPages(),
|
||||||
'moduleName' => trans($module->name),
|
'moduleName' => trans($module->name),
|
||||||
'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']),
|
'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']),
|
||||||
'formSections' => call_user_func([$module->handler, 'getExtendedFormInputsCreate']),
|
'formSections' => call_user_func([$module->handler, 'getExtendedFormInputsCreate']),
|
||||||
@@ -78,13 +78,15 @@ class CreateNewContent extends Controller
|
|||||||
$page->template = $request->template;
|
$page->template = $request->template;
|
||||||
$page->module_handler = $module->handler;
|
$page->module_handler = $module->handler;
|
||||||
|
|
||||||
|
if ($request->parentPage) {
|
||||||
|
$page->parent_id = $request->parentPage;
|
||||||
|
}
|
||||||
|
|
||||||
// save module-specific stuff
|
// save module-specific stuff
|
||||||
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
|
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
|
||||||
|
|
||||||
$page->save();
|
$page->save();
|
||||||
|
|
||||||
Event::fire(new \Modules\StaticPages\Events\CreateNewStaticPage($page));
|
|
||||||
|
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('content.overview')
|
->route('content.overview')
|
||||||
->with('success', trans('admin/contents.successfullyCreated'));
|
->with('success', trans('admin/contents.successfullyCreated'));
|
||||||
|
|||||||
@@ -7,12 +7,7 @@ use App\Http\Requests\EditContentRequest;
|
|||||||
use App\Models\Content;
|
use App\Models\Content;
|
||||||
use App\Models\ContentHistory;
|
use App\Models\ContentHistory;
|
||||||
use App\Models\Template;
|
use App\Models\Template;
|
||||||
use Illuminate\Support\Facades\Event;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Modules\StaticPages\Events\DeleteStaticPage;
|
|
||||||
use Modules\StaticPages\Events\EditStaticPage as EditStaticPageEvent;
|
|
||||||
use Modules\StaticPages\Events\MakeDraftFromStaticPage;
|
|
||||||
use Modules\StaticPages\Events\PublishStaticPage;
|
|
||||||
use Modules\StaticPages\Http\Requests\EditStaticPageRequest;
|
use Modules\StaticPages\Http\Requests\EditStaticPageRequest;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
@@ -56,6 +51,7 @@ class EditContent extends Controller
|
|||||||
return view('admin.content.edit', [
|
return view('admin.content.edit', [
|
||||||
'contentStatuses' => $statuses,
|
'contentStatuses' => $statuses,
|
||||||
'page' => $page,
|
'page' => $page,
|
||||||
|
'rootPages' => $page->rootPages(),
|
||||||
'templates' => $templates,
|
'templates' => $templates,
|
||||||
'formSectionNames' => call_user_func([$page->module_handler, 'getExtendedFormSections']),
|
'formSectionNames' => call_user_func([$page->module_handler, 'getExtendedFormSections']),
|
||||||
'formSections' => call_user_func([$page->module_handler, 'getExtendedFormInputsCreate']),
|
'formSections' => call_user_func([$page->module_handler, 'getExtendedFormInputsCreate']),
|
||||||
@@ -84,6 +80,7 @@ class EditContent extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$request->url = Str::slug($request->url);
|
$request->url = Str::slug($request->url);
|
||||||
|
$request->parentPage = $request->parentPage ? $request->parentPage : null;
|
||||||
|
|
||||||
// array of fields in database and fields from request
|
// array of fields in database and fields from request
|
||||||
$fields = [
|
$fields = [
|
||||||
@@ -95,11 +92,12 @@ class EditContent extends Controller
|
|||||||
'meta_keywords' => 'metaKeywords',
|
'meta_keywords' => 'metaKeywords',
|
||||||
'meta_description' => 'metaDescription',
|
'meta_description' => 'metaDescription',
|
||||||
'content' => 'pageContent',
|
'content' => 'pageContent',
|
||||||
|
'parent_id' => 'parentPage',
|
||||||
'status' => 'status'
|
'status' => 'status'
|
||||||
];
|
];
|
||||||
|
|
||||||
// save new values with history
|
// save new values with history
|
||||||
list($revision, $changedColumns) = $page->updateWithHistory($fields, $request->all());
|
list($revision, $changedColumns) = $page->updateWithHistory($fields, $this->getFields($request, $fields));
|
||||||
|
|
||||||
$changedColumns += call_user_func_array([$page->module_handler, 'edit'], [&$page, $request, $revision]);
|
$changedColumns += call_user_func_array([$page->module_handler, 'edit'], [&$page, $request, $revision]);
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ class EditContent extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fire event with
|
// fire event with
|
||||||
Event::fire(new EditStaticPageEvent($page, $revision));
|
// Event::fire(new EditStaticPageEvent($page, $revision));
|
||||||
|
|
||||||
// something was changed, inform user
|
// something was changed, inform user
|
||||||
return redirect()
|
return redirect()
|
||||||
@@ -121,7 +119,6 @@ class EditContent extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method for changing page status
|
* Method for changing page status
|
||||||
*
|
|
||||||
* This method is called in static page overview from quick actions. It checks if status is valid, if page exists
|
* This method is called in static page overview from quick actions. It checks if status is valid, if page exists
|
||||||
* and updates status.
|
* and updates status.
|
||||||
*
|
*
|
||||||
@@ -164,11 +161,11 @@ class EditContent extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fire events
|
// fire events
|
||||||
if ($status != Content::STATUS_DRAFT) {
|
// if ($status != Content::STATUS_DRAFT) {
|
||||||
Event::fire(new PublishStaticPage($page, $revision));
|
// Event::fire(new PublishStaticPage($page, $revision));
|
||||||
} else {
|
// } else {
|
||||||
Event::fire(new MakeDraftFromStaticPage($page, $revision));
|
// Event::fire(new MakeDraftFromStaticPage($page, $revision));
|
||||||
}
|
// }
|
||||||
|
|
||||||
// redirect back to overview with info for user
|
// redirect back to overview with info for user
|
||||||
return redirect()
|
return redirect()
|
||||||
@@ -205,7 +202,7 @@ class EditContent extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trigger delete event
|
// trigger delete event
|
||||||
Event::fire(new DeleteStaticPage($page, $revision));
|
// Event::fire(new DeleteStaticPage($page, $revision));
|
||||||
|
|
||||||
// redirect back to overview with info for user
|
// redirect back to overview with info for user
|
||||||
return redirect()
|
return redirect()
|
||||||
@@ -253,7 +250,7 @@ class EditContent extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// trigger delete event
|
// trigger delete event
|
||||||
// Event::fire(new DeleteStaticPage($page, $revision));
|
// Event::fire(new DeleteStaticPage($page, $revision));
|
||||||
|
|
||||||
// redirect back to overview with info for user
|
// redirect back to overview with info for user
|
||||||
return redirect()
|
return redirect()
|
||||||
@@ -263,4 +260,15 @@ class EditContent extends Controller
|
|||||||
'url' => $page->url
|
'url' => $page->url
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getFields(EditContentRequest $request, $fields)
|
||||||
|
{
|
||||||
|
$requestData = [];
|
||||||
|
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$requestData[$field] = $request->$field;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $requestData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,8 @@ class CreateNewContentRequest extends Request
|
|||||||
'published_to' => 'date',
|
'published_to' => 'date',
|
||||||
'title_photo' => 'exists:files,id',
|
'title_photo' => 'exists:files,id',
|
||||||
'module_settings' => 'json',
|
'module_settings' => 'json',
|
||||||
'status' => 'required|in:draft,protected,public'
|
'status' => 'required|in:draft,protected,public',
|
||||||
|
'parentPage' => 'exists:contents,id'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ class EditContentRequest extends Request
|
|||||||
'published_from' => 'date',
|
'published_from' => 'date',
|
||||||
'published_to' => 'date',
|
'published_to' => 'date',
|
||||||
'title_photo' => 'exists:files,id',
|
'title_photo' => 'exists:files,id',
|
||||||
'status' => 'required|in:' . $statuses
|
'status' => 'required|in:' . $statuses,
|
||||||
|
'parentPage' => 'exists:contents,id'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-2
@@ -43,7 +43,6 @@ class Content extends Model
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for homepage content page
|
* Getter for homepage content page
|
||||||
*
|
|
||||||
* @return Content
|
* @return Content
|
||||||
*/
|
*/
|
||||||
public function getHomepage()
|
public function getHomepage()
|
||||||
@@ -68,8 +67,36 @@ class Content extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for overview of all content pages.
|
* Get list of all subpages
|
||||||
*
|
*
|
||||||
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
*/
|
||||||
|
public function subpages()
|
||||||
|
{
|
||||||
|
return $this->getPageQuery()
|
||||||
|
->where('parent_id', $this->id)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns list of all root pages - those pages, which parent_id is null
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function rootPages()
|
||||||
|
{
|
||||||
|
$rootPages = $this->getPageQuery()
|
||||||
|
->where('parent_id', null);
|
||||||
|
|
||||||
|
if ($this->id) {
|
||||||
|
$rootPages = $rootPages->where('id', '!=', $this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rootPages->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for overview of all content pages.
|
||||||
* These content pages may be filtered by using some handler
|
* These content pages may be filtered by using some handler
|
||||||
*
|
*
|
||||||
* @param bool $handler
|
* @param bool $handler
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class AddSubpages extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->integer('parent_id')
|
||||||
|
->after('id')
|
||||||
|
->nullable()
|
||||||
|
->default(null)
|
||||||
|
->index()
|
||||||
|
->comment('ID of parent page');
|
||||||
|
|
||||||
|
$table->foreign('parent_id')
|
||||||
|
->references('id')
|
||||||
|
->on('contents')
|
||||||
|
->onDelete('cascade')
|
||||||
|
->onUpdate('cascade');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('contents', function (Blueprint $table) {
|
||||||
|
$table->dropForeign('contents_parent_id_foreign');
|
||||||
|
$table->dropColumn('parent_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,5 +35,6 @@ return [
|
|||||||
'template' => 'Template of this page',
|
'template' => 'Template of this page',
|
||||||
'overview' => 'List of all content pages',
|
'overview' => 'List of all content pages',
|
||||||
'homepageSetup' => 'Homepage successfully set up.',
|
'homepageSetup' => 'Homepage successfully set up.',
|
||||||
'setHomepage' => 'Set page as homepage'
|
'setHomepage' => 'Set page as homepage',
|
||||||
|
'noParentPage' => ' -- No parent page -- '
|
||||||
];
|
];
|
||||||
@@ -9,6 +9,7 @@ return [
|
|||||||
'columnStatus' => 'Page visibility',
|
'columnStatus' => 'Page visibility',
|
||||||
'columnTemplate' => 'Template',
|
'columnTemplate' => 'Template',
|
||||||
'columnIs_homepage' => 'Homepage',
|
'columnIs_homepage' => 'Homepage',
|
||||||
|
'columnParentPage' => 'Parent page',
|
||||||
'emptyValue' => '<em>none</em>',
|
'emptyValue' => '<em>none</em>',
|
||||||
'changedFromTo' => 'Changed from <del>:from</del> to <ins>:to</ins>',
|
'changedFromTo' => 'Changed from <del>:from</del> to <ins>:to</ins>',
|
||||||
'numOfChanges' => 'One change|:count changes',
|
'numOfChanges' => 'One change|:count changes',
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="columns large-12">
|
<div class="columns large-6">
|
||||||
<label>
|
<label>
|
||||||
<select name="status">
|
<select name="status">
|
||||||
@foreach($contentStatuses as $status => $translation)
|
@foreach($contentStatuses as $status => $translation)
|
||||||
@@ -41,6 +41,26 @@
|
|||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
<div class="column large-6">
|
||||||
|
<label>
|
||||||
|
<select name="parentPage">
|
||||||
|
<option value="">@lang('admin/contents.noParentPage')</option>
|
||||||
|
|
||||||
|
@foreach($rootPages as $rootPage)
|
||||||
|
<option value="{{$rootPage->id}}"
|
||||||
|
@if(old('parent_page', $page->parent_id) == $rootPage->id) selected @endif>
|
||||||
|
{{$rootPage->title}}
|
||||||
|
</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
@if (isset($errors) && $errors->has('status'))
|
||||||
|
<div class="callout alert">
|
||||||
|
{{ $errors->first('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user