- Removed legacy Scontainers controller and view files, transitioning to a new controller structure. - Introduced ScontainersController to handle CRUD operations with improved dependency injection. - Created ScontainersRepository for database interactions, encapsulating logic for container management. - Updated container edit and list views to utilize new templating system. - Added unit tests for ScontainersRepository and ScontainersController to ensure functionality. - Enhanced form handling for container editing, including validation and error management.
118 lines
3.9 KiB
PHP
118 lines
3.9 KiB
PHP
<?php
|
|
namespace admin\controls;
|
|
class Pages
|
|
{
|
|
public static function pages_url_browser()
|
|
{
|
|
echo \Tpl::view( 'pages/pages-browse-list', [
|
|
'menus' => \admin\factory\Pages::menus_list(),
|
|
'modal' => \S::get( 'modal' )
|
|
] );
|
|
exit;
|
|
}
|
|
|
|
public static function browse_list()
|
|
{
|
|
return \admin\view\Pages::browse_list(
|
|
\admin\factory\Pages::menus_list()
|
|
);
|
|
}
|
|
|
|
public static function menu_delete()
|
|
{
|
|
if ( \admin\factory\Pages::menu_delete( \S::get( 'id' ) ) )
|
|
\S::set_message( 'Menu zostało usunięte.' );
|
|
else
|
|
\S::alert( 'Podczas usuwania menu wystąpił błąd. Aby usunąć menu nie może ono posiadać przypiętych stron.' );
|
|
header( 'Location: /admin/pages/view_list/' );
|
|
exit;
|
|
}
|
|
|
|
public static function page_delete()
|
|
{
|
|
if ( \admin\factory\Pages::page_delete( \S::get( 'id' ) ) )
|
|
\S::set_message( 'Strona została usunięta.' );
|
|
else
|
|
\S::alert( 'Podczas usuwania strony wystąpił błąd. Aby usunąć stronę nie może ona posiadać przypiętych podstron.' );
|
|
header( 'Location: /admin/pages/view_list/' );
|
|
exit;
|
|
}
|
|
|
|
public static function page_articles()
|
|
{
|
|
return \admin\view\Pages::page_articles( \S::get( 'id' ), \admin\factory\Pages::page_articles( \S::get( 'id' ) ) );
|
|
}
|
|
|
|
public static function page_save()
|
|
{
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania strony wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
$values = json_decode( \S::get( 'values' ), true );
|
|
|
|
if ( $id = \admin\factory\Pages::page_save(
|
|
$values['id'], $values['title'], $values['seo_link'], $values['meta_title'], $values['meta_description'], $values['meta_keywords'], $values['menu_id'], $values['parent_id'], $values['page_type'],
|
|
$values['sort_type'], $values['layout_id'], $values['articles_limit'], $values['show_title'], $values['status'], $values['link'], $values['noindex'], $values['start'], $values['page_title'],
|
|
$values['canonical'], $values['category_id']
|
|
) )
|
|
$response = [ 'status' => 'ok', 'msg' => 'Strona została zapisana.', 'id' => $id ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
public static function page_edit()
|
|
{
|
|
return \Tpl::view( 'pages/page-edit', [
|
|
'page' => \admin\factory\Pages::page_details( \S::get( 'id' ) ),
|
|
'parent_id' => \S::get( 'pid' ),
|
|
'menu_id' => \S::get( 'menu_id' ),
|
|
'menus' => \admin\factory\Pages::menu_lists(),
|
|
'layouts' => self::layouts_for_page_edit( $GLOBALS['mdb'] ),
|
|
'languages' => ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->languagesList()
|
|
] );
|
|
}
|
|
|
|
private static function layouts_for_page_edit( $db )
|
|
{
|
|
if ( class_exists( '\Domain\Layouts\LayoutsRepository' ) )
|
|
{
|
|
$rows = ( new \Domain\Layouts\LayoutsRepository( $db ) ) -> listAll();
|
|
return is_array( $rows ) ? $rows : [];
|
|
}
|
|
|
|
if ( class_exists( '\admin\factory\Layouts' ) )
|
|
{
|
|
$rows = \admin\factory\Layouts::layouts_list();
|
|
return is_array( $rows ) ? $rows : [];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
public static function menu_save()
|
|
{
|
|
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania menu wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
$values = json_decode( \S::get( 'values' ), true );
|
|
|
|
if ( \admin\factory\Pages::menu_save( $values['id'], $values['name'], $values['status'] ) )
|
|
$response = [ 'status' => 'ok', 'msg' => 'Menu zostało zapisane.' ];
|
|
|
|
echo json_encode( $response );
|
|
exit;
|
|
}
|
|
|
|
public static function menu_edit()
|
|
{
|
|
return \admin\view\Pages::menu_edit(
|
|
\admin\factory\Pages::menu_details( \S::get( 'id' ) )
|
|
);
|
|
}
|
|
|
|
public static function view_list()
|
|
{
|
|
return \Tpl::view( 'pages/pages-list', [
|
|
'menus' => \admin\factory\Pages::menus_list()
|
|
] );
|
|
}
|
|
}
|
|
?>
|