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,20 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\calendar\api\GraphQL\Mutations\CreateEvent;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog mutationss GraphQL API
|
||||
*/
|
||||
abstract class _Mutation
|
||||
abstract class Mutation
|
||||
{
|
||||
/**
|
||||
* Get the supported query types in this app
|
||||
@@ -32,9 +32,8 @@ abstract class _Mutation
|
||||
*/
|
||||
public static function mutations(): array
|
||||
{
|
||||
$return = [
|
||||
'createEvent' => new \IPS\calendar\api\GraphQL\Mutations\CreateEvent(),
|
||||
return [
|
||||
'createEvent' => new CreateEvent(),
|
||||
];
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -10,30 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\api\GraphQL\Types\EventType;
|
||||
use IPS\calendar\Calendar;
|
||||
use IPS\calendar\Event;
|
||||
use IPS\Content\Api\GraphQL\ItemMutator;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Member;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Event mutation for GraphQL API
|
||||
*/
|
||||
class _CreateEvent extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
class CreateEvent extends ItemMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = \IPS\calendar\Event::class;
|
||||
protected string $class = Event::class;
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Create a new calendar event";
|
||||
public static string $description = "Create a new calendar event";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -48,7 +56,7 @@ class _CreateEvent extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): EventType
|
||||
{
|
||||
return \IPS\calendar\api\GraphQL\TypeRegistry::event();
|
||||
}
|
||||
@@ -56,42 +64,43 @@ class _CreateEvent extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\calendar\Event
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Event
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): Item
|
||||
{
|
||||
/* Get calendar */
|
||||
try
|
||||
{
|
||||
$calendar = \IPS\calendar\Calendar::loadAndCheckPerms( $args['calendarID'] );
|
||||
$calendar = Calendar::loadAndCheckPerms( $args['calendarID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_CALENDAR', '1L296/6_graphql', 400 );
|
||||
throw new SafeException( 'NO_CALENDAR', '1L296/6_graphql', 400 );
|
||||
}
|
||||
|
||||
/* Check permission */
|
||||
if ( !$calendar->can( 'add', \IPS\Member::loggedIn() ) )
|
||||
if ( !$calendar->can( 'add', Member::loggedIn() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '1L296/7_graphql', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '1L296/7_graphql', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a title and a post */
|
||||
if ( !$args['title'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TITLE', '1L296/8_graphql', 400 );
|
||||
throw new SafeException( 'NO_TITLE', '1L296/8_graphql', 400 );
|
||||
}
|
||||
if ( !$args['content'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1L296/9_grapqhl', 400 );
|
||||
throw new SafeException( 'NO_POST', '1L296/9_grapqhl', 400 );
|
||||
}
|
||||
|
||||
if ( !$args['start'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_START', '1L296/A_grapqhl', 400 );
|
||||
throw new SafeException( 'INVALID_START', '1L296/A_grapqhl', 400 );
|
||||
}
|
||||
|
||||
return $this->_create( $args, $calendar, $args['postKey'] ?? NULL );
|
||||
|
||||
@@ -10,25 +10,28 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\api\GraphQL\Types\CalendarType;
|
||||
use IPS\calendar\Calendar as CalendarClass;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar query for GraphQL API
|
||||
*/
|
||||
class _calendar
|
||||
class Calendar
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a calendar";
|
||||
public static string $description = "Returns a calendar";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -43,7 +46,7 @@ class _calendar
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): CalendarType
|
||||
{
|
||||
return \IPS\calendar\api\GraphQL\TypeRegistry::calendar();
|
||||
}
|
||||
@@ -51,18 +54,19 @@ class _calendar
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\calendar\Calendar
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return CalendarClass
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array$args, array $context, array $info): CalendarClass
|
||||
{
|
||||
$calendar = \IPS\calendar\Calendar::load( $args['id'] );
|
||||
$calendar = CalendarClass::load( $args['id'] );
|
||||
|
||||
if( !$calendar->can( 'view', $context['member'] ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
return $calendar;
|
||||
}
|
||||
|
||||
@@ -10,25 +10,27 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\Calendar;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forums query for GraphQL API
|
||||
*/
|
||||
class _Calendars
|
||||
class Calendars
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of calendars";
|
||||
public static string $description = "Returns a list of calendars";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -43,7 +45,7 @@ class _Calendars
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\calendar\api\GraphQL\TypeRegistry::calendar() );
|
||||
}
|
||||
@@ -51,14 +53,15 @@ class _Calendars
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return array
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): array
|
||||
{
|
||||
\IPS\calendar\Calendar::loadIntoMemory('view', $context['member']);
|
||||
return \IPS\calendar\Calendar::roots();
|
||||
Calendar::loadIntoMemory('view', $context['member']);
|
||||
return Calendar::roots();
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,29 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Queries;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\api\GraphQL\Types\EventType;
|
||||
use IPS\calendar\Event as EventClass;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event query for GraphQL API
|
||||
*/
|
||||
class _Event
|
||||
class Event
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns an event";
|
||||
public static string $description = "Returns an event";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -43,7 +47,7 @@ class _Event
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): EventType
|
||||
{
|
||||
return \IPS\calendar\api\GraphQL\TypeRegistry::event();
|
||||
}
|
||||
@@ -51,25 +55,26 @@ class _Event
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\calendar\Event
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return EventClass
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): EventClass
|
||||
{
|
||||
try
|
||||
{
|
||||
$event = \IPS\calendar\Event::loadAndCheckPerms( $args['id'] );
|
||||
$event = EventClass::loadAndCheckPerms( $args['id'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_EVENT', '1F294/2_graphql', 400 );
|
||||
throw new SafeException( 'NO_EVENT', '1F294/2_graphql', 400 );
|
||||
}
|
||||
|
||||
if( !$event->can('read') )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_ID', '2F294/9_graphql', 403 );
|
||||
throw new SafeException( 'INVALID_ID', '2F294/9_graphql', 403 );
|
||||
}
|
||||
|
||||
return $event;
|
||||
|
||||
@@ -11,25 +11,34 @@
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Queries;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use GraphQL\Type\Definition\ListOfType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\api\GraphQL\Types\EventType;
|
||||
use IPS\calendar\Calendar;
|
||||
use IPS\calendar\Event;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar Events query for GraphQL API
|
||||
*/
|
||||
class _Events
|
||||
class Events
|
||||
{
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Returns a list of events";
|
||||
public static string $description = "Returns a list of events";
|
||||
|
||||
/*
|
||||
* Query arguments
|
||||
@@ -50,7 +59,7 @@ class _Events
|
||||
'type' => TypeRegistry::eNum( [
|
||||
'name' => 'events_order_by',
|
||||
'description' => 'Fields on which events can be sorted',
|
||||
'values' => \IPS\calendar\api\GraphQL\Types\EventType::getOrderByOptions(),
|
||||
'values' => EventType::getOrderByOptions(),
|
||||
] ),
|
||||
'defaultValue' => NULL, // will use default sort option
|
||||
],
|
||||
@@ -72,7 +81,7 @@ class _Events
|
||||
/**
|
||||
* Return the query return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): ListOfType
|
||||
{
|
||||
return TypeRegistry::listOf( \IPS\calendar\api\GraphQL\TypeRegistry::event() );
|
||||
}
|
||||
@@ -80,30 +89,31 @@ class _Events
|
||||
/**
|
||||
* Resolves this query
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\calendar\Event
|
||||
* @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
|
||||
{
|
||||
$where = [];
|
||||
\IPS\calendar\Calendar::loadIntoMemory( 'view', \IPS\Member::loggedIn() );
|
||||
Calendar::loadIntoMemory( 'view', Member::loggedIn() );
|
||||
|
||||
$calendarIDs = [];
|
||||
|
||||
/* Are we filtering by calendards? */
|
||||
if( isset( $args[ 'calendars' ] ) && \count( $args[ 'calendars' ] ) )
|
||||
if( isset( $args[ 'calendars' ] ) && count( $args[ 'calendars' ] ) )
|
||||
{
|
||||
foreach( $args[ 'calendars' ] as $id )
|
||||
{
|
||||
$calendar = \IPS\calendar\Calendar::loadAndCheckPerms( $id );
|
||||
$calendar = Calendar::loadAndCheckPerms( $id );
|
||||
$calendarIDs[] = $calendar->id;
|
||||
}
|
||||
|
||||
if( \count( $calendarIDs ) )
|
||||
if( count( $calendarIDs ) )
|
||||
{
|
||||
$where[ 'container' ][] = [ \IPS\Db::i()->in( 'calendar_events.event_calendar_id', array_filter( $calendarIDs ) ) ];
|
||||
$where[ 'container' ][] = [ Db::i()->in( 'calendar_events.event_calendar_id', array_filter( $calendarIDs ) ) ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,15 +123,15 @@ class _Events
|
||||
{
|
||||
$orderBy = 'saved';
|
||||
}
|
||||
else if( \in_array( $args[ 'orderBy' ], \IPS\calendar\api\GraphQL\Types\EventType::getOrderByOptions() ) )
|
||||
else if( in_array( $args[ 'orderBy' ], EventType::getOrderByOptions() ) )
|
||||
{
|
||||
$orderBy = $args[ 'orderBy' ];
|
||||
}
|
||||
|
||||
$sortBy = \IPS\calendar\Event::$databaseTable.'.'.\IPS\calendar\Event::$databasePrefix."{$orderBy} {$args['orderDir']}";
|
||||
$sortBy = Event::$databaseTable.'.'. Event::$databasePrefix."{$orderBy} {$args['orderDir']}";
|
||||
$offset = max( $args[ 'offset' ], 0 );
|
||||
$limit = min( $args[ 'limit' ], 50 );
|
||||
|
||||
return \IPS\calendar\Event::getItemsWithPermission( $where, $sortBy, [ $offset, $limit ], 'read' );
|
||||
return Event::getItemsWithPermission( $where, $sortBy, [ $offset, $limit ] );
|
||||
}
|
||||
}
|
||||
@@ -10,33 +10,36 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\calendar\api\GraphQL\Queries\Calendar;
|
||||
use IPS\calendar\api\GraphQL\Queries\Calendars;
|
||||
use IPS\calendar\api\GraphQL\Queries\Event;
|
||||
use IPS\calendar\api\GraphQL\Queries\Events;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Blog queries for GraphQL API
|
||||
*/
|
||||
abstract class _Query
|
||||
abstract class Query
|
||||
{
|
||||
/**
|
||||
* Get the supported query types in this app
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function queries()
|
||||
public static function queries(): array
|
||||
{
|
||||
return [
|
||||
'calendar' => new \IPS\calendar\api\GraphQL\Queries\Calendar(),
|
||||
'calendars' => new \IPS\calendar\api\GraphQL\Queries\Calendars(),
|
||||
'events' => new \IPS\calendar\api\GraphQL\Queries\Events(),
|
||||
'event' => new \IPS\calendar\api\GraphQL\Queries\Event(),
|
||||
'calendar' => new Calendar(),
|
||||
'calendars' => new Calendars(),
|
||||
'events' => new Events(),
|
||||
'event' => new Event(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,36 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\Types;
|
||||
use IPS\calendar\api\GraphQL\Types\CalendarType;
|
||||
use IPS\calendar\api\GraphQL\Types\CommentType;
|
||||
use IPS\calendar\api\GraphQL\Types\EventType;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
class _TypeRegistry
|
||||
class TypeRegistry
|
||||
{
|
||||
/**
|
||||
* The calendar type instance
|
||||
* @var \IPS\calendar\api\GraphQL\Types\CalendarType
|
||||
* @var CalendarType
|
||||
*/
|
||||
protected static $calendar;
|
||||
protected static CalendarType $calendar;
|
||||
|
||||
/**
|
||||
* The event type instance
|
||||
* @var \IPS\calendar\api\GraphQL\Types\EventType
|
||||
* @var EventType
|
||||
*/
|
||||
protected static $event;
|
||||
protected static EventType $event;
|
||||
|
||||
/**
|
||||
* The event comment instance
|
||||
* @var \IPS\calendar\api\GraphQL\Types\CalendarType
|
||||
* @var CommentType
|
||||
*/
|
||||
protected static $comment;
|
||||
protected static CommentType $comment;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -52,21 +54,21 @@ class _TypeRegistry
|
||||
/**
|
||||
* @return CalendarType
|
||||
*/
|
||||
public static function calendar() : \IPS\calendar\api\GraphQL\Types\CalendarType
|
||||
public static function calendar() : CalendarType
|
||||
{
|
||||
return self::$calendar ?: (self::$calendar = new \IPS\calendar\api\GraphQL\Types\CalendarType());
|
||||
return self::$calendar ?? (self::$calendar = new CalendarType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EventType
|
||||
*/
|
||||
public static function event() : \IPS\calendar\api\GraphQL\Types\EventType
|
||||
public static function event() : EventType
|
||||
{
|
||||
return self::$event ?: (self::$event = new \IPS\calendar\api\GraphQL\Types\EventType());
|
||||
return self::$event ?? (self::$event = new EventType());
|
||||
}
|
||||
|
||||
public static function comment() : \IPS\calendar\api\GraphQL\Types\CommentType
|
||||
public static function comment() : CommentType
|
||||
{
|
||||
return self::$comment ?: ( self::$comment = new \IPS\calendar\api\GraphQL\Types\CommentType() );
|
||||
return self::$comment ?? ( self::$comment = new CommentType() );
|
||||
}
|
||||
}
|
||||
@@ -11,39 +11,42 @@
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Types;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\Calendar;
|
||||
use IPS\Node\Api\GraphQL\NodeType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* CalendarType for GraphQL API
|
||||
*/
|
||||
class _CalendarType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
class CalendarType extends NodeType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $nodeClass = \IPS\calendar\Calendar::class;
|
||||
protected static string $nodeClass = Calendar::class;
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'calendar_Calendar';
|
||||
protected static string $typeName = 'calendar_Calendar';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A calendar';
|
||||
protected static string $typeDescription = 'A calendar';
|
||||
|
||||
/*
|
||||
* @brief Follow data passed in to FollowType resolver
|
||||
*/
|
||||
protected static $followData = array('app' => 'calendar', 'area' => 'calendar');
|
||||
protected static array $followData = array('app' => 'calendar', 'area' => 'calendar');
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,9 +54,9 @@ class _CalendarType extends \IPS\Node\Api\GraphQL\NodeType
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public static function getItemType()
|
||||
{
|
||||
return \IPS\calendar\api\GraphQL\TypeRegistry::event();
|
||||
public static function getItemType(): ObjectType
|
||||
{
|
||||
return TypeRegistry::event();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,43 +11,46 @@
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Types;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\Event\Comment;
|
||||
use IPS\Content\Api\GraphQL\CommentType as ApiCommentType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* PostType for GraphQL API
|
||||
*/
|
||||
class _CommentType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
class CommentType extends ApiCommentType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $commentClass = \IPS\calendar\Event\Comment::class;
|
||||
protected static string $commentClass = Comment::class;
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'calendar_Comment';
|
||||
protected static string $typeName = 'calendar_Comment';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A calendar event comment';
|
||||
protected static string $typeDescription = 'A calendar event comment';
|
||||
|
||||
/**
|
||||
* Get the item type that goes with this item type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
public static function getItemType()
|
||||
{
|
||||
return \IPS\calendar\api\GraphQL\TypeRegistry::comment();
|
||||
public static function getItemType(): ObjectType
|
||||
{
|
||||
return TypeRegistry::comment();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,12 +58,12 @@ class _CommentType extends \IPS\Content\Api\GraphQL\CommentType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
$defaultFields = parent::fields();
|
||||
$postFields = array(
|
||||
'event' => [
|
||||
'type' => \IPS\calendar\api\GraphQL\TypeRegistry::event(),
|
||||
'type' => TypeRegistry::event(),
|
||||
'resolve' => function ($comment) {
|
||||
return $comment->item();
|
||||
}
|
||||
|
||||
@@ -12,47 +12,49 @@
|
||||
namespace IPS\calendar\api\GraphQL\Types;
|
||||
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\_TypeRegistry;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\Event;
|
||||
use IPS\Content\Api\GraphQL\ItemType;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entry for GraphQL API
|
||||
*/
|
||||
class _EventType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
class EventType extends ItemType
|
||||
{
|
||||
/*
|
||||
* @brief The item classname we use for this type
|
||||
*/
|
||||
protected static $itemClass = \IPS\calendar\Event::class;
|
||||
protected static string $itemClass = Event::class;
|
||||
|
||||
/*
|
||||
* @brief GraphQL type name
|
||||
*/
|
||||
protected static $typeName = 'calendar_Event';
|
||||
protected static string $typeName = 'calendar_Event';
|
||||
|
||||
/*
|
||||
* @brief GraphQL type description
|
||||
*/
|
||||
protected static $typeDescription = 'A calendar event';
|
||||
protected static string $typeDescription = 'A calendar event';
|
||||
|
||||
/*
|
||||
* @brief Follow data passed in to FollowType resolver
|
||||
*/
|
||||
protected static $followData = array( 'app' => 'calendar', 'area' => 'event' );
|
||||
protected static array $followData = array( 'app' => 'calendar', 'area' => 'event' );
|
||||
|
||||
/**
|
||||
* Get the comment type that goes with this item type
|
||||
*
|
||||
* @return ObjectType
|
||||
*/
|
||||
protected static function getCommentType()
|
||||
protected static function getCommentType(): ObjectType
|
||||
{
|
||||
return \IPS\calendar\api\GraphQL\TypeRegistry::comment();
|
||||
}
|
||||
@@ -62,7 +64,7 @@ class _EventType extends \IPS\Content\Api\GraphQL\ItemType
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fields()
|
||||
public function fields(): array
|
||||
{
|
||||
// Extend our fields with image-specific stuff
|
||||
$defaultFields = parent::fields();
|
||||
|
||||
Reference in new issue
Block a user