Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
101 changes: 30 additions & 71 deletions sources/Afup/Corporate/Branche.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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 '';
}

Expand All @@ -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 .= '<li' . $class . '>';
if ($this->navigation == 'image' && $feuille['image'] !== null) {
$extraction .= '<a href="' . $route . '"><img alt="' . $feuille['alt'] . '" src="' . Site::WEB_PATH . 'templates/site/images/' . $feuille['image'] . '" /><br>';
$extraction .= $feuille['nom'] . '</a><br>';
$extraction .= $feuille['alt'];
} else {
$extraction .= '<a href="' . $route . '">' . $feuille['nom'] . '</a>';
}
$extraction .= '</li>';
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 .= '<li' . $class . '>';
if ($this->navigation == 'image' && $feuille['image'] !== null) {
$extraction .= '<a href="' . $route . '"><img alt="' . $feuille['alt'] . '" src="' . Site::WEB_PATH . 'templates/site/images/' . $feuille['image'] . '" /><br>';
$extraction .= $feuille['nom'] . '</a><br>';
$extraction .= $feuille['alt'];
} else {
$extraction .= '<a href="' . $route . '">' . $feuille['nom'] . '</a>';
}
$extraction .= '</li>';
if ($profondeur > 0) {
$extraction .= $this->naviguer($feuille['id'], $profondeur - 1);
}
}

Expand Down
33 changes: 14 additions & 19 deletions sources/Afup/Corporate/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<ul>';

$feuillesEnfants = $branche->feuillesEnfants(Feuille::ID_FEUILLE_HEADER);
$feuillesEnfants = iterator_to_array($this->sheetRepository->getActiveChildrenByParentId(Feuille::ID_FEUILLE_HEADER));

if ($user instanceof UserInterface) {
$feuillesEnfants[] = [
Expand Down Expand Up @@ -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;
}
Expand All @@ -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");
}
}
6 changes: 3 additions & 3 deletions sources/AppBundle/Controller/Website/Global/HomeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,15 +33,15 @@ public function __construct(
private readonly TalkRepository $talkRepository,
#[Autowire('%home_algolia_enabled%')]
private readonly bool $homeAlgoliaEnabled,
private readonly SheetRepository $sheetRepository,
) {}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions sources/AppBundle/Controller/Website/SecondaryMenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

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;
use Symfony\Component\HttpFoundation\Response;

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',
Expand All @@ -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 = [];

Expand Down
29 changes: 29 additions & 0 deletions sources/AppBundle/Site/Model/Repository/SheetRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
Loading