142 lines
4.4 KiB
PHP
142 lines
4.4 KiB
PHP
<?php
|
|
namespace Modules\Blog\Article\Handlers;
|
|
|
|
use App\Enumerations\ModulesHandlerToId;
|
|
use App\Handlers\Handler;
|
|
use App\Http\Controllers\Admin\EditContent;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Request;
|
|
use App\Models\Content;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Modules\Blog\Article\Entities\Comment;
|
|
|
|
class Article extends Handler
|
|
{
|
|
/**
|
|
* Render given module into visitor area.
|
|
*
|
|
* @param Content $content DB model from table contents
|
|
* @param array $parameters parameters used for modifications/custom settings of given model
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function render(Content $content, $parameters)
|
|
{
|
|
$content->comments = [];
|
|
if (isset($content->module_settings->allowComments) && $content->module_settings->allowComments) {
|
|
$content->comments = Comment::where('content_id', $content->id)
|
|
->where('approved', 1)
|
|
->orderBy('created_at')
|
|
->get();
|
|
}
|
|
|
|
return Controller::VisitorsView($content->template, ['page' => $content, 'extra' => $parameters]);
|
|
}
|
|
|
|
public static function getExtendedFormInputsCreate()
|
|
{
|
|
$sections = parent::getExtendedFormInputsCreate();
|
|
|
|
$sections['basicInfo'] = 'article::admin.content.basicInfo';
|
|
|
|
return $sections;
|
|
}
|
|
|
|
public static function getExtendedFormInputsEdit()
|
|
{
|
|
return self::getExtendedFormInputsCreate();
|
|
}
|
|
|
|
/**
|
|
* Save module-specific values into database
|
|
*
|
|
* @param Content $content
|
|
* @param Request $request
|
|
*
|
|
* @return mixed
|
|
* @internal param Widget $widget
|
|
*/
|
|
public static function createNew(Content &$content, Request $request)
|
|
{
|
|
$content->module_settings = json_encode(['allowComments' => (int)$request->has('allowComments')]);
|
|
}
|
|
|
|
/**
|
|
* Method used for editing existing content page.
|
|
*
|
|
* Reason why it is separated from createNew() method is simple - we need to save history of changes.
|
|
*
|
|
* @param Content $content
|
|
* @param Request $request
|
|
*
|
|
* @param $revisionID string ID of revision used
|
|
*
|
|
* @return int number of edited fields
|
|
*/
|
|
public static function edit(Content &$content, Request $request, $revisionID)
|
|
{
|
|
$fields = ['allowComments' => 'allowComments'];
|
|
|
|
// get data and try to save them
|
|
$data = EditContent::getFields($request, $fields);
|
|
|
|
$data['allowComments'] = (int)$data['allowComments'];
|
|
|
|
list($revision, $changedColumns) = $content->updateWithHistory($fields, $data, $revisionID);
|
|
|
|
// return amount of changed columns
|
|
return $changedColumns;
|
|
}
|
|
|
|
public static function getOverviewTitle()
|
|
{
|
|
return trans('article::module.allArticles');
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param User $user
|
|
*/
|
|
public static function registerAdminMenu(User $user)
|
|
{
|
|
parent::registerAdminMenu($user);
|
|
|
|
$menu = \Menu::instance('mainMenu');
|
|
|
|
$blogSubmenu = $menu->whereTitle(trans('article::module.blog'));
|
|
if (!$blogSubmenu) {
|
|
$blogSubmenu = $menu->dropdown(trans('article::module.blog'), function ($sub) {
|
|
}, 20, ['icon' => 'fa fa-fw fa-book']);
|
|
}
|
|
|
|
$blogSubmenu->dropdown(trans('article::module.name'), function ($sub) {
|
|
$sub->route('content.new', trans('article::article.new'), ['id' => self::getModuleId()], 10, ['icon' => 'fa fa-fw fa-pencil']);
|
|
$sub->route('content.overview', trans('article::article.overview'), ['id' => self::getModuleId()], 30, ['icon' => 'fa fa-fw fa-book']);
|
|
}, 10, ['icon' => 'fa fa-fw fa-book']);
|
|
|
|
$blogSubmenu->dropdown(trans('article::module.comments'), function ($sub) {
|
|
$sub->route('comments.overview', trans('article::module.commentsOverview'), [], 10, ['icon' => 'fa fa-fw fa-commenting-o']);
|
|
}, 20, ['icon' => 'fa fa-fw fa-comments-o']);
|
|
}
|
|
|
|
public static function getModuleId()
|
|
{
|
|
$handler = config('article.handler');
|
|
$allModules = ModulesHandlerToId::getWithTranslations();
|
|
$moduleId = isset($allModules[$handler]) ? $allModules[$handler] : null;
|
|
|
|
return $moduleId;
|
|
}
|
|
|
|
/**
|
|
* Install module
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public static function install()
|
|
{
|
|
// seed action log types
|
|
// Artisan::call('')
|
|
}
|
|
} |