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

+61 -38
View File
@@ -12,21 +12,38 @@
namespace IPS\calendar\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use IPS\Api\Exception;
use IPS\Api\PaginatedResponse;
use IPS\Api\Response;
use IPS\calendar\Venue;
use IPS\GeoLocation;
use IPS\Http\Url\Friendly;
use IPS\Lang;
use IPS\Node\Api\NodeController;
use IPS\Node\Model;
use IPS\Request;
use OutOfRangeException;
use function defined;
use function in_array;
use function is_array;
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;
}
/**
* @brief Calendar Venues API
*/
class _venues extends \IPS\Node\Api\NodeController
class venues extends NodeController
{
/**
* Class
*/
protected $class = 'IPS\calendar\Venue';
protected string $class = 'IPS\calendar\Venue';
/**
* GET /calendar/venues
@@ -34,9 +51,10 @@ class _venues extends \IPS\Node\Api\NodeController
*
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Venue>
* @apireturn PaginatedResponse<IPS\calendar\Venue>
* @return PaginatedResponse<Venue>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Return */
return $this->_list();
@@ -48,17 +66,18 @@ class _venues extends \IPS\Node\Api\NodeController
*
* @param int $id ID Number
* @throws 1L384/1 INVALID_ID The venue does not exist
* @return \IPS\calendar\Venue
* @apireturn \IPS\calendar\Venue
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
try
{
return $this->_view( $id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1L384/1', 404 );
throw new Exception( 'INVALID_ID', '1L384/1', 404 );
}
}
@@ -70,16 +89,17 @@ class _venues extends \IPS\Node\Api\NodeController
* @reqapiparam string title The venue title
* @reqapiparam \IPS\GeoLocation address The venue address (latitude and longitude do not need to be supplied and will be ignored)
* @apiparam string description The venue description
* @return \IPS\calendar\Venue
* @apireturn \IPS\calendar\Venue
* @throws 1L384/2 NO_ADDRESS An address is required for the venue but was not supplied
* @throws 1L384/3 INVALID_ADDRESS An invalid address was supplied
* @throws 1L384/4 NO_TITLE No title was supplied for the venue
* @return Response
*/
public function POSTindex()
public function POSTindex(): Response
{
if( !\IPS\Request::i()->address OR !\is_array( \IPS\Request::i()->address ) )
if( !Request::i()->address OR !is_array( Request::i()->address ) )
{
throw new \IPS\Api\Exception( 'NO_ADDRESS', '1L384/2', 400 );
throw new Exception( 'NO_ADDRESS', '1L384/2', 400 );
}
else
{
@@ -87,12 +107,12 @@ class _venues extends \IPS\Node\Api\NodeController
$this->_getGeoLocationObject();
}
if ( !\IPS\Request::i()->title )
if ( !Request::i()->title )
{
throw new \IPS\Api\Exception( 'NO_TITLE', '1L384/4', 400 );
throw new Exception( 'NO_TITLE', '1L384/4', 400 );
}
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
return new Response( 201, $this->_create()->apiOutput( $this->member ) );
}
/**
@@ -104,17 +124,19 @@ class _venues extends \IPS\Node\Api\NodeController
* @reqapiparam \IPS\GeoLocation address The venue address (latitude and longitude do not need to be supplied and will be ignored)
* @apiparam string description The venue description
* @param int $id ID Number
* @return \IPS\calendar\Venue
* @apireturn \IPS\calendar\Venue
* @throws 1L384/2 NO_ADDRESS An address is required for the venue but was not supplied
* @throws 1L384/3 INVALID_ADDRESS An invalid address was supplied
* @throws 1L384/4 NO_TITLE No title was supplied for the venue
* @return Response
*/
public function POSTitem( $id )
public function POSTitem( int $id ): Response
{
/* @var Venue $class */
$class = $this->class;
$venue = $class::load( $id );
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $venue )->apiOutput( $this->member ) );
return new Response( 200, $this->_createOrUpdate( $venue )->apiOutput( $this->member ) );
}
/**
@@ -123,9 +145,10 @@ class _venues extends \IPS\Node\Api\NodeController
*
* @apiclientonly
* @param int $id ID Number
* @return void
* @apireturn void
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
return $this->_delete( $id );
}
@@ -133,27 +156,27 @@ class _venues extends \IPS\Node\Api\NodeController
/**
* Create or update node
*
* @param \IPS\node\Model $venue The node
* @return \IPS\node\Model
* @param Model $venue The node
* @return Model
*/
protected function _createOrUpdate( \IPS\Node\Model $venue )
protected function _createOrUpdate( Model $venue ): Model
{
if( \IPS\Request::i()->address AND \is_array( \IPS\Request::i()->address ) )
if( Request::i()->address AND is_array( Request::i()->address ) )
{
$geoLocation = $this->_getGeoLocationObject();
$venue->address = json_encode( $geoLocation );
}
if ( isset( \IPS\Request::i()->title ) )
if ( isset( Request::i()->title ) )
{
\IPS\Lang::saveCustom( 'calendar', 'calendar_venue_' . $venue->id, \IPS\Request::i()->title );
$venue->title_seo = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->title );
Lang::saveCustom( 'calendar', 'calendar_venue_' . $venue->id, Request::i()->title );
$venue->title_seo = Friendly::seoTitle( Request::i()->title );
}
if( isset( \IPS\Request::i()->description ) )
if( isset( Request::i()->description ) )
{
\IPS\Lang::saveCustom( 'calendar', 'calendar_venue_' . $venue->id .'_desc', \IPS\Request::i()->description );
Lang::saveCustom( 'calendar', 'calendar_venue_' . $venue->id .'_desc', Request::i()->description );
}
return parent::_createOrUpdate( $venue );
@@ -162,16 +185,16 @@ class _venues extends \IPS\Node\Api\NodeController
/**
* Get geolocation object
*
* @return array
* @return GeoLocation
*/
protected function _getGeoLocationObject()
protected function _getGeoLocationObject(): GeoLocation
{
$geoLocation = new \IPS\GeoLocation;
$geoLocation = new GeoLocation;
$geoLocation->addressLines = array();
foreach( \IPS\Request::i()->address as $k => $v )
foreach( Request::i()->address as $k => $v )
{
if( \in_array( $k, array( 'city', 'postalCode', 'region', 'addressLines', 'country' ) ) )
if( in_array( $k, array( 'city', 'postalCode', 'region', 'addressLines', 'country' ) ) )
{
$geoLocation->$k = $v;
}
@@ -181,9 +204,9 @@ class _venues extends \IPS\Node\Api\NodeController
{
$geoLocation->getLatLong();
}
catch( \BadMethodCallException $e )
catch( BadMethodCallException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ADDRESS', '1L384/3', 400 );
throw new Exception( 'INVALID_ADDRESS', '1L384/3', 400 );
}
return $geoLocation;