Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -10,20 +10,26 @@
|
||||
|
||||
namespace IPS\core\api\GraphQL\Queries;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\core\api\GraphQL\Types\ClubType;
|
||||
use IPS\Db;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_int;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER[ 'SERVER_PROTOCOL' ] ) ? $_SERVER[ 'SERVER_PROTOCOL' ] : 'HTTP/1.0' ).' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ).' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Club query for GraphQL API
|
||||
*/
|
||||
class _Clubs
|
||||
class Clubs
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
@@ -49,7 +55,7 @@ class _Clubs
|
||||
'type' => TypeRegistry::eNum( [
|
||||
'name' => 'clubs_order_by',
|
||||
'description' => 'Fields on which topics can be sorted',
|
||||
'values' => \IPS\core\api\GraphQL\Types\ClubType::getOrderByOptions()
|
||||
'values' => ClubType::getOrderByOptions()
|
||||
] ),
|
||||
'defaultValue' => NULL // will use default sort option
|
||||
],
|
||||
@@ -70,7 +76,7 @@ class _Clubs
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type(): \GraphQL\Type\Definition\ListOfType
|
||||
public function type(): ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\core\api\GraphQL\TypeRegistry::club() );
|
||||
}
|
||||
@@ -78,19 +84,19 @@ class _Clubs
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\Patterns\ActiveRecordIterator[\IPS\Member\Club]
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @return ActiveRecordIterator[\IPS\Member\Club]
|
||||
*/
|
||||
public function resolve( mixed $val, array $args, array $context ): \IPS\Patterns\ActiveRecordIterator
|
||||
public function resolve( mixed $val, array $args, array $context ): ActiveRecordIterator
|
||||
{
|
||||
$where = [];
|
||||
$sortBy = ( isset( $args['orderBy'] ) and \in_array( $args['orderBy'], \IPS\core\api\GraphQL\Types\ClubType::getOrderByOptions() ) ) ? $args['orderBy'] : 'name';
|
||||
$sortDir = ( isset( $args['orderDir'] ) and \in_array( mb_strtolower( $args['orderDir'] ), array( 'asc', 'desc' ) ) ) ? $args['orderDir'] : 'desc';
|
||||
$limit =( isset( $args['orderDir'] ) and \is_int( $args['limit'] ) ) ? $args['limit'] : 25;
|
||||
$sortBy = ( isset( $args['orderBy'] ) and in_array( $args['orderBy'], ClubType::getOrderByOptions() ) ) ? $args['orderBy'] : 'name';
|
||||
$sortDir = ( isset( $args['orderDir'] ) and in_array( mb_strtolower( $args['orderDir'] ), array( 'asc', 'desc' ) ) ) ? $args['orderDir'] : 'desc';
|
||||
$limit =( isset( $args['orderDir'] ) and is_int( $args['limit'] ) ) ? $args['limit'] : 25;
|
||||
|
||||
$query = \IPS\Db::i()->select( '*', 'core_clubs', $where, "{$sortBy} {$sortDir}", $limit );
|
||||
return new \IPS\Patterns\ActiveRecordIterator( $query, '\IPS\Member\Club' );
|
||||
$query = Db::i()->select( '*', 'core_clubs', $where, "{$sortBy} {$sortDir}", $limit );
|
||||
return new ActiveRecordIterator( $query, '\IPS\Member\Club' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user