parent
4b7e83b3e9
commit
438d39efe0
@ -1,35 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
declare(strict_types=1); |
|
||||||
|
|
||||||
/* For licensing terms, see /license.txt */ |
|
||||||
|
|
||||||
namespace Chamilo\CoreBundle\DataProvider; |
|
||||||
|
|
||||||
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; |
|
||||||
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; |
|
||||||
use Chamilo\CoreBundle\Component\Utils\NameConvention; |
|
||||||
use Chamilo\CoreBundle\Entity\User; |
|
||||||
use Chamilo\CoreBundle\Repository\Node\UserRepository; |
|
||||||
|
|
||||||
class UserItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface |
|
||||||
{ |
|
||||||
public function __construct( |
|
||||||
private readonly UserRepository $repository, |
|
||||||
private readonly NameConvention $nameConvention |
|
||||||
) {} |
|
||||||
|
|
||||||
public function getItem(string $resourceClass, $id, ?string $operationName = null, array $context = []): ?object |
|
||||||
{ |
|
||||||
$user = $this->repository->find($id); |
|
||||||
|
|
||||||
$this->nameConvention->getPersonName($user); |
|
||||||
|
|
||||||
return $user; |
|
||||||
} |
|
||||||
|
|
||||||
public function supports(string $resourceClass, ?string $operationName = null, array $context = []): bool |
|
||||||
{ |
|
||||||
return User::class === $resourceClass; |
|
||||||
} |
|
||||||
} |
|
@ -0,0 +1,49 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\CoreBundle\State; |
||||||
|
|
||||||
|
use ApiPlatform\Doctrine\Orm\Paginator; |
||||||
|
use ApiPlatform\Doctrine\Orm\State\CollectionProvider; |
||||||
|
use ApiPlatform\Doctrine\Orm\State\ItemProvider; |
||||||
|
use ApiPlatform\Metadata\CollectionOperationInterface; |
||||||
|
use ApiPlatform\Metadata\Operation; |
||||||
|
use ApiPlatform\State\ProviderInterface; |
||||||
|
use Chamilo\CoreBundle\Component\Utils\NameConvention; |
||||||
|
use Chamilo\CoreBundle\Entity\User; |
||||||
|
|
||||||
|
/** |
||||||
|
* @template-implements ProviderInterface<User> |
||||||
|
*/ |
||||||
|
class UserProvider implements ProviderInterface |
||||||
|
{ |
||||||
|
public function __construct( |
||||||
|
private readonly ItemProvider $itemProvider, |
||||||
|
private readonly CollectionProvider $collectionProvider, |
||||||
|
private readonly NameConvention $nameConvention |
||||||
|
) {} |
||||||
|
|
||||||
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null |
||||||
|
{ |
||||||
|
if ($operation instanceof CollectionOperationInterface) { |
||||||
|
$providedUsers = $this->collectionProvider->provide($operation, $uriVariables, $context); |
||||||
|
|
||||||
|
assert($providedUsers instanceof Paginator); |
||||||
|
|
||||||
|
/** @var User $user */ |
||||||
|
foreach ($providedUsers as $user) { |
||||||
|
$this->nameConvention->getPersonName($user); |
||||||
|
} |
||||||
|
|
||||||
|
return $providedUsers; |
||||||
|
} |
||||||
|
|
||||||
|
/** @var User $user */ |
||||||
|
$user = $this->itemProvider->provide($operation, $uriVariables, $context); |
||||||
|
|
||||||
|
$this->nameConvention->getPersonName($user); |
||||||
|
|
||||||
|
return $user; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue