GraphQL Add query for user sessions #2644
parent
6f47f4492f
commit
9798310e5a
@ -0,0 +1,56 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CoreBundle\Entity\SessionCategory; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class SessionCategoryResolver |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class SessionCategoryResolver implements ResolverInterface, AliasedInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases(): array |
||||
{ |
||||
return [ |
||||
'resolveStartDate' => 'sessioncategory_startdate', |
||||
'resolveEndDate' => 'sessioncategory_enddate', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param SessionCategory $category |
||||
* |
||||
* @return \DateTime |
||||
*/ |
||||
public function resolveStartDate(SessionCategory $category): \DateTime |
||||
{ |
||||
return $category->getDateStart(); |
||||
} |
||||
|
||||
/** |
||||
* @param SessionCategory $category |
||||
* |
||||
* @return \DateTime |
||||
*/ |
||||
public function resolveEndDate(SessionCategory $category): \DateTime |
||||
{ |
||||
return $category->getDateEnd(); |
||||
} |
||||
} |
@ -0,0 +1,71 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Resolver; |
||||
|
||||
use Chamilo\ApiBundle\GraphQL\ApiGraphQLTrait; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\AliasedInterface; |
||||
use Overblog\GraphQLBundle\Definition\Resolver\ResolverInterface; |
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
||||
|
||||
/** |
||||
* Class SessionResolver |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Resolver |
||||
*/ |
||||
class SessionResolver implements ResolverInterface, AliasedInterface, ContainerAwareInterface |
||||
{ |
||||
use ApiGraphQLTrait; |
||||
|
||||
/** |
||||
* Returns methods aliases. |
||||
* |
||||
* For instance: |
||||
* array('myMethod' => 'myAlias') |
||||
* |
||||
* @return array |
||||
*/ |
||||
public static function getAliases(): array |
||||
{ |
||||
return [ |
||||
'resolveDescription' => 'session_description', |
||||
'resolveNumberCourses' => 'session_nbrcourses', |
||||
'resolveNumberUsers' => 'session_nbrusers', |
||||
]; |
||||
} |
||||
|
||||
/** |
||||
* @param Session $session |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function resolveDescription(Session $session): string |
||||
{ |
||||
if (false === $session->getShowDescription()) { |
||||
return ''; |
||||
} |
||||
|
||||
return $session->getDescription(); |
||||
} |
||||
|
||||
/** |
||||
* @param Session $session |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function resolveNumberCourses(Session $session): int |
||||
{ |
||||
return $session->getNbrCourses(); |
||||
} |
||||
|
||||
/** |
||||
* @param Session $session |
||||
* |
||||
* @return int |
||||
*/ |
||||
public function resolveNumberUsers(Session $session): int |
||||
{ |
||||
return $session->getNbrUsers(); |
||||
} |
||||
} |
Loading…
Reference in new issue