Skip to content

Instantly share code, notes, and snippets.

View kaugustanec's full-sized avatar
🎯
Focusing

Karlo Augustanec kaugustanec

🎯
Focusing
  • Zagreb, Croatia
View GitHub Profile
<?php
namespace App\Doctrine;
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
use App\Entity\BusinessUnit;
use Doctrine\ORM\QueryBuilder;
@kaugustanec
kaugustanec / LibraryUnitRepository.php
Last active February 17, 2025 13:16
Repository function to recursively fetch descendant unit IDs given a parent ID provided
final public function fetchAllChildUnitUUIDs(string $parentId): array
{
$connection = $this->entityManager->getConnection();
$sql = '
WITH RECURSIVE library_unit_hierarchy AS (
SELECT lu.id, lu.parent_uuid, 0 AS depth
FROM library_unit bu
WHERE lu.id = :parentId
@kaugustanec
kaugustanec / LibraryUnitGetChildUnitsStateProvider.php
Created February 17, 2025 13:05
Example how to configure a state provider to fetch all of the descendant units
readonly class LibraryUnitGetChildUnitsStateProvider implements ProviderInterface
{
/**
* @param ProviderInterface<CollectionProvider> $itemProvider
*/
public function __construct(
#[Autowire(service: 'api_platform.doctrine.orm.state.collection_provider')]
private ProviderInterface $itemProvider,
private LibraryUnitRepository $unitRepository,
) {