44
55namespace Afup \Site \Corporate ;
66
7- use Afup \Site \Utils \Base_De_Donnees ;
7+ use AppBundle \Site \Model \Repository \SheetRepository ;
8+ use AppBundle \Site \Model \Sheet ;
9+ use CCMBenchmark \Ting \Repository \Collection ;
810
911class Branche
1012{
1113 public $ navigation = 'nom ' ;
1214
13- /**
14- * @var Base_De_Donnees
15- */
16- protected $ bdd ;
17-
18- public function __construct ($ bdd = false )
19- {
20- $ this ->bdd = $ bdd ?: new _Site_Base_De_Donnees ();
21- }
15+ public function __construct (private readonly SheetRepository $ sheetRepository ) {}
2216
2317 public function navigation_avec_image ($ bool = false ): void
2418 {
@@ -29,13 +23,8 @@ public function navigation_avec_image($bool = false): void
2923
3024 public function naviguer ($ id , $ profondeur = 1 , string $ identification = "" ): string
3125 {
32- $ requete = 'SELECT *
33- FROM afup_site_feuille
34- WHERE id = ' . $ this ->bdd ->echapper ($ id ) . '
35- AND etat = 1 ' ;
36- $ racine = $ this ->bdd ->obtenirEnregistrement ($ requete );
37-
38- if ($ racine === false ) {
26+ $ racine = $ this ->sheetRepository ->getOneBy (['id ' => $ id , 'state ' => 1 ]);
27+ if (!$ racine instanceof Sheet) {
3928 return '' ;
4029 }
4130
@@ -52,36 +41,31 @@ public function naviguer($id, $profondeur = 1, string $identification = ""): str
5241 public function extraireFeuilles ($ id , $ profondeur ): string
5342 {
5443 $ extraction = '' ;
44+ $ sheets = $ this ->sheetRepository ->getActiveChildrenByParentIdOrderedByPostion ($ id );
45+ if (!$ sheets instanceof Collection) {
46+ return $ extraction ;
47+ }
5548
56- $ requete = 'SELECT *
57- FROM afup_site_feuille
58- WHERE id_parent = ' . $ this ->bdd ->echapper ($ id ) . '
59- AND etat = 1
60- ORDER BY position ' ;
61- $ feuilles = $ this ->bdd ->obtenirTous ($ requete );
62-
63- if (is_array ($ feuilles )) {
64- foreach ($ feuilles as $ feuille ) {
65- $ class = "" ;
66- if ($ extraction === "" ) {
67- $ class = ' class="top" ' ;
68- }
69- $ route = match (true ) {
70- preg_match ('#^http://# ' , (string ) $ feuille ['lien ' ]), preg_match ('#^/# ' , (string ) $ feuille ['lien ' ]) => $ feuille ['lien ' ],
71- default => Site::WEB_PATH . Site::WEB_PREFIX . Site::WEB_QUERY_PREFIX . $ feuille ['lien ' ],
72- };
73- $ extraction .= '<li ' . $ class . '> ' ;
74- if ($ this ->navigation == 'image ' && $ feuille ['image ' ] !== null ) {
75- $ extraction .= '<a href=" ' . $ route . '"><img alt=" ' . $ feuille ['alt ' ] . '" src=" ' . Site::WEB_PATH . 'templates/site/images/ ' . $ feuille ['image ' ] . '" /><br> ' ;
76- $ extraction .= $ feuille ['nom ' ] . '</a><br> ' ;
77- $ extraction .= $ feuille ['alt ' ];
78- } else {
79- $ extraction .= '<a href=" ' . $ route . '"> ' . $ feuille ['nom ' ] . '</a> ' ;
80- }
81- $ extraction .= '</li> ' ;
82- if ($ profondeur > 0 ) {
83- $ extraction .= $ this ->naviguer ($ feuille ['id ' ], $ profondeur - 1 );
84- }
49+ foreach ($ sheets as $ feuille ) {
50+ $ class = "" ;
51+ if ($ extraction === "" ) {
52+ $ class = ' class="top" ' ;
53+ }
54+ $ route = match (true ) {
55+ preg_match ('#^http://# ' , (string ) $ feuille ['lien ' ]), preg_match ('#^/# ' , (string ) $ feuille ['lien ' ]) => $ feuille ['lien ' ],
56+ default => Site::WEB_PATH . Site::WEB_PREFIX . Site::WEB_QUERY_PREFIX . $ feuille ['lien ' ],
57+ };
58+ $ extraction .= '<li ' . $ class . '> ' ;
59+ if ($ this ->navigation == 'image ' && $ feuille ['image ' ] !== null ) {
60+ $ extraction .= '<a href=" ' . $ route . '"><img alt=" ' . $ feuille ['alt ' ] . '" src=" ' . Site::WEB_PATH . 'templates/site/images/ ' . $ feuille ['image ' ] . '" /><br> ' ;
61+ $ extraction .= $ feuille ['nom ' ] . '</a><br> ' ;
62+ $ extraction .= $ feuille ['alt ' ];
63+ } else {
64+ $ extraction .= '<a href=" ' . $ route . '"> ' . $ feuille ['nom ' ] . '</a> ' ;
65+ }
66+ $ extraction .= '</li> ' ;
67+ if ($ profondeur > 0 ) {
68+ $ extraction .= $ this ->naviguer ($ feuille ['id ' ], $ profondeur - 1 );
8569 }
8670 }
8771
0 commit comments