94 lines
2.8 KiB
PHP
94 lines
2.8 KiB
PHP
<?php
|
|
namespace Modules\StaticPages\Http\Controllers\Admin;
|
|
|
|
use App\Enumerations\ContentStatuses;
|
|
use App\Models\Content;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class EditStaticPage extends Controller
|
|
{
|
|
public function getEdit($id)
|
|
{
|
|
return view('staticpages::index');
|
|
}
|
|
|
|
/**
|
|
* 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();
|
|
unset($statuses[Content::STATUS_DELETED]);
|
|
|
|
// check if given status is valid
|
|
if (!isset($statuses[$status])) {
|
|
return redirect()
|
|
->route('staticpage.overview')
|
|
->with('error', trans('staticpages::admin.invalidStatus'));
|
|
}
|
|
|
|
try {
|
|
// try to find this page
|
|
$page = Content::where('module_handler', config('staticpages.handler'))
|
|
->findOrFail($id);
|
|
|
|
// page found, save status
|
|
$page->status = $status;
|
|
|
|
$page->save();
|
|
|
|
// redirect back to overview with info for user
|
|
return redirect()
|
|
->route('staticpage.overview')
|
|
->with('success', trans('staticpages::admin.statusChanged'));
|
|
} catch (NotFoundHttpException $e) {
|
|
// page not found
|
|
return redirect()
|
|
->route('staticpage.overview')
|
|
->with('error', trans('staticpages::admin.invalidPage'));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Delete page
|
|
*
|
|
* @param $id
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function deletePage($id)
|
|
{
|
|
try {
|
|
// try to find this page
|
|
$page = Content::where('module_handler', config('staticpages.handler'))
|
|
->findOrFail($id);
|
|
|
|
// page found, save status
|
|
$page->status = Content::STATUS_DELETED;
|
|
|
|
$page->save();
|
|
|
|
// redirect back to overview with info for user
|
|
return redirect()
|
|
->route('staticpage.overview')
|
|
->with('success', trans('staticpages::admin.pageDeleted', [
|
|
'name' => $page->title,
|
|
'url' => $page->url
|
|
]));
|
|
} catch (NotFoundHttpException $e) {
|
|
// page not found
|
|
return redirect()
|
|
->route('staticpage.overview')
|
|
->with('error', trans('staticpages::admin.invalidPage'));
|
|
}
|
|
}
|
|
} |