-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(NodeTree): Use Doctrine DTO to optimize node-tree walking in bac…
…koffice
- Loading branch information
1 parent
6c11340
commit 15aad4a
Showing
27 changed files
with
782 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
lib/RoadizCoreBundle/src/ListManager/NodeTreeDtoListManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\ListManager; | ||
|
||
use RZ\Roadiz\CoreBundle\Entity\Node; | ||
use RZ\Roadiz\CoreBundle\Model\NodeTreeDto; | ||
use RZ\Roadiz\CoreBundle\Repository\StatusAwareRepository; | ||
use Symfony\Component\DependencyInjection\Attribute\Exclude; | ||
|
||
#[Exclude] | ||
final class NodeTreeDtoListManager extends EntityListManager | ||
{ | ||
protected function createPaginator(): void | ||
{ | ||
$this->paginator = new NodeTreeDtoPaginator( | ||
$this->entityManager, | ||
Node::class, | ||
$this->itemPerPage, | ||
$this->filteringArray | ||
); | ||
$this->paginator->setTranslation($this->translation); | ||
$this->paginator->setDisplayingNotPublishedNodes($this->isDisplayingNotPublishedNodes()); | ||
$this->paginator->setDisplayingAllNodesStatuses($this->isDisplayingAllNodesStatuses()); | ||
} | ||
|
||
/** | ||
* @return array<NodeTreeDto> | ||
*/ | ||
public function getEntities(): array | ||
{ | ||
if ($this->pagination === true && null !== $this->paginator) { | ||
$this->paginator->setItemsPerPage($this->getItemPerPage()); | ||
// @phpstan-ignore-next-line | ||
return $this->paginator->findByAtPage($this->orderingArray, $this->currentPage); | ||
} else { | ||
$repository = $this->entityManager->getRepository(Node::class); | ||
if ($repository instanceof StatusAwareRepository) { | ||
$repository->setDisplayingNotPublishedNodes($this->isDisplayingNotPublishedNodes()); | ||
$repository->setDisplayingAllNodesStatuses($this->isDisplayingAllNodesStatuses()); | ||
} | ||
return $repository->findByAsNodeTreeDto( | ||
$this->filteringArray, | ||
$this->orderingArray, | ||
$this->itemPerPage | ||
); | ||
} | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
lib/RoadizCoreBundle/src/ListManager/NodeTreeDtoPaginator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RZ\Roadiz\CoreBundle\ListManager; | ||
|
||
use RZ\Roadiz\Core\AbstractEntities\TranslationInterface; | ||
use RZ\Roadiz\CoreBundle\Entity\Node; | ||
use RZ\Roadiz\CoreBundle\Model\NodeTreeDto; | ||
use RZ\Roadiz\CoreBundle\Repository\NodeRepository; | ||
use Symfony\Component\DependencyInjection\Attribute\Exclude; | ||
|
||
/** | ||
* A paginator class to filter node entities with limit and search. | ||
* | ||
* This class add some translation and security filters | ||
* | ||
*/ | ||
#[Exclude] | ||
class NodeTreeDtoPaginator extends Paginator | ||
{ | ||
protected ?TranslationInterface $translation = null; | ||
|
||
public function getTranslation(): ?TranslationInterface | ||
{ | ||
return $this->translation; | ||
} | ||
|
||
public function setTranslation(TranslationInterface $translation = null): self | ||
{ | ||
$this->translation = $translation; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @param array $order | ||
* @param int $page | ||
* @return array<NodeTreeDto> | ||
*/ | ||
public function findByAtPage(array $order = [], int $page = 1): array | ||
{ | ||
$repository = $this->getRepository(); | ||
if (null !== $this->searchPattern) { | ||
return $repository->searchByAsNodeTreeDto( | ||
$this->searchPattern, | ||
$this->criteria, | ||
$order, | ||
$this->getItemsPerPage(), | ||
$this->getItemsPerPage() * ($page - 1) | ||
); | ||
} else { | ||
return $repository->findByAsNodeTreeDto( | ||
$this->criteria, | ||
$order, | ||
$this->getItemsPerPage(), | ||
$this->getItemsPerPage() * ($page - 1), | ||
$this->getTranslation() | ||
); | ||
} | ||
} | ||
|
||
public function getTotalCount(): int | ||
{ | ||
if (null === $this->totalCount) { | ||
if (null !== $this->searchPattern) { | ||
$this->totalCount = $this->getRepository() | ||
->countSearchBy($this->searchPattern, $this->criteria); | ||
} else { | ||
$this->totalCount = $this->getRepository()->countBy( | ||
$this->criteria, | ||
$this->getTranslation() | ||
); | ||
} | ||
} | ||
|
||
return $this->totalCount; | ||
} | ||
|
||
// @phpstan-ignore-next-line | ||
protected function getRepository(): NodeRepository | ||
{ | ||
$repository = $this->em->getRepository(Node::class); | ||
$repository->setDisplayingNotPublishedNodes($this->isDisplayingNotPublishedNodes()); | ||
$repository->setDisplayingAllNodesStatuses($this->isDisplayingAllNodesStatuses()); | ||
return $repository; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.