REFACTORING #1880 @4h30m: another ugly refactoring commit
This commit is contained in:
@@ -5,7 +5,6 @@ use App\CMS\Contracts\Content\AdvancedContentModifier;
|
||||
use App\CMS\Contracts\Content\ContentTitles;
|
||||
use App\CMS\Contracts\Modules\InstallableModule;
|
||||
use App\CMS\Handlers\Handler;
|
||||
use App\Http\Controllers\Admin\Contents\EditContent;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\ActionLog\ActionLogType;
|
||||
@@ -27,7 +26,7 @@ class Article extends Handler implements ContentTitles, AdvancedContentModifier,
|
||||
public function render(Content $content, $parameters)
|
||||
{
|
||||
$content->comments = [];
|
||||
if (isset($content->module_settings->allowComments) && $content->module_settings->allowComments) {
|
||||
if (isset($content->moduleSettings->allowComments) && $content->moduleSettings->allowComments) {
|
||||
$content->comments = Comment::where('content_id', $content->id)
|
||||
->with('author')
|
||||
->where('approved', 1)
|
||||
@@ -62,7 +61,7 @@ class Article extends Handler implements ContentTitles, AdvancedContentModifier,
|
||||
*/
|
||||
public static function createNew(Content &$content, Request $request)
|
||||
{
|
||||
$content->module_settings = json_encode(['allowComments' => (int)$request->has('allowComments')]);
|
||||
$content->moduleSettings = ['allowComments' => (int)$request->has('allowComments')];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,23 +72,18 @@ class Article extends Handler implements ContentTitles, AdvancedContentModifier,
|
||||
* @param Content $content
|
||||
* @param Request $request
|
||||
*
|
||||
* @param $revisionID string ID of revision used
|
||||
*
|
||||
* @return int number of edited fields
|
||||
* @return void
|
||||
*/
|
||||
public static function edit(Content &$content, Request $request, $revisionID)
|
||||
public static function edit(Content $content, $request)
|
||||
{
|
||||
$fields = ['allowComments' => 'allowComments'];
|
||||
$settings = $content->moduleSettings;
|
||||
if (!is_object($settings))
|
||||
$settings = new \stdClass();
|
||||
|
||||
// get data and try to save them
|
||||
$data = EditContent::getFields($request, $fields);
|
||||
$settings->allowComments = isset($request['allowComments']) ? (int)$request['allowComments'] : 0;
|
||||
|
||||
$data['allowComments'] = (int)$data['allowComments'];
|
||||
|
||||
list($revision, $changedColumns) = $content->updateWithHistory($fields, $data, $revisionID);
|
||||
|
||||
// return amount of changed columns
|
||||
return $changedColumns;
|
||||
$content->moduleSettings = $settings;
|
||||
$content->save();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,8 +93,6 @@ class Article extends Handler implements ContentTitles, AdvancedContentModifier,
|
||||
*/
|
||||
public static function registerAdminMenu(User $user)
|
||||
{
|
||||
parent::registerAdminMenu($user);
|
||||
|
||||
$menu = \Menu::instance('mainMenu');
|
||||
|
||||
$blogSubmenu = $menu->whereTitle(trans('article::module.blog'));
|
||||
|
||||
@@ -14,12 +14,12 @@ class CreateNewComment extends Controller
|
||||
public function postNew(\Modules\Blog\Article\Http\Requests\CreateNewComment $request, $articleId)
|
||||
{
|
||||
$article = Content::where('id', $articleId)
|
||||
->where('module_handler', Article::class)
|
||||
->where('moduleHandler', Article::class)
|
||||
->firstOrFail();
|
||||
|
||||
$article->module_settings = json_decode($article->module_settings);
|
||||
$article->moduleSettings = json_decode($article->moduleSettings);
|
||||
|
||||
if (!isset($article->module_settings->allowComments) || !$article->module_settings->allowComments) {
|
||||
if (!isset($article->moduleSettings->allowComments) || !$article->moduleSettings->allowComments) {
|
||||
return redirect()
|
||||
->route('page.content', ['url' => $article->url])
|
||||
->with('error', trans('article::comments.disabledComments'));
|
||||
|
||||
@@ -37,12 +37,12 @@
|
||||
@include('admin.snippets.hasError', ['field' => 'status'])
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<select class="form-control" name="parentPage">
|
||||
<select class="form-control" name="parentId">
|
||||
<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>
|
||||
@if(old('parentId', $page->parentId) == $rootPage->id) selected @endif>
|
||||
{{$rootPage->title}}
|
||||
</option>
|
||||
@endforeach
|
||||
@@ -54,7 +54,7 @@
|
||||
<div class="col-lg-2 text-center">
|
||||
<label>
|
||||
<input class="checkbox" value="1"
|
||||
@if(old('allowComments', isset($page->module_settings->allowComments) ? $page->module_settings->allowComments : true)) checked
|
||||
@if(old('allowComments', isset($page->moduleSettings->allowComments) ? $page->moduleSettings->allowComments : true)) checked
|
||||
@endif name="allowComments" type="checkbox">
|
||||
<span>@lang('article::article.allowComments')</span>
|
||||
</label>
|
||||
@@ -62,11 +62,11 @@
|
||||
|
||||
@if($module->support_categories && count($categories))
|
||||
<div class="col-lg-12">
|
||||
<select class="form-control" name="category">
|
||||
<select class="form-control" name="categoryId">
|
||||
<option value="">@lang('admin/contents.noCategory')</option>
|
||||
@foreach($categories as $category)
|
||||
<option value="{{$category->id}}"
|
||||
@if($category->id == old('category', $page->category_id)) selected @endif>
|
||||
@if($category->id == old('categoryId', $page->categoryId)) selected @endif>
|
||||
{{str_repeat(' - ', $category->real_depth)}} {{$category->name}}
|
||||
</option>
|
||||
@endforeach
|
||||
@@ -78,7 +78,7 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<textarea name="pageContent" id="pageContent" class="wysiwyg-editor">
|
||||
{{old('pageContent', $page->content)}}
|
||||
{{old('pageContent', $page->pageContent)}}
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -96,18 +96,18 @@ class ArticleList extends Handler
|
||||
*/
|
||||
public function render(Content $content, $parameters)
|
||||
{
|
||||
$articles = ArticleModel::where('module_handler', Article::class)
|
||||
$articles = ArticleModel::where('moduleHandler', Article::class)
|
||||
->with('comments')
|
||||
->with('category')
|
||||
->where(function ($query) {
|
||||
$query->where('published_from', '<', Carbon::now())
|
||||
->orWhereNull('published_from');
|
||||
$query->where('publishedFrom', '<', Carbon::now())
|
||||
->orWhereNull('publishedFrom');
|
||||
})
|
||||
->where(function ($query) {
|
||||
$query->where('published_to', '>', Carbon::now())
|
||||
->orWhereNull('published_to');
|
||||
$query->where('publishedTo', '>', Carbon::now())
|
||||
->orWhereNull('publishedTo');
|
||||
})
|
||||
->orderBy('published_from', 'DESC')
|
||||
->orderBy('publishedFrom', 'DESC')
|
||||
->orderBy('created_at', 'DESC');
|
||||
|
||||
// show articles for not-logged users of even for logged onew?
|
||||
@@ -135,7 +135,7 @@ class ArticleList extends Handler
|
||||
|
||||
// decode module settings
|
||||
foreach ($articles as $article) {
|
||||
$article->module_settings = json_decode($article->module_settings);
|
||||
$article->moduleSettings = json_decode($article->moduleSettings);
|
||||
}
|
||||
|
||||
return Controller::VisitorsView($content->template, [
|
||||
|
||||
Reference in New Issue
Block a user