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

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