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,25 +10,35 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use Exception;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\Db;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Topics query for GraphQL API
|
||||
*/
|
||||
class _Topics
|
||||
class Topics
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of topics";
|
||||
public static string $description = "Returns a list of topics";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -49,7 +59,7 @@ class _Topics
|
||||
'type' => TypeRegistry::eNum([
|
||||
'name' => 'forums_fluid_order_by',
|
||||
'description' => 'Fields on which topics can be sorted',
|
||||
'values' => \IPS\forums\api\GraphQL\Types\TopicType::getOrderByOptions()
|
||||
'values' => TopicType::getOrderByOptions()
|
||||
]),
|
||||
'defaultValue' => NULL // will use default sort option
|
||||
],
|
||||
@@ -70,8 +80,10 @@ class _Topics
|
||||
|
||||
/**
|
||||
* Return the query return type
|
||||
*
|
||||
* @return ListOfType<TopicType>
|
||||
*/
|
||||
public function type()
|
||||
public function type() : ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\forums\api\GraphQL\TypeRegistry::topic() );
|
||||
}
|
||||
@@ -79,30 +91,31 @@ class _Topics
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Topic
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return ActiveRecordIterator
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info ) : ActiveRecordIterator
|
||||
{
|
||||
\IPS\forums\Forum::loadIntoMemory('view', \IPS\Member::loggedIn() );
|
||||
Forum::loadIntoMemory('view', Member::loggedIn() );
|
||||
|
||||
$where = array( 'container' => array( array( 'forums_forums.password IS NULL' ) ) );
|
||||
$forumIDs = [];
|
||||
|
||||
/* Are we filtering by forums? */
|
||||
if( isset( $args['forums'] ) && \count( $args['forums'] ) )
|
||||
if( isset( $args['forums'] ) && count( $args['forums'] ) )
|
||||
{
|
||||
foreach( $args['forums'] as $id )
|
||||
{
|
||||
$forum = \IPS\forums\Forum::loadAndCheckPerms( $id );
|
||||
$forum = Forum::loadAndCheckPerms( $id );
|
||||
$forumIDs[] = $forum->id;
|
||||
}
|
||||
|
||||
if( \count( $forumIDs ) )
|
||||
if( count( $forumIDs ) )
|
||||
{
|
||||
$where['container'][] = array( \IPS\Db::i()->in( 'forums_forums.id', array_filter( $forumIDs ) ) );
|
||||
$where['container'][] = array( Db::i()->in( 'forums_forums.id', array_filter( $forumIDs ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,30 +128,30 @@ class _Topics
|
||||
}
|
||||
else
|
||||
{
|
||||
$orderBy = \IPS\forums\Topic::$databaseColumnMap[ $args['orderBy'] ];
|
||||
$orderBy = Topic::$databaseColumnMap[ $args['orderBy'] ];
|
||||
}
|
||||
|
||||
if( $args['orderBy'] === 'last_comment' )
|
||||
{
|
||||
$orderBy = \is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
|
||||
$orderBy = is_array( $orderBy ) ? array_pop( $orderBy ) : $orderBy;
|
||||
}
|
||||
}
|
||||
catch (\Exception $e)
|
||||
catch (Exception $e)
|
||||
{
|
||||
$orderBy = 'last_post';
|
||||
}
|
||||
|
||||
$sortBy = \IPS\forums\Topic::$databaseTable . '.' . \IPS\forums\Topic::$databasePrefix . "{$orderBy} {$args['orderDir']}";
|
||||
$sortBy = Topic::$databaseTable . '.' . Topic::$databasePrefix . "{$orderBy} {$args['orderDir']}";
|
||||
$offset = max( $args['offset'], 0 );
|
||||
$limit = min( $args['limit'], 50 );
|
||||
|
||||
/* Figure out pinned status */
|
||||
if ( $args['honorPinned'] )
|
||||
{
|
||||
$column = \IPS\forums\Topic::$databaseTable . '.' . \IPS\forums\Topic::$databasePrefix . \IPS\forums\Topic::$databaseColumnMap['pinned'];
|
||||
$column = Topic::$databaseTable . '.' . Topic::$databasePrefix . Topic::$databaseColumnMap['pinned'];
|
||||
$sortBy = "{$column} DESC, {$sortBy}";
|
||||
}
|
||||
|
||||
return \IPS\forums\Topic::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ), 'read' );
|
||||
return Topic::getItemsWithPermission( $where, $sortBy, array( $offset, $limit ), 'read' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user