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'] . '
'; - $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'] . '
'; + $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 = '