parent
a3d52579f3
commit
5ffaf25e9e
@ -0,0 +1,59 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\CoreBundle\Framework\Container; |
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Overblog\GraphQLBundle\Definition\Argument; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
|
||||
/** |
||||
* Class UserResolver |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class UserResolver implements ResolverInterface, AliasedInterface |
||||
{ |
||||
public const IMAGE_SIZE_TINY = 16; |
||||
public const IMAGE_SIZE_SMALL = 32; |
||||
public const IMAGE_SIZE_MEDIUM = 64; |
||||
public const IMAGE_SIZE_BIG = 128; |
||||
|
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases(): array |
||||
{ |
||||
return [ |
||||
'resolveUserPicture' => 'user_picture', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param int $size |
||||
* @param \ArrayObject $context |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function resolveUserPicture($size, \ArrayObject $context): string |
||||
{ |
||||
/** @var User $user */ |
||||
$user = $context->offsetGet('user'); |
||||
|
||||
if (!$user) { |
||||
return null; |
||||
} |
||||
|
||||
$path = $user->getAvatarOrAnonymous((int) $size); |
||||
$url = Container::getAsset()->getUrl($path); |
||||
|
||||
return $url; |
||||
} |
||||
} |
@ -0,0 +1,35 @@ |
||||
UserStatus: |
||||
type: enum |
||||
config: |
||||
description: "One of the statuses for the user." |
||||
values: |
||||
TEACHER: |
||||
description: "Global status of a user: Course Manager." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::TEACHER")' |
||||
SESSION_ADMIN: |
||||
description: "Global status of a user: Session Admin." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::SESSION_ADMIN")' |
||||
DRH: |
||||
description: "Global status of a user: Human Ressource Manager." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::DRH")' |
||||
STUDENT: |
||||
description: "Global status of a user: Student." |
||||
value: '@=constant("Chamilo\\UserBundle\\Entity\\User::STUDENT")' |
||||
|
||||
UserImageSize: |
||||
type: enum |
||||
config: |
||||
description: 'One of the sizes for the user picture.' |
||||
values: |
||||
SIZE_TINY: |
||||
description: 'Image in small size: 16px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_TINY")' |
||||
SIZE_SMALL: |
||||
description: 'Image in small size: 32px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_SMALL")' |
||||
SIZE_MEDIUM: |
||||
description: 'Image in small size: 64px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_MEDIUM")' |
||||
SIZE_BIG: |
||||
description: 'Image in small size: 128px.' |
||||
value: '@=constant("Chamilo\\ApiBundle\\GraphQL\\Resolver\\UserResolver::IMAGE_SIZE_BIG")' |
Loading…
Reference in new issue