@@ -42,30 +42,18 @@ public function findByContent(?Content $content): array
4242 if (null === $ content ) {
4343 return [];
4444 }
45- $ contentIds = $ this ->repository ->sudo (
46- function (Repository $ repository ) use ($ content ) {
47- $ ids = [$ content ->id ];
48- $ locations = $ repository ->getLocationService ()->loadLocations ($ content ->contentInfo );
49- foreach ($ locations as $ location ) {
50- /** @var Location $location */
51- $ parent = $ repository ->getLocationService ()->loadLocation ($ location ->parentLocationId );
52- $ ids [] = $ parent ->contentInfo ->id ;
53- }
54-
55- return $ ids ;
56- }
57- );
45+ $ contentIds = $ this ->getContentIds ($ content );
5846
5947 $ entityRepository = $ this ->entityManager ->getRepository ($ this ->getEntityClass ());
6048
6149 $ qb = $ entityRepository ->createQueryBuilder ($ this ->getAlias ());
62-
6350 $ qb ->where ($ qb ->expr ()->eq ($ this ->getAlias ().'.enabled ' , true ));
6451 $ qb ->andWhere (
6552 $ qb ->expr ()->in ($ this ->getAlias ().'.contentId ' , ':contentIds ' )
6653 );
6754 $ qb ->setParameter ('contentIds ' , $ contentIds );
6855 $ results = $ qb ->getQuery ()->getResult ();
56+
6957 $ filteredResults = [];
7058 foreach ($ results as $ protection ) {
7159 /** @var ProtectedAccess $protection */
@@ -82,4 +70,37 @@ function (Repository $repository) use ($content) {
8270
8371 return $ filteredResults ;
8472 }
73+
74+ /**
75+ * Retourne les ContentID du contenu et de tous ces descendants en prenant en compte ses multiples emplacements.
76+ * @param Content $content
77+ * @return array
78+ */
79+ protected function getContentIds (Content $ content ): array
80+ {
81+ return $ this ->repository ->sudo (
82+ function (Repository $ repository ) use ($ content ) {
83+ $ ids = [$ content ->id ];
84+ $ locations = $ repository ->getLocationService ()->loadLocations ($ content ->contentInfo );
85+ $ ct = 0 ;
86+ foreach ($ locations as $ location ) {
87+ /** @var Location $loc */
88+ $ loc = $ location ;
89+ while ($ loc ->parentLocationId
90+ && ($ loc = $ repository ->getLocationService ()->loadLocation ($ loc ->parentLocationId ))
91+ && $ loc instanceof Location
92+ && $ loc ->parentLocationId
93+ && $ loc ->parentLocationId !== 1
94+ ) {
95+ $ ct ++;
96+ $ ids [] = $ loc ->getContentInfo ()->id ;
97+ if ($ ct >= 15 ) {
98+ break (2 );
99+ }
100+ }
101+ }
102+ return $ ids ;
103+ }
104+ );
105+ }
85106}
0 commit comments