Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\calendar\api;
|
||||
|
||||
/* 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' );
|
||||
exit;
|
||||
@@ -32,6 +32,7 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
* GET /calendar/calendars
|
||||
* Get list of calendars
|
||||
*
|
||||
* @apiparam int clubs 0|1 Include club calendars, default: 1
|
||||
* @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
|
||||
@@ -75,10 +76,17 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int approve_comments 0|1 Comments must be approved
|
||||
* @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
|
||||
* @throws 1L364/2 NO_TITLE A title for the calendar must be supplied
|
||||
*/
|
||||
public function POSTindex()
|
||||
{
|
||||
if ( !\IPS\Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '1L364/2', 400 );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
@@ -94,6 +102,8 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
* @apiparam int approve_comments 0|1 Comments must be approved
|
||||
* @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)
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\calendar\Calendar
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
@@ -101,7 +111,7 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
$class = $this->class;
|
||||
$calendar = $class::load( $id );
|
||||
|
||||
return new \IPS\Api\Response( 201, $this->_createOrUpdate( $calendar )->apiOutput( $this->member ) );
|
||||
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $calendar )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,17 +130,12 @@ class _calendars extends \IPS\Node\Api\NodeController
|
||||
/**
|
||||
* Create or update node
|
||||
*
|
||||
* @param \IPS\node\Model $node The node
|
||||
* @param \IPS\node\Model $calendar The node
|
||||
* @return \IPS\node\Model
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\node\Model $calendar )
|
||||
{
|
||||
if ( !\IPS\Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '', 400 );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\Request::i()->title ) )
|
||||
if ( \IPS\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 );
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\calendar\api;
|
||||
|
||||
/* 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' );
|
||||
exit;
|
||||
@@ -83,7 +83,7 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* POST /calendar/comments
|
||||
* Create a comment
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authenticated user has permission to hide content).
|
||||
* @reqapiparam int event The ID number of the event the comment is for
|
||||
* @reqapiparam int author The ID number of the member making the comment (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author
|
||||
* @apiparam string author_name If author is 0, the guest name that should be used
|
||||
@@ -149,7 +149,7 @@ class _comments extends \IPS\Content\Api\CommentController
|
||||
* POST /calendar/comments/{id}
|
||||
* Edit a comment
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authenticated user has permission to hide content).
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author The ID number of the member making the comment (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @apiparam string author_name If author is 0, the guest name that should be used
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\calendar\api;
|
||||
|
||||
/* 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' );
|
||||
exit;
|
||||
@@ -38,19 +38,76 @@ class _events extends \IPS\Content\Api\ItemController
|
||||
* @apiparam int locked If 1, only events which are locked are returned, if 0 only unlocked
|
||||
* @apiparam int hidden If 1, only events which are hidden are returned, if 0 only not hidden
|
||||
* @apiparam int featured If 1, only events which are featured are returned, if 0 only not featured
|
||||
* @apiparam string sortBy What to sort by. Can be 'date' for creation date, 'title' or leave unspecified for ID
|
||||
* @apiparam string rangeStart YYYY-MM-DD. Only events occurring on or after this date will be returned.
|
||||
* @apiparam string rangeEnd YYYY-MM-DD. Only events occurring on or before this date will be returned.
|
||||
* @apiparam string sortBy What to sort by. Can be 'date' for creation date, 'start' for event start date, 'end' for event end date, 'title' or leave unspecified for ID
|
||||
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Event>
|
||||
* @throws 1L296/M INVALID_DATE The rangeStart and/or rangeEnd value was not a valid date in YYYY-MM-DD format
|
||||
*/
|
||||
public function GETindex()
|
||||
{
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
|
||||
/* Are we limiting to a date range? */
|
||||
if( isset( \IPS\Request::i()->rangeStart ) OR isset( \IPS\Request::i()->rangeEnd ) )
|
||||
{
|
||||
$startDate = $endDate = NULL;
|
||||
|
||||
foreach( array( 'start', 'end' ) as $limiter )
|
||||
{
|
||||
$inputKey = 'range' . mb_ucfirst( $limiter );
|
||||
|
||||
if( \IPS\Request::i()->$inputKey )
|
||||
{
|
||||
$datePieces = explode( '-', \IPS\Request::i()->$inputKey );
|
||||
|
||||
/* Let's make sure the date is valid... */
|
||||
if( @checkdate( $datePieces[1], $datePieces[2], $datePieces[0] ) )
|
||||
{
|
||||
if( $limiter === 'start' )
|
||||
{
|
||||
$startDate = \IPS\calendar\Date::getDate( $datePieces[0], $datePieces[1], $datePieces[2] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$endDate = \IPS\calendar\Date::getDate( $datePieces[0], $datePieces[1], $datePieces[2], 23, 59, 59 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_DATE', '1L296/M', 403 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the events within this range */
|
||||
$events = \IPS\calendar\Event::retrieveEvents( $startDate, $endDate, NULL, NULL, FALSE, new \IPS\Member, NULL, TRUE );
|
||||
|
||||
if( !\count( $events ) )
|
||||
{
|
||||
/* Force no results */
|
||||
$where[] = array( '0=1' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$where[] = array( 'event_id IN(' . implode( ',', array_map( function( $event ) { return $event->id; }, $events ) ) . ')' );
|
||||
}
|
||||
}
|
||||
|
||||
/* Sort by */
|
||||
$sortBy = NULL;
|
||||
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'start', 'end' ) ) )
|
||||
{
|
||||
$sortBy = 'event_' . \IPS\Request::i()->sortBy . '_date';
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return $this->_list( $where, 'calendars' );
|
||||
return $this->_list( $where, 'calendars', FALSE, $sortBy );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +134,7 @@ class _events extends \IPS\Content\Api\ItemController
|
||||
* POST /calendar/events
|
||||
* Create an event
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authentictaed user has permission to lock events).
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authenticated user has permission to lock events).
|
||||
* @reqapiparam int calendar The ID number of the calendar the event should be created in
|
||||
* @apiparam int author The ID number of the member creating the event (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author
|
||||
* @reqapiparam string title The event title
|
||||
@@ -180,7 +237,7 @@ class _events extends \IPS\Content\Api\ItemController
|
||||
* POST /calendar/events/{id}
|
||||
* Edit an event
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authentictaed user has permission to lock topics).
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, locked will only be honoured if the authenticated user has permission to lock topics).
|
||||
* @reqapiparam int calendar The ID number of the calendar the event should be created in
|
||||
* @reqapiparam int author The ID number of the member creating the event (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @reqapiparam string title The event title
|
||||
@@ -193,11 +250,11 @@ class _events extends \IPS\Content\Api\ItemController
|
||||
* @apiparam \IPS\GeoLocation location The location where the event is taking place
|
||||
* @apiparam string prefix Prefix tag
|
||||
* @apiparam string tags Comma-separated list of tags (do not include prefix)
|
||||
* @apiparam datetime date The date/time that should be used for the event/post post date. If not provided, will use the current date/time. Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @apiparam string ip_address The IP address that should be stored for the event/post. If not provided, will use the IP address from the API request. Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @apiparam int locked 1/0 indicating if the event should be locked
|
||||
* @apiparam int hidden 0 = unhidden; 1 = hidden, pending moderator approval; -1 = hidden (as if hidden by a moderator)
|
||||
* @apiparam int featured 1/0 indicating if the event should be featured
|
||||
* @param int $id ID Number
|
||||
* @throws 1L296/I INVALID_ID The event ID is invalid or the authorized user does not have permission to view it
|
||||
* @throws 1L296/D NO_CALENDAR The calendar ID does not exist or the authorized user does not have permission to post in it
|
||||
* @throws 1L296/E NO_AUTHOR The author ID does not exist
|
||||
@@ -397,7 +454,7 @@ class _events extends \IPS\Content\Api\ItemController
|
||||
*/
|
||||
public function PUTitem_rsvps( $id, $memberId )
|
||||
{
|
||||
if ( !isset( \IPS\Request::i()->response ) or !in_array( (int) \IPS\Request::i()->response, range( 0, 2 ) ) )
|
||||
if ( !isset( \IPS\Request::i()->response ) or !\in_array( (int) \IPS\Request::i()->response, range( 0, 2 ) ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_RESPONSE', '1L296/L', 400 );
|
||||
}
|
||||
@@ -458,7 +515,7 @@ class _events extends \IPS\Content\Api\ItemController
|
||||
throw new \IPS\Api\Exception( 'INVALID_MEMBER', '2L296/K', 404 );
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'calendar_event_rsvp', array( 'rsvp_event_id=? AND rsvp_member_id=?', intval( $id ), intval( $memberId ) ) );
|
||||
\IPS\Db::i()->delete( 'calendar_event_rsvp', array( 'rsvp_event_id=? AND rsvp_member_id=?', \intval( $id ), \intval( $memberId ) ) );
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
}
|
||||
|
||||
@@ -502,7 +559,7 @@ class _events extends \IPS\Content\Api\ItemController
|
||||
/* RSVP */
|
||||
if ( isset( \IPS\Request::i()->rsvp ) and ( !$this->member or $item->container()->can( 'askrsvp', $this->member ) ) )
|
||||
{
|
||||
$item->rsvp = intval( \IPS\Request::i()->rsvp );
|
||||
$item->rsvp = \intval( \IPS\Request::i()->rsvp );
|
||||
if ( $item->rsvp and isset( \IPS\Request::i()->rsvpLimit ) and \IPS\Request::i()->rsvpLimit )
|
||||
{
|
||||
$item->rsvp_limit = \IPS\Request::i()->rsvpLimit;
|
||||
|
||||
Whitespace-only changes.
@@ -12,7 +12,7 @@
|
||||
namespace IPS\calendar\api;
|
||||
|
||||
/* 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' );
|
||||
exit;
|
||||
@@ -83,7 +83,7 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* POST /calendar/reviews
|
||||
* Create a review
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authenticated user has permission to hide content).
|
||||
* @reqapiparam int event The ID number of the event the review is for
|
||||
* @reqapiparam int author The ID number of the member making the review (0 for guest). Required for requests made using an API Key or the Client Credentials Grant Type. For requests using an OAuth Access Token for a particular member, that member will always be the author
|
||||
* @apiparam string author_name If author is 0, the guest name that should be used
|
||||
@@ -144,7 +144,7 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
}
|
||||
|
||||
/* Check we have a rating */
|
||||
if ( !\IPS\Request::i()->rating or !in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
|
||||
if ( !\IPS\Request::i()->rating or !\in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_RATING', '1L298/8', 403 );
|
||||
}
|
||||
@@ -157,7 +157,7 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
* POST /calendar/reviews/{id}
|
||||
* Edit a review
|
||||
*
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authentictaed user has permission to hide content).
|
||||
* @note For requests using an OAuth Access Token for a particular member, any parameters the user doesn't have permission to use are ignored (for example, hidden will only be honoured if the authenticated user has permission to hide content).
|
||||
* @param int $id ID Number
|
||||
* @apiparam int author The ID number of the member making the review (0 for guest). Ignored for requests using an OAuth Access Token for a particular member.
|
||||
* @apiparam string author_name If author is 0, the guest name that should be used
|
||||
@@ -186,7 +186,7 @@ class _reviews extends \IPS\Content\Api\CommentController
|
||||
}
|
||||
|
||||
/* Check */
|
||||
if ( isset( \IPS\Request::i()->rating ) and !in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
|
||||
if ( isset( \IPS\Request::i()->rating ) and !\in_array( (int) \IPS\Request::i()->rating, range( 1, \IPS\Settings::i()->reviews_rating_out_of ) ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_RATING', '1L298/9', 403 );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Calendar Venues API
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Calendar
|
||||
* @since 5 June 2018
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calendar Venues API
|
||||
*/
|
||||
class _venues extends \IPS\Node\Api\NodeController
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\calendar\Venue';
|
||||
|
||||
/**
|
||||
* GET /calendar/venues
|
||||
* Get list of venues
|
||||
*
|
||||
* @apiparam int page Page number
|
||||
* @apiparam int perPage Number of results per page - defaults to 25
|
||||
* @return \IPS\Api\PaginatedResponse<IPS\calendar\Venue>
|
||||
*/
|
||||
public function GETindex()
|
||||
{
|
||||
/* Return */
|
||||
return $this->_list();
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /calendar/venues/{id}
|
||||
* Get specific venue
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @throws 1L384/1 INVALID_ID The venue does not exist
|
||||
* @return \IPS\calendar\Venue
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_view( $id );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '1L384/1', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /calendar/venues
|
||||
* Create a venue
|
||||
*
|
||||
* @apiclientonly
|
||||
* @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
|
||||
* @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
|
||||
*/
|
||||
public function POSTindex()
|
||||
{
|
||||
if( !\IPS\Request::i()->address OR !\is_array( \IPS\Request::i()->address ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_ADDRESS', '1L384/2', 400 );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Just check before we try to save */
|
||||
$this->_getGeoLocationObject();
|
||||
}
|
||||
|
||||
if ( !\IPS\Request::i()->title )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'NO_TITLE', '1L384/4', 400 );
|
||||
}
|
||||
|
||||
return new \IPS\Api\Response( 201, $this->_create()->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /calendar/venues/{id}
|
||||
* Edit a venue
|
||||
*
|
||||
* @apiclientonly
|
||||
* @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
|
||||
* @param int $id ID Number
|
||||
* @return \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
|
||||
*/
|
||||
public function POSTitem( $id )
|
||||
{
|
||||
$class = $this->class;
|
||||
$venue = $class::load( $id );
|
||||
|
||||
return new \IPS\Api\Response( 200, $this->_createOrUpdate( $venue )->apiOutput( $this->member ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /calendar/venues/{id}
|
||||
* Delete a venue
|
||||
*
|
||||
* @apiclientonly
|
||||
* @param int $id ID Number
|
||||
* @return void
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
{
|
||||
return $this->_delete( $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or update node
|
||||
*
|
||||
* @param \IPS\node\Model $venue The node
|
||||
* @return \IPS\node\Model
|
||||
*/
|
||||
protected function _createOrUpdate( \IPS\node\Model $venue )
|
||||
{
|
||||
if( \IPS\Request::i()->address AND \is_array( \IPS\Request::i()->address ) )
|
||||
{
|
||||
$geoLocation = $this->_getGeoLocationObject();
|
||||
|
||||
$venue->address = json_encode( $geoLocation );
|
||||
}
|
||||
|
||||
if ( isset( \IPS\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 );
|
||||
}
|
||||
|
||||
if( isset( \IPS\Request::i()->description ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'calendar', 'calendar_venue_' . $venue->id .'_desc', \IPS\Request::i()->description );
|
||||
}
|
||||
|
||||
return parent::_createOrUpdate( $venue );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get geolocation object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getGeoLocationObject()
|
||||
{
|
||||
$geoLocation = new \IPS\GeoLocation;
|
||||
$geoLocation->addressLines = array();
|
||||
|
||||
foreach( \IPS\Request::i()->address as $k => $v )
|
||||
{
|
||||
if( \in_array( $k, array( 'city', 'postalCode', 'region', 'addressLines', 'country' ) ) )
|
||||
{
|
||||
$geoLocation->$k = $v;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$geoLocation->getLatLong();
|
||||
}
|
||||
catch( \BadMethodCallException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ADDRESS', '1L384/3', 400 );
|
||||
}
|
||||
|
||||
return $geoLocation;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user