diff --git a/app/config/services.yml b/app/config/services.yml
index 40b1aea6c..19dc72993 100644
--- a/app/config/services.yml
+++ b/app/config/services.yml
@@ -164,6 +164,12 @@ services:
Afup\Site\Association\CotisationsFactory:
autowire: true
+ Afup\Site\Corporate\Branche:
+ autowire: true
+
+ Afup\Site\Corporate\Page:
+ autowire: true
+
Afup\Site\Forum\Facturation:
autowire: true
diff --git a/sources/Afup/Corporate/Branche.php b/sources/Afup/Corporate/Branche.php
index a85245988..ec82d9667 100644
--- a/sources/Afup/Corporate/Branche.php
+++ b/sources/Afup/Corporate/Branche.php
@@ -4,21 +4,15 @@
namespace Afup\Site\Corporate;
-use Afup\Site\Utils\Base_De_Donnees;
+use AppBundle\Site\Model\Repository\SheetRepository;
+use AppBundle\Site\Model\Sheet;
+use CCMBenchmark\Ting\Repository\Collection;
class Branche
{
public $navigation = 'nom';
- /**
- * @var Base_De_Donnees
- */
- protected $bdd;
-
- public function __construct($bdd = false)
- {
- $this->bdd = $bdd ?: new _Site_Base_De_Donnees();
- }
+ public function __construct(private readonly SheetRepository $sheetRepository) {}
public function navigation_avec_image($bool = false): void
{
@@ -27,40 +21,10 @@ public function navigation_avec_image($bool = false): void
}
}
- public function feuillesEnfants($id)
- {
- $requete = 'SELECT *
- FROM afup_site_feuille
- WHERE id_parent = ' . $this->bdd->echapper($id) . '
- AND etat = 1
- ORDER BY position';
- return $this->bdd->obtenirTous($requete);
- }
-
- public function getNom($id)
- {
- $requete = 'SELECT nom
- FROM afup_site_feuille
- WHERE id = ' . $this->bdd->echapper($id) . '
- AND etat = 1';
- $enregistrement = $this->bdd->obtenirEnregistrement($requete);
-
- if (false === $enregistrement) {
- return null;
- }
-
- return $enregistrement['nom'];
- }
-
public function naviguer($id, $profondeur = 1, string $identification = ""): string
{
- $requete = 'SELECT *
- FROM afup_site_feuille
- WHERE id = ' . $this->bdd->echapper($id) . '
- AND etat = 1';
- $racine = $this->bdd->obtenirEnregistrement($requete);
-
- if ($racine === false) {
+ $racine = $this->sheetRepository->getOneBy(['id' => $id, 'state' => 1]);
+ if (!$racine instanceof Sheet) {
return '';
}
@@ -77,36 +41,31 @@ public function naviguer($id, $profondeur = 1, string $identification = ""): str
public function extraireFeuilles($id, $profondeur): string
{
$extraction = '';
+ $sheets = $this->sheetRepository->getActiveChildrenByParentIdOrderedByPostion($id);
+ if (!$sheets instanceof Collection) {
+ return $extraction;
+ }
- $requete = 'SELECT *
- FROM afup_site_feuille
- WHERE id_parent = ' . $this->bdd->echapper($id) . '
- AND etat = 1
- ORDER BY position';
- $feuilles = $this->bdd->obtenirTous($requete);
-
- if (is_array($feuilles)) {
- foreach ($feuilles as $feuille) {
- $class = "";
- if ($extraction === "") {
- $class = ' class="top"';
- }
- $route = match (true) {
- preg_match('#^http://#', (string) $feuille['lien']), preg_match('#^/#', (string) $feuille['lien']) => $feuille['lien'],
- default => Site::WEB_PATH . Site::WEB_PREFIX . Site::WEB_QUERY_PREFIX . $feuille['lien'],
- };
- $extraction .= '
';
- if ($this->navigation == 'image' && $feuille['image'] !== null) {
- $extraction .= '![' . $feuille['alt'] . '](' . Site::WEB_PATH . 'templates/site/images/' . $feuille['image'] . ')
';
- $extraction .= $feuille['nom'] . '
';
- $extraction .= $feuille['alt'];
- } else {
- $extraction .= '' . $feuille['nom'] . '';
- }
- $extraction .= '';
- if ($profondeur > 0) {
- $extraction .= $this->naviguer($feuille['id'], $profondeur - 1);
- }
+ foreach ($sheets as $feuille) {
+ $class = "";
+ if ($extraction === "") {
+ $class = ' class="top"';
+ }
+ $route = match (true) {
+ preg_match('#^http://#', (string) $feuille['lien']), preg_match('#^/#', (string) $feuille['lien']) => $feuille['lien'],
+ default => Site::WEB_PATH . Site::WEB_PREFIX . Site::WEB_QUERY_PREFIX . $feuille['lien'],
+ };
+ $extraction .= '';
+ if ($this->navigation == 'image' && $feuille['image'] !== null) {
+ $extraction .= '![' . $feuille['alt'] . '](' . Site::WEB_PATH . 'templates/site/images/' . $feuille['image'] . ')
';
+ $extraction .= $feuille['nom'] . '
';
+ $extraction .= $feuille['alt'];
+ } else {
+ $extraction .= '' . $feuille['nom'] . '';
+ }
+ $extraction .= '';
+ if ($profondeur > 0) {
+ $extraction .= $this->naviguer($feuille['id'], $profondeur - 1);
}
}
diff --git a/sources/Afup/Corporate/Page.php b/sources/Afup/Corporate/Page.php
index 94f127ec1..e055dd24b 100644
--- a/sources/Afup/Corporate/Page.php
+++ b/sources/Afup/Corporate/Page.php
@@ -4,24 +4,22 @@
namespace Afup\Site\Corporate;
+use AppBundle\Site\Model\Repository\SheetRepository;
use Symfony\Component\Security\Core\User\UserInterface;
final readonly class Page
{
- private _Site_Base_De_Donnees $bdd;
-
- public function __construct()
- {
- $this->bdd = new _Site_Base_De_Donnees();
- }
+ public function __construct(
+ private SheetRepository $sheetRepository,
+ private Branche $branch,
+ ) {}
public function header($url = null, UserInterface $user = null): string
{
- $branche = new Branche($this->bdd);
$url = urldecode((string) $url);
$str = '';
- $feuillesEnfants = $branche->feuillesEnfants(Feuille::ID_FEUILLE_HEADER);
+ $feuillesEnfants = iterator_to_array($this->sheetRepository->getActiveChildrenByParentId(Feuille::ID_FEUILLE_HEADER));
if ($user instanceof UserInterface) {
$feuillesEnfants[] = [
@@ -72,9 +70,9 @@ public function header($url = null, UserInterface $user = null): string
}
if (false === $isCurrent) {
- $enfants = $branche->feuillesEnfants($feuille['id']);
+ $enfants = $this->sheetRepository->getActiveChildrenByParentId($feuille['id']);
foreach ($enfants as $feuilleEnfant) {
- foreach ($branche->feuillesEnfants($feuilleEnfant['id']) as $feuillesEnfant2) {
+ foreach ($this->sheetRepository->getActiveChildrenByParentId($feuilleEnfant['id']) as $feuillesEnfant2) {
if (str_contains($url, (string) $feuillesEnfant2['lien'])) {
$isCurrent = true;
}
@@ -99,23 +97,20 @@ public function header($url = null, UserInterface $user = null): string
*/
public function footer(): array
{
- $branche = new Branche($this->bdd);
-
$footerColumns = [];
- foreach ($branche->feuillesEnfants(Feuille::ID_FEUILLE_FOOTER) as $feuilleColonne) {
+ foreach ($this->sheetRepository->getActiveChildrenByParentId(Feuille::ID_FEUILLE_FOOTER) as $feuilleColonne) {
$footerColumns[] = [
- 'nom' => $branche->getNom($feuilleColonne['id']),
- 'items' => $branche->feuillesEnfants($feuilleColonne['id']),
+ 'nom' => $feuilleColonne['nom'],
+ 'items' => $this->sheetRepository->getActiveChildrenByParentId($feuilleColonne['id']),
];
}
return $footerColumns;
}
- public function getRightColumn(): Branche
+ public function getRightColumn(): string
{
- $branche = new Branche($this->bdd);
- $branche->navigation_avec_image(true);
- return $branche;
+ $this->branch->navigation_avec_image(true);
+ return $this->branch->naviguer(1, 2, "externe");
}
}
diff --git a/sources/AppBundle/Controller/Website/Global/HomeAction.php b/sources/AppBundle/Controller/Website/Global/HomeAction.php
index 9d56e9b73..5bbd11bbe 100644
--- a/sources/AppBundle/Controller/Website/Global/HomeAction.php
+++ b/sources/AppBundle/Controller/Website/Global/HomeAction.php
@@ -5,13 +5,13 @@
namespace AppBundle\Controller\Website\Global;
use Afup\Site\Corporate\Articles;
-use Afup\Site\Corporate\Branche;
use Afup\Site\Corporate\Feuille;
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
use Algolia\AlgoliaSearch\SearchClient;
use AppBundle\Event\Model\Meetup;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Talk;
+use AppBundle\Site\Model\Repository\SheetRepository;
use AppBundle\Twig\ViewRenderer;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
@@ -33,6 +33,7 @@ public function __construct(
private readonly TalkRepository $talkRepository,
#[Autowire('%home_algolia_enabled%')]
private readonly bool $homeAlgoliaEnabled,
+ private readonly SheetRepository $sheetRepository,
) {}
public function __invoke(): Response
@@ -40,8 +41,7 @@ public function __invoke(): Response
$articles = new Articles();
$derniers_articles = $articles->chargerDerniersAjouts(self::MAX_ARTICLES);
- $branche = new Branche();
- $enfants = $branche->feuillesEnfants(Feuille::ID_FEUILLE_COLONNE_DROITE);
+ $enfants = iterator_to_array($this->sheetRepository->getActiveChildrenByParentId(Feuille::ID_FEUILLE_COLONNE_DROITE));
$premiereFeuille = array_shift($enfants);
$deuxiemeFeuille = array_shift($enfants);
diff --git a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php
index 112cce9ea..7c17d605f 100644
--- a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php
+++ b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php
@@ -4,12 +4,12 @@
namespace AppBundle\Controller\Website\Global;
-use Afup\Site\Corporate\Branche;
use Afup\Site\Corporate\Feuille;
use AppBundle\Association\Model\Repository\CompanyMemberRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Talk;
use AppBundle\Site\Model\Repository\ArticleRepository;
+use AppBundle\Site\Model\Repository\SheetRepository;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
@@ -21,24 +21,23 @@ public function __construct(
private readonly CompanyMemberRepository $companyMemberRepository,
private readonly ArticleRepository $articleRepository,
private readonly TalkRepository $talkRepository,
+ private readonly SheetRepository $sheetRepository,
) {}
public function __invoke(): Response
{
- $branche = new Branche();
-
return $this->view->render('site/sitemap.html.twig', [
- 'pages' => $this->buildLeafs($branche, Feuille::ID_FEUILLE_HEADER),
- 'association' => $this->buildLeafs($branche, Feuille::ID_FEUILLE_ANTENNES),
+ 'pages' => $this->buildLeafs(Feuille::ID_FEUILLE_HEADER),
+ 'association' => $this->buildLeafs(Feuille::ID_FEUILLE_ANTENNES),
'members' => $this->members(),
'news' => $this->news(),
'talks' => $this->talks(),
]);
}
- private function buildLeafs(Branche $branche, int $id): array
+ private function buildLeafs(int $id): array
{
- $leafs = $branche->feuillesEnfants($id);
+ $leafs = $this->sheetRepository->getActiveChildrenByParentId($id);
$pages = [];
foreach ($leafs as $leaf) {
diff --git a/sources/AppBundle/Controller/Website/SecondaryMenuController.php b/sources/AppBundle/Controller/Website/SecondaryMenuController.php
index b98e7fa76..aaa8aa35b 100644
--- a/sources/AppBundle/Controller/Website/SecondaryMenuController.php
+++ b/sources/AppBundle/Controller/Website/SecondaryMenuController.php
@@ -4,7 +4,8 @@
namespace AppBundle\Controller\Website;
-use Afup\Site\Corporate\Branche;
+use AppBundle\Site\Model\Repository\SheetRepository;
+use CCMBenchmark\Ting\Repository\CollectionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -12,12 +13,14 @@
class SecondaryMenuController extends AbstractController
{
- public function __construct(private readonly RequestStack $requestStack) {}
+ public function __construct(
+ private readonly RequestStack $requestStack,
+ private readonly SheetRepository $sheetRepository,
+ ) {}
public function display(Request $request): Response
{
- $branche = new Branche();
- $menu = $branche->feuillesEnfants($request->get('feuille_id'));
+ $menu = $this->sheetRepository->getActiveChildrenByParentId($request->get('feuille_id'));
return $this->render(
'site/secondary_menu.html.twig',
@@ -30,7 +33,7 @@ public function display(Request $request): Response
/**
* @return mixed[]
*/
- protected function prepareMenu(Request $masterRequest, array $menu): array
+ protected function prepareMenu(Request $masterRequest, CollectionInterface $menu): array
{
$preparedMenu = [];
diff --git a/sources/AppBundle/Site/Model/Repository/SheetRepository.php b/sources/AppBundle/Site/Model/Repository/SheetRepository.php
index ade705925..b3da563ea 100644
--- a/sources/AppBundle/Site/Model/Repository/SheetRepository.php
+++ b/sources/AppBundle/Site/Model/Repository/SheetRepository.php
@@ -5,6 +5,7 @@
namespace AppBundle\Site\Model\Repository;
use AppBundle\Site\Model\Sheet;
+use Aura\SqlQuery\Common\SelectInterface;
use CCMBenchmark\Ting\Exception;
use CCMBenchmark\Ting\Query\QueryException;
use CCMBenchmark\Ting\Repository\CollectionInterface;
@@ -49,6 +50,34 @@ public function getAllSheets(string $ordre = 'date', string $direction = 'desc',
return $query->query($this->getCollection(new HydratorArray()));
}
+ public function getActiveChildrenByParentId(int $parentId): CollectionInterface
+ {
+ $queryBuilder = $this->getActiveChildrenByParentIdBuilder();
+
+ $query = $this->getPreparedQuery($queryBuilder->getStatement())->setParams(['parentId' => $parentId]);
+ return $query->query($this->getCollection(new HydratorArray()));
+ }
+
+ public function getActiveChildrenByParentIdOrderedByPostion(int $parentId): CollectionInterface
+ {
+ $queryBuilder = $this->getActiveChildrenByParentIdBuilder();
+ $queryBuilder->orderBy(['position', 'asc']);
+
+ $query = $this->getPreparedQuery($queryBuilder->getStatement())->setParams(['parentId' => $parentId]);
+ return $query->query($this->getCollection(new HydratorArray()));
+ }
+
+ private function getActiveChildrenByParentIdBuilder(): SelectInterface
+ {
+ /**
+ * @var SelectInterface $queryBuilder
+ */
+ $queryBuilder = $this->getQueryBuilder(self::QUERY_SELECT);
+ $queryBuilder->cols(['*'])->from('afup_site_feuille')->where('id_parent = :parentId')->where('etat = 1');
+
+ return $queryBuilder;
+ }
+
/**
* @inheritDoc
*/
diff --git a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php
index 81d83f231..b6603bc94 100644
--- a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php
+++ b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php
@@ -4,7 +4,6 @@
namespace AppBundle\Subscriber;
-use Afup\Site\Corporate\Branche;
use Afup\Site\Corporate\Feuille;
use AppBundle\Association\Model\CompanyMember;
use AppBundle\Association\Model\Repository\CompanyMemberRepository;
@@ -17,6 +16,7 @@
use AppBundle\Event\Model\Talk;
use AppBundle\Site\Model\Article;
use AppBundle\Site\Model\Repository\ArticleRepository;
+use AppBundle\Site\Model\Repository\SheetRepository;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
use Presta\SitemapBundle\Service\UrlContainerInterface;
use Presta\SitemapBundle\Sitemap\Url\GoogleVideo;
@@ -34,6 +34,7 @@ public function __construct(
private readonly EventRepository $eventRepository,
private readonly ArticleRepository $articleRepository,
private readonly CompanyMemberRepository $companyMemberRepository,
+ private readonly SheetRepository $sheetRepository,
) {}
public static function getSubscribedEvents(): array
@@ -194,9 +195,7 @@ private function registerDefaultPages(UrlContainerInterface $urls): void
private function fromFeuilleId(int $id, UrlContainerInterface $urls): void
{
- $branche = new Branche();
-
- $leafs = $branche->feuillesEnfants($id);
+ $leafs = $this->sheetRepository->getActiveChildrenByParentId($id);
foreach ($leafs as $leaf) {
if (!$leaf['lien'] || !str_starts_with((string) $leaf['lien'], 'http')) {
continue;
diff --git a/sources/AppBundle/Twig/ViewRenderer.php b/sources/AppBundle/Twig/ViewRenderer.php
index 45052e787..76079406b 100644
--- a/sources/AppBundle/Twig/ViewRenderer.php
+++ b/sources/AppBundle/Twig/ViewRenderer.php
@@ -16,6 +16,7 @@ public function __construct(
private readonly Security $security,
private readonly RequestStack $requestStack,
private readonly Environment $twig,
+ private readonly Page $page,
) {}
@@ -33,11 +34,10 @@ public function render(string $view, array $parameters = [], Response $response
$blocks = [];
if ($this->requestStack->getCurrentRequest()) {
$requestUri = $this->requestStack->getCurrentRequest()->getRequestUri();
- $page = new Page();
$blocks = [
- 'header' => $page->header($requestUri, $this->security->getUser()),
- 'sidebar' => $page->getRightColumn(),
- 'footer' => $page->footer(),
+ 'header' => $this->page->header($requestUri, $this->security->getUser()),
+ 'sidebar' => $this->page->getRightColumn(),
+ 'footer' => $this->page->footer(),
];
}
diff --git a/templates/site/base.html.twig b/templates/site/base.html.twig
index cdec80da9..58cd7f456 100644
--- a/templates/site/base.html.twig
+++ b/templates/site/base.html.twig
@@ -61,7 +61,7 @@