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
@@ -12,21 +12,34 @@
|
||||
namespace IPS\calendar\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Api\Exception;
|
||||
use IPS\Api\PaginatedResponse;
|
||||
use IPS\Api\Response;
|
||||
use IPS\calendar\Calendar;
|
||||
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;
|
||||
|
||||
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 Calendars API
|
||||
*/
|
||||
class _calendars extends \IPS\Node\Api\NodeController
|
||||
class calendars extends NodeController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\calendar\Calendar';
|
||||
protected string $class = 'IPS\calendar\Calendar';
|
||||
|
||||
/**
|
||||
* GET /calendar/calendars
|
||||
@@ -36,9 +49,10 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @note For requests using an OAuth Access Token for a particular member, only calendars the authorized user can view will be included
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Calendar>
|
||||
* @apireturn PaginatedResponse<IPS\calendar\Calendar>
|
||||
* @return PaginatedResponse<Calendar>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Return */
|
||||
return $this->_list();
|
||||
@@ -50,17 +64,18 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 1L364/1 INVALID_ID The calendar does not exist or the authorized user does not have permission to view it
|
||||
* @return \IPS\calendar\Calendar
|
||||
* @apireturn \IPS\calendar\Calendar
|
||||
* @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', '1L364/1', 404 );
|
||||
throw new Exception( 'INVALID_ID', '1L364/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,17 +92,18 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int allow_reviews 0|1 Allow reviews
|
||||
* @apiparam int approve_reviews 0|1 Reviews must be approved
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, reply, review, askrsvp, rsvp) and values as permissions to use (which may be * to grant access to all groups, or an array of group IDs to permit access to)
|
||||
* @return \IPS\calendar\Calendar
|
||||
* @apireturn \IPS\calendar\Calendar
|
||||
* @throws 1L364/2 NO_TITLE A title for the calendar must be supplied
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTindex()
|
||||
public function POSTindex(): Response
|
||||
{
|
||||
if ( !\IPS\Request::i()->title )
|
||||
if ( !Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '1L364/2', 400 );
|
||||
throw new Exception( 'NO_TITLE', '1L364/2', 400 );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
return new Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,14 +120,16 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int approve_reviews 0|1 Reviews must be approved
|
||||
* @apiparam object permissions An object with the keys as permission options (view, read, add, reply, review, askrsvp, rsvp) and values as permissions to use (which may be * to grant access to all groups, or an array of group IDs to permit access to)
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\calendar\Calendar
|
||||
* @apireturn \IPS\calendar\Calendar
|
||||
* @return Response
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
public function POSTitem( int $id ): Response
|
||||
{
|
||||
/* @var Calendar $class */
|
||||
$class = $this->class;
|
||||
$calendar = $class::load( $id );
|
||||
|
||||
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $calendar )->apiOutput( $this->member ) );
|
||||
return new Response( 200, $this->_createOrUpdate( $calendar )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,9 +138,10 @@ class _calendars 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 );
|
||||
}
|
||||
@@ -130,27 +149,27 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
/**
|
||||
* Create or update node
|
||||
*
|
||||
* @param \IPS\node\Model $calendar The node
|
||||
* @return \IPS\node\Model
|
||||
* @param Model $calendar The node
|
||||
* @return Model
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\Node\Model $calendar )
|
||||
protected function _createOrUpdate( Model $calendar ): Model
|
||||
{
|
||||
if ( \IPS\Request::i()->title )
|
||||
if ( Request::i()->title )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'calendar', 'calendar_calendar_' . $calendar->id, \IPS\Request::i()->title );
|
||||
$calendar->title_seo = \IPS\Http\Url\Friendly::seoTitle( \IPS\Request::i()->title );
|
||||
Lang::saveCustom( 'calendar', 'calendar_calendar_' . $calendar->id, Request::i()->title );
|
||||
$calendar->title_seo = Friendly::seoTitle( Request::i()->title );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->color ) )
|
||||
if ( isset( Request::i()->color ) )
|
||||
{
|
||||
$calendar->color = \IPS\Request::i()->color;
|
||||
$calendar->color = Request::i()->color;
|
||||
}
|
||||
|
||||
$calendar->moderate = (int) isset( \IPS\Request::i()->approve_events ) ? \IPS\Request::i()->approve_events : 0;
|
||||
$calendar->allow_comments = (int) isset( \IPS\Request::i()->allow_comments ) ? \IPS\Request::i()->allow_comments : 0;
|
||||
$calendar->comment_moderate = (int) isset( \IPS\Request::i()->approve_comments ) ? \IPS\Request::i()->approve_comments : 0;
|
||||
$calendar->allow_reviews = (int) isset( \IPS\Request::i()->allow_reviews ) ? \IPS\Request::i()->allow_reviews : 0;
|
||||
$calendar->review_moderate = (int) isset( \IPS\Request::i()->approve_reviews ) ? \IPS\Request::i()->approve_reviews : 0;
|
||||
$calendar->moderate = (int) isset( Request::i()->approve_events ) ? Request::i()->approve_events : 0;
|
||||
$calendar->allow_comments = (int) isset( Request::i()->allow_comments ) ? Request::i()->allow_comments : 0;
|
||||
$calendar->comment_moderate = (int) isset( Request::i()->approve_comments ) ? Request::i()->approve_comments : 0;
|
||||
$calendar->allow_reviews = (int) isset( Request::i()->allow_reviews ) ? Request::i()->allow_reviews : 0;
|
||||
$calendar->review_moderate = (int) isset( Request::i()->approve_reviews ) ? Request::i()->approve_reviews : 0;
|
||||
|
||||
return parent::_createOrUpdate( $calendar );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user