1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\NodeSearchBundle\Helper; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
6
|
|
|
use Kunstmaan\PagePartBundle\Entity\PagePartRef; |
7
|
|
|
use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; |
8
|
|
|
use Kunstmaan\SearchBundle\Helper\IndexableInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class IndexablePagePartsService |
12
|
|
|
* |
13
|
|
|
* Quick & dirty for now, needs to be in a generic PagePartService without static call & |
14
|
|
|
* without passing EntityManager as param... |
15
|
|
|
*/ |
16
|
|
|
class IndexablePagePartsService |
17
|
|
|
{ |
18
|
|
|
/** @var EntityManagerInterface */ |
19
|
|
|
private $em; |
20
|
|
|
|
21
|
|
|
/** @var [] */ |
22
|
|
|
private $contexts; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* IndexablePagePartsService constructor. |
26
|
|
|
* |
27
|
|
|
* @param EntityManagerInterface $em |
28
|
|
|
* @param [] $contexts |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
public function __construct(EntityManagerInterface $em, $contexts = []) |
31
|
|
|
{ |
32
|
|
|
$this->em = $em; |
33
|
|
|
$this->contexts = $contexts; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns all indexable pageparts for the specified page and context |
38
|
|
|
* |
39
|
|
|
* @param HasPagePartsInterface $page |
40
|
|
|
* @param string $context |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function getIndexablePageParts(HasPagePartsInterface $page, $context = 'main') |
45
|
|
|
{ |
46
|
|
|
$contexts = array_unique(array_merge($this->contexts, [$context])); |
47
|
|
|
|
48
|
|
|
$indexablePageParts = []; |
49
|
|
|
foreach ($contexts as $context) { |
50
|
|
|
$pageParts = $this->em |
|
|
|
|
51
|
|
|
->getRepository(PagePartRef::class) |
52
|
|
|
->getPageParts($page, $context); |
53
|
|
|
|
54
|
|
|
foreach ($pageParts as $pagePart) { |
55
|
|
|
if ($pagePart instanceof IndexableInterface && !$pagePart->isIndexable()) { |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
$indexablePageParts[] = $pagePart; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $indexablePageParts; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.