diff --git a/app/CMS/Contracts/Repositories/BaseRepository.php b/app/CMS/Contracts/Repositories/BaseRepository.php new file mode 100644 index 00000000..9b0bebc6 --- /dev/null +++ b/app/CMS/Contracts/Repositories/BaseRepository.php @@ -0,0 +1,7 @@ +getValidationRules($parameters); - $validator = Validator::make($request->all(), $validationRules); + // validate interaction + $validator = Validator::make($request->all(), $interaction->getValidationRules($parameters)); if ($validator->fails()) { throw new ValidationFailedException($validator); } + // handle it return $interaction->handle($request, $parameters); } } \ No newline at end of file diff --git a/app/CMS/Interactions/Admin/Content/NewContent.php b/app/CMS/Interactions/Admin/Content/NewContent.php index 2c108ca8..3e8a25f6 100644 --- a/app/CMS/Interactions/Admin/Content/NewContent.php +++ b/app/CMS/Interactions/Admin/Content/NewContent.php @@ -3,15 +3,33 @@ namespace App\Cms\Interactions\Admin\Content; use App\CMS\Contracts\Interaction; use App\CMS\Helpers\CurrentTemplate; +use App\Events\CreateNewContent; use App\Http\Requests\Request; use App\Models\Content\Content; +use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Str; use Mcamara\LaravelLocalization\Facades\LaravelLocalization; class NewContent implements Interaction { + protected $content; + + public function __construct() + { + $this->content = App::make(\App\CMS\Contracts\Repositories\Content::class); + } + + /** + * @param Request $request + * @param $parameters + * + * @return Content + */ public function handle(Request $request, $parameters) { + list($moduleHandler) = $parameters; + // create new page $page = new Content(); $page->template = $request->template; @@ -27,7 +45,7 @@ class NewContent implements Interaction $page->meta_description = $request->metaDescription; $page->content = $request->pageContent; $page->status = $request->status; - $page->module_handler = $request->handler; + $page->module_handler = $moduleHandler; $page->category_id = (int)$request->category > 0 ? $request->category : null; $page->parent_id = $request->parentPage ? $request->parentPage : null; @@ -48,6 +66,9 @@ class NewContent implements Interaction // upload files assigned to content page $page->uploadRelatedFiles($request); + Event::fire(new CreateNewContent($this)); + + return $page; } diff --git a/app/CMS/Repositories/Content/Content.php b/app/CMS/Repositories/Content/Content.php new file mode 100644 index 00000000..3d2a0a2e --- /dev/null +++ b/app/CMS/Repositories/Content/Content.php @@ -0,0 +1,124 @@ +model = $model; + } + + /** + * Getter for query with setup filter for non-deleted and non-draft pages + */ + protected function getPageQuery() + { + return ContentModel::where('status', '!=', IContent::STATUS_DRAFT) + ->select('contents.*') + ->with('author') + ->join('modules', 'modules.handler', '=', 'contents.module_handler') + ->where(function ($query) { + $query->where('published_from', '<', Carbon::now()) + ->orWhereNull('published_from'); + }) + ->where(function ($query) { + $query->where('published_to', '>', Carbon::now()) + ->orWhereNull('published_to'); + }) + ->where('language', LaravelLocalization::getCurrentLocale()) + ->where('modules.enabled', true); + } + + public function all() + { + return $this->getPageQuery() + ->get(); + } + + public function getOne($id = null) + { + if (is_null($id)) { + $page = new ContentModel(); + $page->user_id = \Auth::user()->id; + $page->language = LaravelLocalization::getCurrentLocale(); + $page->module_settings = []; + } else { + $page = $this->model->find($id); + $page->module_settings = json_decode($page->module_settings); + } + + return $page; + } + + /** + * Getter for homepage content page + * @return Content + */ + public function getHomepage() + { + return $this->getPageQuery() + ->where('is_homepage', 1) + ->first(); + } + + /** + * Getter for any page specified by its url. + * + * @param $url + * + * @return Content + */ + public function getByURL($url) + { + return $this->getPageQuery() + ->where('url', $url) + ->first(); + } + + /** + * Getter for overview of all content pages. + * These content pages may be filtered by using some handler + * + * @param bool $handler + * @param null $statuses + * + * @return + */ + public function getOverview($handler = null, $statuses = null) + { + $query = ContentModel::select('contents.*', 'modules.name AS module_name', 'modules.id AS module_id') + ->join('modules', 'modules.handler', '=', 'contents.module_handler') + ->join('users', 'users.id', '=', 'contents.user_id') + ->addSelect(DB::raw('COALESCE(users.name, users.email) AS author_name')) + ->addSelect('users.email AS author_email') + ->whereNull('contents.deleted_at') + ->where('contents.language', LaravelLocalization::getCurrentLocale()) + ->where('modules.enabled', 1) + ->orderBy('contents.created_at', 'DESC'); + + // filter results using handler + if (!is_null($handler)) { + $query = $query->where('contents.module_handler', $handler); + } + + // add filtering by status + if (is_array($statuses) && in_array($statuses, ContentStatuses::getSimple())) { + $query = $query->whereIn('contents.status', $statuses); + } + + return $query->paginate(20); + } +} \ No newline at end of file diff --git a/app/CMS/Repositories/Content/History.php b/app/CMS/Repositories/Content/History.php new file mode 100644 index 00000000..e69de29b diff --git a/app/CMS/Repositories/Module.php b/app/CMS/Repositories/Module.php new file mode 100644 index 00000000..a31e62e5 --- /dev/null +++ b/app/CMS/Repositories/Module.php @@ -0,0 +1,48 @@ +handler, 'getOverviewTitle'])) { + $pageHeading = call_user_func([$module->handler, 'getOverviewTitle']); + } + + return $pageHeading; + } + + public function all() + { + // TODO: Implement all() method. + } +} \ No newline at end of file diff --git a/app/CMS/Repositories/Repository.php b/app/CMS/Repositories/Repository.php new file mode 100644 index 00000000..7df4d787 --- /dev/null +++ b/app/CMS/Repositories/Repository.php @@ -0,0 +1,12 @@ +model, $method], $args); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/Contents/ContentActions.php b/app/Http/Controllers/Admin/Contents/ContentActions.php new file mode 100644 index 00000000..be6e6bc4 --- /dev/null +++ b/app/Http/Controllers/Admin/Contents/ContentActions.php @@ -0,0 +1,162 @@ +route('content.overview') + ->with('error', trans('admin/contents.invalidStatus')); + } + + try { + // try to find this page + $page = Content::findOrFail($id); + } catch (NotFoundHttpException $e) { + // page not found + return redirect() + ->route('content.overview') + ->with('error', trans('admin/contents.invalidPage')); + } + + // try to change the page + list ($revision, $changedColumns) = $page->updateWithHistory(['status' => 'status'], ['status' => $status]); + + // was something changed? + if ($changedColumns == 0) { + return redirect() + ->route('content.edit', ['id' => $page->id]) + ->with('error', trans('admin/contents.nothingToEdit')); + } + + // fire events + if ($status != Content::STATUS_DRAFT) { + Event::fire(new PublishContent($page, $revision)); + } else { + Event::fire(new MakeDraftFromContent($page, $revision)); + } + + // redirect back to overview with info for user + return redirect() + ->route('content.overview') + ->with('success', trans('admin/contents.statusChanged')); + } + + /** + * Delete page + * + * @param $id + * + * @return \Illuminate\Http\RedirectResponse + */ + public function delete($id) + { + try { + // try to find this page + $page = Content::findOrFail($id); + } catch (NotFoundHttpException $e) { + // page not found + return redirect() + ->route('content.overview') + ->with('error', trans('admin/contents.invalidPage')); + } + + // change url to something unique + $oldURL = $page->url; + $page->url .= uniqid('_deleted_'); + $page->save(); + + // delete page + $page->delete(); + + // let module to delete some extra content created during page's life + call_user_func([$page->module_handler, 'delete'], $page); + + // trigger delete event + Event::fire(new DeleteContent($page)); + + // redirect back to overview with info for user + return redirect() + ->route('content.overview') + ->with('success', trans('admin/contents.pageDeleted', [ + 'name' => $page->title, + 'url' => $oldURL + ])); + } + + /** + * Sets page as homepage + * + * @param $id + * + * @return \Illuminate\Http\RedirectResponse + */ + public function setHomepage($id) + { + try { + // try to find this page + /** + * @var $page Content + */ + $page = Content::findOrFail($id); + } catch (NotFoundHttpException $e) { + // page not found + return redirect() + ->back() + ->with('error', trans('admin/contents.invalidPage')); + } + + // disable any other existing homepage + Content::where('is_homepage', 1) + ->where('language', LaravelLocalization::getCurrentLocale()) + ->update(['is_homepage' => 0]); + + // set new homepage + list ($revision, $changedColumns) = $page->updateWithHistory(['is_homepage' => 'is_homepage'], ['is_homepage' => 1]); + + // was something changed? + if ($changedColumns == 0) { + return redirect() + ->back() + ->with('error', trans('admin/contents.nothingToEdit')); + } + + // trigger delete event + Event::fire(new SetHomepage($page, $revision)); + + // redirect back to overview with info for user + return redirect() + ->back() + ->with('success', trans('admin/contents.homepageSetup', [ + 'name' => $page->title, + 'url' => $page->url + ])); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Admin/Contents/ContentOverview.php b/app/Http/Controllers/Admin/Contents/ContentOverview.php index 2c792680..28f5ac5d 100644 --- a/app/Http/Controllers/Admin/Contents/ContentOverview.php +++ b/app/Http/Controllers/Admin/Contents/ContentOverview.php @@ -1,53 +1,45 @@ content = $content; + $this->module = $module; } /** * Overview for all content pages. * - * @param bool|false $moduleId - * @param null $status + * @param null|int $moduleId + * @param null $status * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function getOverview($moduleId = false, $status = null) + public function index($moduleId = null, $status = null) { - $moduleFilterHandler = false; - $perPage = Input::get('perPage') ? Input::get('perPage') : 20; - $pageHeading = 'admin/contents.overview'; - - // does user want to filter results using module? - if (is_numeric($moduleId)) { - $module = Module::findOrFail($moduleId); - $moduleFilterHandler = $module->handler; - - if (is_callable([$module->handler, 'getOverviewTitle'])) { - $pageHeading = call_user_func([$module->handler, 'getOverviewTitle']); - } - } + // get module settings + $module = $this->module->getOne($moduleId); + $pageHeading = $this->module->getOverviewTitle($module); // get pages for overview - $pages = $this->content->getOverview($moduleFilterHandler, $status, true, true) - ->paginate($perPage); + $handler = $module !== null ? $module->handler : null; + $pages = $this->content->getOverview($handler, [$status]); // get homepage - for checking if homepage is set and available $homepage = $this->content->getHomepage(); diff --git a/app/Http/Controllers/Admin/Contents/CreateNewContent.php b/app/Http/Controllers/Admin/Contents/CreateNewContent.php index 15e5343f..dac734a4 100644 --- a/app/Http/Controllers/Admin/Contents/CreateNewContent.php +++ b/app/Http/Controllers/Admin/Contents/CreateNewContent.php @@ -1,21 +1,19 @@ file = $file; $this->content = $content; + $this->module = $module; } /** @@ -57,7 +61,7 @@ class CreateNewContent extends Controller * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function getNew($moduleId) + public function create($moduleId) { $module = Module::findOrFail($moduleId); $statuses = ContentStatuses::getWithTranslations(); @@ -82,7 +86,7 @@ class CreateNewContent extends Controller } // create default content object - $this->content->status = Content::STATUS_DRAFT; + $this->content->status = IContent::STATUS_DRAFT; // render view return view('admin.content.new', [ @@ -110,21 +114,12 @@ class CreateNewContent extends Controller * * @return \Illuminate\Http\RedirectResponse */ - public function postNew(Request $request, $moduleId) + public function store(Request $request, $moduleId) { - try { - $module = Module::findOrFail($moduleId); - } catch (NotFoundHttpException $e) { - return redirect() - ->route('content.overview') - ->withInput() - ->with('error', trans('admin/contents.invalidModule')); - } - - $request->handler = $module->handler; + $module = Module::findOrFail($moduleId); // create new page - Interaction::handle($request, new NewContent()); + Interaction::handle($request, new NewContent(), $module->handler); return redirect() ->route('content.overview') diff --git a/app/Http/Controllers/Admin/Contents/EditContent.php b/app/Http/Controllers/Admin/Contents/EditContent.php index 81c96fe3..2bc7a092 100644 --- a/app/Http/Controllers/Admin/Contents/EditContent.php +++ b/app/Http/Controllers/Admin/Contents/EditContent.php @@ -6,10 +6,6 @@ use App\Cms\Handlers\Interactions\Interaction; use App\CMS\Helpers\CurrentTemplate; use App\Cms\Interactions\Admin\Content\EditContent as EditContentInteraction; use App\Events\AttemptToEditInvalidContent; -use App\Events\DeleteContent; -use App\Events\MakeDraftFromContent; -use App\Events\PublishContent; -use App\Events\SetHomepage; use App\Http\Controllers\Admin\Controller; use App\Http\Requests\EditContentRequest; use App\Http\Requests\Request; @@ -19,7 +15,6 @@ use App\Models\FileManager\File; use App\Models\Module; use App\Models\Templates\Template; use Illuminate\Support\Facades\Event; -use Mcamara\LaravelLocalization\Facades\LaravelLocalization; use Modules\Categories\Entities\Category; use Pingpong\Modules\Facades\Module as ModuleInstance; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -56,7 +51,7 @@ class EditContent extends Controller * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function getEdit($id) + public function edit($id) { // select all content statuses $statuses = ContentStatuses::getWithTranslations(); @@ -70,7 +65,7 @@ class EditContent extends Controller ->firstOrFail(); $pageHeading = trans('admin/contents.edit', ['name' => e($page->title)]); - if (is_callable([$module->handler, 'getCreateNewTitle'])) { + if (is_callable([$module->handler, 'getEditTitle'])) { $pageHeading = call_user_func([$module->handler, 'getEditTitle'], $page); } @@ -120,7 +115,7 @@ class EditContent extends Controller * * @return \Illuminate\Http\RedirectResponse */ - public function postEdit(Request $request, $id) + public function update(Request $request, $id) { try { /** @@ -154,152 +149,6 @@ class EditContent extends Controller ->with('success', trans('admin/contents.successfullyEdited')); } - /** - * 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. - * - * @param $id - * @param $status - * - * @return \Illuminate\Http\RedirectResponse - */ - public function changeStatus($id, $status) - { - // get possible statuses - $statuses = ContentStatuses::getWithTranslations(); - - // check if given status is valid - if (!isset($statuses[$status])) { - return redirect() - ->route('content.overview') - ->with('error', trans('admin/contents.invalidStatus')); - } - - try { - // try to find this page - $page = Content::findOrFail($id); - } catch (NotFoundHttpException $e) { - // page not found - return redirect() - ->route('content.overview') - ->with('error', trans('admin/contents.invalidPage')); - } - - // try to change the page - list ($revision, $changedColumns) = $page->updateWithHistory(['status' => 'status'], ['status' => $status]); - - // was something changed? - if ($changedColumns == 0) { - return redirect() - ->route('content.edit', ['id' => $page->id]) - ->with('error', trans('admin/contents.nothingToEdit')); - } - - // fire events - if ($status != Content::STATUS_DRAFT) { - Event::fire(new PublishContent($page, $revision)); - } else { - Event::fire(new MakeDraftFromContent($page, $revision)); - } - - // redirect back to overview with info for user - return redirect() - ->route('content.overview') - ->with('success', trans('admin/contents.statusChanged')); - } - - /** - * Delete page - * - * @param $id - * - * @return \Illuminate\Http\RedirectResponse - */ - public function deletePage($id) - { - try { - // try to find this page - $page = Content::findOrFail($id); - } catch (NotFoundHttpException $e) { - // page not found - return redirect() - ->route('content.overview') - ->with('error', trans('admin/contents.invalidPage')); - } - - // change url to something unique - $oldURL = $page->url; - $page->url .= uniqid('_deleted_'); - $page->save(); - - // delete page - $page->delete(); - - // let module to delete some extra content created during page's life - call_user_func([$page->module_handler, 'delete'], $page); - - // trigger delete event - Event::fire(new DeleteContent($page)); - - // redirect back to overview with info for user - return redirect() - ->route('content.overview') - ->with('success', trans('admin/contents.pageDeleted', [ - 'name' => $page->title, - 'url' => $oldURL - ])); - } - - /** - * Sets page as homepage - * - * @param $id - * - * @return \Illuminate\Http\RedirectResponse - */ - public function setHomepage($id) - { - try { - // try to find this page - /** - * @var $page Content - */ - $page = Content::findOrFail($id); - } catch (NotFoundHttpException $e) { - // page not found - return redirect() - ->back() - ->with('error', trans('admin/contents.invalidPage')); - } - - // disable any other existing homepage - Content::where('is_homepage', 1) - ->where('language', LaravelLocalization::getCurrentLocale()) - ->update(['is_homepage' => 0]); - - // set new homepage - list ($revision, $changedColumns) = $page->updateWithHistory(['is_homepage' => 'is_homepage'], ['is_homepage' => 1]); - - // was something changed? - if ($changedColumns == 0) { - return redirect() - ->back() - ->with('error', trans('admin/contents.nothingToEdit')); - } - - // trigger delete event - Event::fire(new SetHomepage($page, $revision)); - - // redirect back to overview with info for user - return redirect() - ->back() - ->with('success', trans('admin/contents.homepageSetup', [ - 'name' => $page->title, - 'url' => $page->url - ])); - } - /** * Convert object of all request data into array of only wanted fields * diff --git a/app/Http/routes/admin/contents.php b/app/Http/routes/admin/contents.php index 6e7b6a6a..20a2fe81 100644 --- a/app/Http/routes/admin/contents.php +++ b/app/Http/routes/admin/contents.php @@ -1,35 +1,35 @@ 'Contents'], function () { // list of all static pages - Route::get('content/overview/{moduleId?}/{status?}', 'ContentOverview@getOverview') + Route::get('content/overview/{moduleId?}/{status?}', 'ContentOverview@index') ->name('content.overview'); // form for creating new static page - Route::get('content/new/{moduleId}', 'CreateNewContent@getNew') + Route::get('content/new/{moduleId}', 'CreateNewContent@create') ->name('content.new'); // form for editing existing static page - Route::get('content/edit/{id}', 'EditContent@getEdit') + Route::get('content/edit/{id}', 'EditContent@edit') ->name('content.edit'); // post method for creating new static page - Route::post('content/new/{moduleId}', 'CreateNewContent@postNew') + Route::post('content/new/{moduleId}', 'CreateNewContent@store') ->name('content.newPost'); // post method for creating new static page - Route::post('content/edit/{id}', 'EditContent@postEdit') + Route::post('content/edit/{id}', 'EditContent@update') ->name('content.editPost'); // change status of page (protected, public or draft) - Route::get('content/status/{id}/{status}', 'EditContent@changeStatus') + Route::get('content/status/{id}/{status}', 'ContentActions@changeStatus') ->name('content.changeStatus'); // set homepage - Route::get('content/homepage/{id}', 'EditContent@setHomepage') + Route::get('content/homepage/{id}', 'ContentActions@setHomepage') ->name('content.setHomepage'); // delete page - Route::get('content/delete/{id}', 'EditContent@deletePage') + Route::get('content/delete/{id}', 'ContentActions@delete') ->name('content.delete'); // history of changes for specified page diff --git a/app/Models/Content/Content.php b/app/Models/Content/Content.php index beebd301..35ae6a49 100644 --- a/app/Models/Content/Content.php +++ b/app/Models/Content/Content.php @@ -36,49 +36,6 @@ class Content extends Model 'module_settings', 'status' ]; - const STATUS_DRAFT = 'draft'; - const STATUS_PROTECTED = 'protected'; - const STATUS_PUBLIC = 'public'; - - /** - * Is current content draft? - * - * @return bool - */ - public function isDraft() - { - return $this->status == self::STATUS_DRAFT; - } - - /** - * Is current content visible for all visitors? - * - * @return bool - */ - public function isPublic() - { - return $this->status == self::STATUS_PUBLIC; - } - - /** - * Is current content visible only for logged users? - * - * @return bool - */ - public function isProtected() - { - return $this->status == self::STATUS_PROTECTED; - } - - /** - * Is current content visible for logged user OR for everyone? - * - * @return bool - */ - public function isVisible() - { - return $this->isPublic() || $this->isProtected(); - } /** * Mark relationship with its historical records @@ -119,16 +76,4 @@ class Content extends Model { return $this->belongsTo(Category::class); } - - public function save(array $options = []) - { - $saved = parent::save($options); - - // fire event about creating new content page - if ($this->wasRecentlyCreated) { - Event::fire(new CreateNewContent($this)); - } - - return $saved; - } } diff --git a/app/Models/Content/ModelTraits/Content.php b/app/Models/Content/ModelTraits/Content.php index 6780e5d5..16069185 100644 --- a/app/Models/Content/ModelTraits/Content.php +++ b/app/Models/Content/ModelTraits/Content.php @@ -1,24 +1,20 @@ select('contents.*') - ->with('author') - ->join('modules', 'modules.handler', '=', 'contents.module_handler') - ->where(function ($query) { - $query->where('published_from', '<', Carbon::now()) - ->orWhereNull('published_from'); - }) - ->where(function ($query) { - $query->where('published_to', '>', Carbon::now()) - ->orWhereNull('published_to'); - }) - ->where('language', LaravelLocalization::getCurrentLocale()) - ->where('modules.enabled', true); + return $this->status == IContent::STATUS_DRAFT; } /** - * Getter for homepage content page - * @return Content + * Is current content visible for all visitors? + * + * @return bool */ - public function getHomepage() + public function isPublic() { - return $this->getPageQuery() - ->where('is_homepage', 1) - ->first(); + return $this->status == IContent::STATUS_PUBLIC; } /** - * Getter for any page specified by its url. + * Is current content visible only for logged users? * - * @param $url - * - * @return Content + * @return bool */ - public function getByURL($url) + public function isProtected() { - return $this->getPageQuery() - ->where('url', $url) - ->first(); + return $this->status == IContent::STATUS_PROTECTED; + } + + /** + * Is current content visible for logged user OR for everyone? + * + * @return bool + */ + public function isVisible() + { + return $this->isPublic() || $this->isProtected(); } /** @@ -122,53 +112,6 @@ trait Content { return $rootPages->get(); } - /** - * Getter for overview of all content pages. - * These content pages may be filtered by using some handler - * - * @param bool $handler - * @param bool $status - * @param bool $joinAuthor - * @param bool $joinParent - * - * @return - */ - public function getOverview($handler = false, $status = false, $joinAuthor = false, $joinParent = false) - { - $query = DB::table('contents') - ->select('contents.*', 'modules.name AS module_name', 'modules.id AS module_id') - ->join('modules', 'modules.handler', '=', 'contents.module_handler') - ->whereNull('contents.deleted_at') - ->where('contents.language', LaravelLocalization::getCurrentLocale()) - ->where('modules.enabled', 1) - ->orderBy('created_at', 'DESC'); - - // filter results using handler - if ($handler) { - $query = $query->where('contents.module_handler', $handler); - } - - // join user email and user name to results when needed - if ($joinAuthor) { - $query = $query->join('users', 'users.id', '=', 'contents.user_id') - ->addSelect(DB::raw('COALESCE(users.name, users.email) AS author_name')) - ->addSelect('users.email AS author_email'); - } - - if ($joinParent) { - $query = $query->leftJoin('contents as parent', 'parent.id', '=', 'contents.parent_id') - ->addSelect('parent.title AS parent_title') - ->addSelect('parent.url AS parent_url'); - } - - // add filtering by status - if (in_array($status, ContentStatuses::getSimple())) { - $query = $query->where('contents.status', $status); - } - - return $query; - } - /** * Updates current model with information about changed columns * @@ -329,6 +272,7 @@ trait Content { return count($allFiles); } + /** * Save history entry into database * diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 05e764d4..fa711848 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,7 +2,8 @@ namespace App\Providers; -use App\CMS\Handlers\Registrators\MenuExtensionRegistrator; +use App\CMS\Contracts\Repositories\Content as IContent; +use App\CMS\Contracts\Repositories\Module as IModule; use App\CMS\Handlers\Registrators\SearchEngineRegistrator; use App\CMS\Handlers\Registrators\SettingsExtensionRegistrator; use App\CMS\Handlers\Registrators\TemplateRegistrator; @@ -11,10 +12,15 @@ use App\CMS\Handlers\Search\Content; use App\CMS\Handlers\Search\Files; use App\CMS\Handlers\Search\Presenters\AdminContent as AdminContentPresenter; use App\CMS\Handlers\Search\Presenters\AdminFiles; +use App\CMS\Repositories\Content\Content as ContentRepository; +use App\CMS\Repositories\Module as ModuleRepository; use App\CMS\Widgets\HtmlCode\HtmlCode; use App\CMS\Widgets\Menu\Menu; +use Barryvdh\Debugbar\ServiceProvider as DebugBarServiceProvider; use Illuminate\Support\Facades\App; use Illuminate\Support\ServiceProvider; +use Pingpong\Menus\MenusServiceProvider; +use Pingpong\Modules\ModulesServiceProvider; class AppServiceProvider extends ServiceProvider { @@ -32,6 +38,9 @@ class AppServiceProvider extends ServiceProvider $this->registerWidgets(); $this->registerSettings(); $this->registerSearch(); + + $this->app->bind(IContent::class, ContentRepository::class); + $this->app->bind(IModule::class, ModuleRepository::class); } /** @@ -40,19 +49,13 @@ class AppServiceProvider extends ServiceProvider */ public function register() { - if ($this->app->environment() == 'local') { - try { - $this->app->register('Barryvdh\Debugbar\ServiceProvider'); - } catch (\Exception $e) { - // this service provider may not exist when switching from other environment than local - // until composer install is run - // just ignore this exception and when no service provider is available, do not use debugbar - } + if ($this->app->environment() == 'local' && class_exists(DebugBarServiceProvider::class)) { + $this->app->register(DebugBarServiceProvider::class); } // register PingPong module extension - $this->app->register('Pingpong\Modules\ModulesServiceProvider'); - $this->app->register('Pingpong\Menus\MenusServiceProvider'); + $this->app->register(ModulesServiceProvider::class); + $this->app->register(MenusServiceProvider::class); $this->app->register(LaravelLocalizationServiceProvider::class); // create singletons for registering widgets diff --git a/resources/views/admin/content/overview.blade.php b/resources/views/admin/content/overview.blade.php index 5ba1c021..697f6970 100644 --- a/resources/views/admin/content/overview.blade.php +++ b/resources/views/admin/content/overview.blade.php @@ -3,8 +3,8 @@ @section('pageHeading', @trans(isset($pageHeading) ? $pageHeading : 'admin/contents.overview')) @section('headerButtons') - @if($module) - + @if($module->exists === true) + @endif @@ -21,7 +21,7 @@ @endif - @if (count($pages)) + @if (count($pages) > 0)
@@ -58,8 +58,8 @@ @if($page->is_homepage) @lang('admin/contents.homepage') @endif
- isPublic()) tag-success + @elseif ($page->isDraft()) tag-danger @else tag-warning @endif">{{$statuses[$page->status]}}
@@ -98,16 +98,16 @@ - @if($page->status == \App\Models\Content\Content::STATUS_DRAFT) + @if($page->isDraft())
  • -
  • - @@ -121,7 +121,7 @@
  • - @@ -136,16 +136,6 @@ class="fa fa-trash-o">
  • - - - {{--
  • --}} - {{-- --}} - {{--
  • --}} - {{--
  • --}} - {{-- --}} - {{--
  • --}}