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\Module;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -39,6 +38,7 @@ class CreateNewContent extends Controller
|
||||
'templates' => $templates,
|
||||
'moduleId' => $moduleId,
|
||||
'page' => $page,
|
||||
'rootPages' => $page->rootPages(),
|
||||
'moduleName' => trans($module->name),
|
||||
'formSectionNames' => call_user_func([$module->handler, 'getExtendedFormSections']),
|
||||
'formSections' => call_user_func([$module->handler, 'getExtendedFormInputsCreate']),
|
||||
@@ -78,13 +78,15 @@ class CreateNewContent extends Controller
|
||||
$page->template = $request->template;
|
||||
$page->module_handler = $module->handler;
|
||||
|
||||
if ($request->parentPage) {
|
||||
$page->parent_id = $request->parentPage;
|
||||
}
|
||||
|
||||
// save module-specific stuff
|
||||
call_user_func_array([$module->handler, 'createNew'], [&$page, $request]);
|
||||
|
||||
$page->save();
|
||||
|
||||
Event::fire(new \Modules\StaticPages\Events\CreateNewStaticPage($page));
|
||||
|
||||
return redirect()
|
||||
->route('content.overview')
|
||||
->with('success', trans('admin/contents.successfullyCreated'));
|
||||
|
||||
@@ -7,12 +7,7 @@ use App\Http\Requests\EditContentRequest;
|
||||
use App\Models\Content;
|
||||
use App\Models\ContentHistory;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
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 Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
@@ -56,6 +51,7 @@ class EditContent extends Controller
|
||||
return view('admin.content.edit', [
|
||||
'contentStatuses' => $statuses,
|
||||
'page' => $page,
|
||||
'rootPages' => $page->rootPages(),
|
||||
'templates' => $templates,
|
||||
'formSectionNames' => call_user_func([$page->module_handler, 'getExtendedFormSections']),
|
||||
'formSections' => call_user_func([$page->module_handler, 'getExtendedFormInputsCreate']),
|
||||
@@ -84,6 +80,7 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
$request->url = Str::slug($request->url);
|
||||
$request->parentPage = $request->parentPage ? $request->parentPage : null;
|
||||
|
||||
// array of fields in database and fields from request
|
||||
$fields = [
|
||||
@@ -95,11 +92,12 @@ class EditContent extends Controller
|
||||
'meta_keywords' => 'metaKeywords',
|
||||
'meta_description' => 'metaDescription',
|
||||
'content' => 'pageContent',
|
||||
'parent_id' => 'parentPage',
|
||||
'status' => 'status'
|
||||
];
|
||||
|
||||
// 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]);
|
||||
|
||||
@@ -111,7 +109,7 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// fire event with
|
||||
Event::fire(new EditStaticPageEvent($page, $revision));
|
||||
// Event::fire(new EditStaticPageEvent($page, $revision));
|
||||
|
||||
// something was changed, inform user
|
||||
return redirect()
|
||||
@@ -121,7 +119,6 @@ class EditContent extends Controller
|
||||
|
||||
/**
|
||||
* 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
|
||||
* and updates status.
|
||||
*
|
||||
@@ -164,11 +161,11 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// fire events
|
||||
if ($status != Content::STATUS_DRAFT) {
|
||||
Event::fire(new PublishStaticPage($page, $revision));
|
||||
} else {
|
||||
Event::fire(new MakeDraftFromStaticPage($page, $revision));
|
||||
}
|
||||
// if ($status != Content::STATUS_DRAFT) {
|
||||
// Event::fire(new PublishStaticPage($page, $revision));
|
||||
// } else {
|
||||
// Event::fire(new MakeDraftFromStaticPage($page, $revision));
|
||||
// }
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
@@ -205,7 +202,7 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// trigger delete event
|
||||
Event::fire(new DeleteStaticPage($page, $revision));
|
||||
// Event::fire(new DeleteStaticPage($page, $revision));
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
@@ -253,7 +250,7 @@ class EditContent extends Controller
|
||||
}
|
||||
|
||||
// trigger delete event
|
||||
// Event::fire(new DeleteStaticPage($page, $revision));
|
||||
// Event::fire(new DeleteStaticPage($page, $revision));
|
||||
|
||||
// redirect back to overview with info for user
|
||||
return redirect()
|
||||
@@ -263,4 +260,15 @@ class EditContent extends Controller
|
||||
'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',
|
||||
'title_photo' => 'exists:files,id',
|
||||
'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_to' => 'date',
|
||||
'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
|
||||
*
|
||||
* @return Content
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param bool $handler
|
||||
|
||||
Reference in New Issue
Block a user