|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Silverback\ApiComponentBundle\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
9
|
|
|
use Doctrine\Common\Collections\Collection; |
|
10
|
|
|
use PHPCR\RepositoryException; |
|
11
|
|
|
use Silverback\ApiComponentBundle\Entity\Content\AbstractContent; |
|
12
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @method AbstractContent|null find($id, $lockMode = null, $lockVersion = null) |
|
16
|
|
|
* @method AbstractContent|null findOneBy(array $criteria, array $orderBy = null) |
|
17
|
|
|
* @method AbstractContent[] findAll() |
|
18
|
|
|
* @method AbstractContent[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
19
|
|
|
*/ |
|
20
|
|
|
class ContentRepository extends ServiceEntityRepository |
|
21
|
|
|
{ |
|
22
|
|
|
private $registry; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(RegistryInterface $registry) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->registry = $registry; |
|
27
|
|
|
parent::__construct($registry, AbstractContent::class); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function findPageByType(string $entityClass): Collection |
|
31
|
|
|
{ |
|
32
|
|
|
if (!is_subclass_of($entityClass, AbstractContent::class)) { |
|
33
|
|
|
throw new RepositoryException(substr('The entity class must be a subclass of %s', AbstractContent::class)); |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
$childRepository = new ServiceEntityRepository($this->registry, $entityClass); |
|
36
|
|
|
$result = new ArrayCollection($childRepository->findAll()); |
|
37
|
|
|
|
|
38
|
|
|
$uow = $childRepository->getEntityManager()->getUnitOfWork(); |
|
39
|
|
|
$scheduledInsertions = $uow->getScheduledEntityInsertions(); |
|
40
|
|
|
foreach ($scheduledInsertions as $scheduledInsertion) { |
|
41
|
|
|
if (is_a($scheduledInsertion, $entityClass)) { |
|
42
|
|
|
$result->add($scheduledInsertion); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
return $result; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|