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,31 +10,36 @@
|
||||
*/
|
||||
|
||||
namespace IPS\forums\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\InputObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\forums\api\GraphQL\Types\TopicType;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Poll\Api\GraphQL\PollMutator;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vote in poll mutation for GraphQL API
|
||||
*/
|
||||
class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
class VoteInPoll extends PollMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\forums\Topic';
|
||||
protected string $class = 'IPS\forums\Topic';
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Vote in a poll in a topic";
|
||||
public static string $description = "Vote in a poll in a topic";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -57,8 +62,10 @@ class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*
|
||||
* @return TopicType
|
||||
*/
|
||||
public function type()
|
||||
public function type() : TopicType
|
||||
{
|
||||
return \IPS\forums\api\GraphQL\TypeRegistry::topic();
|
||||
}
|
||||
@@ -66,27 +73,26 @@ class _VoteInPoll extends \IPS\Poll\Api\GraphQL\PollMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\forums\Forum
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @return Topic
|
||||
*/
|
||||
public function resolve($val, $args)
|
||||
public function resolve( mixed $val, array $args ) : Topic
|
||||
{
|
||||
/* Get topic */
|
||||
try
|
||||
{
|
||||
$topic = \IPS\forums\Topic::loadAndCheckPerms( $args['itemID'] );
|
||||
$topic = Topic::loadAndCheckPerms( $args['itemID'] );
|
||||
$poll = $topic->getPoll();
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_TOPIC', 'GQL/0006/1', 403 );
|
||||
throw new SafeException( 'INVALID_TOPIC', 'GQL/0006/1', 403 );
|
||||
}
|
||||
|
||||
if( !$topic->can('read') || $poll === NULL )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POLL', 'GQL/0006/2', 403 );
|
||||
throw new SafeException( 'NO_POLL', 'GQL/0006/2', 403 );
|
||||
}
|
||||
|
||||
$this->_vote( $poll, $args['poll'] );
|
||||
|
||||
Reference in new issue
Block a user