2022-03-13 19:32:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Core\Controller\Site;
|
|
|
|
|
|
|
|
use App\Core\Controller\Admin\AdminController;
|
|
|
|
use App\Core\Entity\Site\Navigation;
|
|
|
|
use App\Core\Factory\Site\MenuFactory;
|
|
|
|
use App\Core\Form\Site\MenuType;
|
|
|
|
use App\Core\Repository\Site\NavigationRepositoryQuery;
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
use Symfony\Component\HttpFoundation\Session\Session;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
|
2022-11-19 19:35:28 +01:00
|
|
|
#[Route(path: '/admin/site/tree')]
|
2022-03-13 19:32:32 +01:00
|
|
|
class TreeAdminController extends AdminController
|
|
|
|
{
|
2022-11-19 19:35:28 +01:00
|
|
|
#[Route(path: '/', name: 'admin_site_tree_index')]
|
2022-03-13 19:32:32 +01:00
|
|
|
public function index(NavigationRepositoryQuery $navigationQuery, Session $session): Response
|
|
|
|
{
|
|
|
|
$navigation = null;
|
|
|
|
|
|
|
|
if ($session->has('site_tree_last_navigation')) {
|
|
|
|
$navigation = $navigationQuery->create()
|
|
|
|
->filterById((int) $session->get('site_tree_last_navigation'))
|
|
|
|
->findOne()
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null === $navigation) {
|
|
|
|
$navigation = $navigationQuery->create()
|
|
|
|
->orderBy('.sortOrder')
|
|
|
|
->findOne()
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (null === $navigation) {
|
|
|
|
$this->addFlash('warning', 'You must add a navigation.');
|
|
|
|
|
|
|
|
return $this->redirectToRoute('admin_site_navigation_new');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->redirectToRoute('admin_site_tree_navigation', [
|
|
|
|
'navigation' => $navigation->getId(),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-11-19 19:35:28 +01:00
|
|
|
#[Route(path: '/navigation/{navigation}', name: 'admin_site_tree_navigation')]
|
2022-03-13 19:32:32 +01:00
|
|
|
public function navigation(
|
|
|
|
Navigation $navigation,
|
|
|
|
NavigationRepositoryQuery $navigationQuery,
|
|
|
|
MenuFactory $menuFactory,
|
|
|
|
Session $session
|
|
|
|
): Response {
|
|
|
|
$navigations = $navigationQuery->create()
|
|
|
|
->orderBy('.sortOrder')
|
|
|
|
->find()
|
|
|
|
;
|
|
|
|
|
|
|
|
$session->set('site_tree_last_navigation', $navigation->getId());
|
|
|
|
|
|
|
|
$forms = [
|
|
|
|
'menu' => $this->createForm(MenuType::class, $menuFactory->create())->createView(),
|
|
|
|
'menus' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($navigation->getMenus() as $menu) {
|
|
|
|
$forms['menus'][$menu->getId()] = $this->createForm(MenuType::class, $menu)->createView();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('@Core/site/tree_admin/navigation.html.twig', [
|
|
|
|
'navigation' => $navigation,
|
|
|
|
'navigations' => $navigations,
|
|
|
|
'forms' => $forms,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSection(): string
|
|
|
|
{
|
|
|
|
return 'site_tree';
|
|
|
|
}
|
|
|
|
}
|