Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -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 ] );
}
}