Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
<?php
/**
* @brief Invoices API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 9 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 Invoices API
*/
class _invoices extends \IPS\Api\Controller
{
/**
* GET /nexus/invoices
* Get list of invoices
*
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned
* @apiparam string statuses Comma-delimited list of statuses - if provided, only invoices with those statuses are returned - see invoice object for status keys
* @apiparam string sortBy What to sort by. Can be 'date', 'paid' (for paid date), 'total', 'title' or do not specify for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Invoice>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Customers */
if ( isset( \IPS\Request::i()->customers ) )
{
$where[] = array( \IPS\Db::i()->in( 'i_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
}
/* Statuses */
if ( isset( \IPS\Request::i()->statuses ) )
{
$where[] = array( \IPS\Db::i()->in( 'i_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'date', 'title', 'total' ) ) )
{
$sortBy = 'i_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 'i_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'nexus_invoices', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\nexus\Invoice',
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', $where )->first()
);
}
/**
* GET /nexus/invoices/{id}
* Get information about a specific invoice
*
* @param int $id ID Number
* @throws 2X299/1 INVALID_ID The invoice ID does not exist
* @return \IPS\nexus\Invoice
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Invoice::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X299/1', 404 );
}
}
}
+84
View File
@@ -0,0 +1,84 @@
<?php
/**
* @brief License Key API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 License Key API
*/
class _lkey extends \IPS\Api\Controller
{
/**
* GET /nexus/lkey/{key}
* Get information about a specific purchase from its license key
*
* @param string $lkey License key
* @throws 2X310/1 INVALID_KEY The license key does not exist
* @return \IPS\nexus\Purchase
*/
public function GETitem( $lkey )
{
try
{
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( $lkey );
$purchase = $licenseKey->purchase;
return new \IPS\Api\Response( 200, $purchase->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_KEY', '2X332/1', 404 );
}
}
/**
* POST /nexus/lkey/{key}
* Update custom fields for a purchase from its license key
*
* @apiparam object customFields Values for custom fields
* @throws 2X310/2 INVALID_KEY The license key does not exist
* @return \IPS\nexus\Purchase
*/
public function POSTitem( $lkey )
{
try
{
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( $lkey );
$purchase = $licenseKey->purchase;
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_KEY', '2X332/2', 404 );
}
if ( isset( \IPS\Request::i()->customFields ) )
{
$customFields = $purchase->custom_fields;
foreach ( \IPS\Request::i()->customFields as $k => $v )
{
$customFields[ $k ] = $v;
}
$purchase->custom_fields = $customFields;
}
$purchase->save();
return new \IPS\Api\Response( 200, $purchase->apiOutput() );
}
}
+165
View File
@@ -0,0 +1,165 @@
<?php
/**
* @brief Purchases API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 Purchases API
*/
class _purchases extends \IPS\Api\Controller
{
/**
* GET /nexus/purchases
* Get list of purchases
*
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned
* @apiparam int active If 1, only active purchases are returned. If 0, only inactive
* @apiparam int canceled If 1, only canceled purchases are returned. If 0, only not canceled
* @apiparam string itemApp If specified, only purchases with this application key are returned
* @apiparam string itemType If specified, only purchases with this item type are returned
* @apiparam int itemId If specified, only purchases with this item ID are returned
* @apiparam int parent If specified, only purchases with which are children of the purchase with the ID specified are returned
* @apiparam int show If 1, only purchases which show in the Admin CP are returned, if 0, only purchases which do not
* @apiparam string sortBy What to sort by. Can be 'start' (for purchase date), 'expire' (for the epiry date) or do not specify for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Purchase>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Customers */
if ( isset( \IPS\Request::i()->customers ) )
{
$where[] = array( \IPS\Db::i()->in( 'ps_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
}
/* Status */
if ( isset( \IPS\Request::i()->active ) )
{
$where[] = array( 'ps_active=?', intval( \IPS\Request::i()->active ) );
}
if ( isset( \IPS\Request::i()->canceled ) )
{
$where[] = array( 'ps_cancelled=?', intval( \IPS\Request::i()->canceled ) );
}
/* Item */
if ( isset( \IPS\Request::i()->itemApp ) )
{
$where[] = array( 'ps_app=?', \IPS\Request::i()->itemApp );
}
if ( isset( \IPS\Request::i()->itemType ) )
{
$where[] = array( 'ps_type=?', \IPS\Request::i()->itemType );
}
if ( isset( \IPS\Request::i()->itemId ) )
{
$where[] = array( 'ps_item_id=?', \IPS\Request::i()->itemId );
}
/* Parent */
if ( isset( \IPS\Request::i()->parent ) )
{
$where[] = array( 'ps_parent=?', intval( \IPS\Request::i()->parent ) );
}
/* Show */
if ( isset( \IPS\Request::i()->show ) )
{
$where[] = array( 'ps_show=?', intval( \IPS\Request::i()->show ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'start', 'expire' ) ) )
{
$sortBy = 'ps_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 'ps_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'nexus_purchases', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\nexus\Purchase',
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', $where )->first()
);
}
/**
* GET /nexus/purchases/{id}
* Get information about a specific purchase
*
* @param int $id ID Number
* @throws 2X310/1 INVALID_ID The purchase ID does not exist
* @return \IPS\nexus\Purchase
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Purchase::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X309/1', 404 );
}
}
/**
* POST /nexus/purchases/{id}
* Update custom fields for a purchase
*
* @apiparam object customFields Values for custom fields
* @throws 2X310/2 INVALID_ID The purchase ID does not exist
* @return \IPS\nexus\Purchase
*/
public function POSTitem( $id )
{
try
{
$purchase = \IPS\nexus\Purchase::load( $id );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X309/1', 404 );
}
if ( isset( \IPS\Request::i()->customFields ) )
{
$customFields = $purchase->custom_fields;
foreach ( \IPS\Request::i()->customFields as $k => $v )
{
$customFields[ $k ] = $v;
}
$purchase->custom_fields = $customFields;
}
$purchase->save();
return new \IPS\Api\Response( 200, $purchase->apiOutput() );
}
}
+95
View File
@@ -0,0 +1,95 @@
<?php
/**
* @brief Shipments API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 Shipments API
*/
class _shipments extends \IPS\Api\Controller
{
/**
* GET /nexus/shipments
* Get list of shipments
*
* @apiparam string statuses Comma-delimited list of statuses - if provided, only transactions with those statuses are returned - see order object for status keys
* @apiparam string methods Comma-delimited list of shipping method IDs - if provided, only shipments from those methods are returned
* @apiparam string sortBy What to sort by. Can be 'date', 'shipped_date' or do not specify for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Shipping\Order>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Statuses */
if ( isset( \IPS\Request::i()->statuses ) )
{
$where[] = array( \IPS\Db::i()->in( 'o_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
}
/* Methods */
if ( isset( \IPS\Request::i()->methods ) )
{
$where[] = array( \IPS\Db::i()->in( 'o_method', array_filter( explode( ',', \IPS\Request::i()->methods ) ) ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'date', 'shipped_date' ) ) )
{
$sortBy = 'o_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 'o_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'nexus_ship_orders', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\nexus\Shipping\Order',
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_ship_orders', $where )->first()
);
}
/**
* GET /nexus/shipments/{id}
* Get information about a specific shipment
*
* @param int $id ID Number
* @throws 2X307/1 INVALID_ID The shipment ID does not exist
* @return \IPS\nexus\Shipping\Order
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Shipping\Order::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X308/1', 404 );
}
}
}
+237
View File
@@ -0,0 +1,237 @@
<?php
/**
* @brief Support Replies API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 11 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 Support Replies API
*/
class _supportreplies extends \IPS\Content\Api\CommentController
{
/**
* Class
*/
protected $class = 'IPS\nexus\Support\Reply';
/**
* GET /nexus/supportreplies
* Get list of support replies
*
* @apiparam int staffReplies If 1, only replies by staff will be included. If 0, only replies by non-staff.
* @apiparam string authors Comma-delimited list of member IDs - if provided, only replies by those members are returned
* @apiparam string departments Comma-delimited list of department IDs
* @apiparam string statuses Comma-delimited list of status IDs
* @apiparam string severities Comma-delimited list of severity IDs
* @apiparam string sortBy What to sort by. Can be '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
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Support\Reply>
*/
public function GETindex()
{
/* Init */
$where = array();
/* Type */
if ( isset( \IPS\Request::i()->staffReplies ) )
{
$where[] = array( \IPS\Db::i()->in( 'reply_type', \IPS\Request::i()->staffReplies ? array( \IPS\nexus\Support\Reply::REPLY_STAFF, \IPS\nexus\Support\Reply::REPLY_HIDDEN ) : array( \IPS\nexus\Support\Reply::REPLY_MEMBER, \IPS\nexus\Support\Reply::REPLY_ALTCONTACT, \IPS\nexus\Support\Reply::REPLY_EMAIL ) ) );
}
else
{
$where[] = array( 'reply_type<>?', \IPS\nexus\Support\Reply::REPLY_PENDING );
}
/* Departments */
if ( isset( \IPS\Request::i()->departments ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_department', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->departments ) ) ) ) );
}
/* Statuses */
if ( isset( \IPS\Request::i()->statuses ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_status', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
}
/* Severities */
if ( isset( \IPS\Request::i()->severities ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_severity', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
}
/* Return */
return $this->_list( $where );
}
/**
* GET /nexus/supportreplies/{id}
* View information about a specific reply
*
* @param int $id ID Number
* @throws 2X314/1 INVALID_ID The reply ID does not exist
* @return \IPS\nexus\Support\Reply
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Support\Reply::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X314/1', 404 );
}
}
/**
* POST /nexus/supportreplies
* Create a reply
*
* @reqapiparam int request The ID number of the request the reply is for
* @reqapiparam int author The ID number of the member making the post (0 for guest)
* @reqapiparam string message The reply content as HTML (e.g. "<p>This is a post.</p>")
* @apiparam datetime date The date/time that should be used for the topic/post post date. If not provided, will use the current date/time
* @apiparam string ip_address The IP address that should be stored for the topic/post. If not provided, will use the IP address from the API request
* @apiparam bool hidden If true will be added as a hidden note
* @throws 2X314/2 NO_REQUEST The forum ID does not exist
* @throws 1X314/3 NO_AUTHOR The author ID does not exist
* @throws 1X314/4 NO_MESSAGE No message was supplied
* @return \IPS\nexus\Support\Reply
*/
public function POSTindex()
{
/* Get request */
try
{
$request = \IPS\nexus\Support\Request::load( \IPS\Request::i()->request );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_REQUEST', '2X314/2', 403 );
}
/* Get author */
if ( \IPS\Request::i()->author )
{
$author = \IPS\Member::load( \IPS\Request::i()->author );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X314/3', 403 );
}
}
else
{
$author = new \IPS\Member;
$author->name = \IPS\Request::i()->author_name;
}
/* Check we have a post */
if ( !\IPS\Request::i()->message )
{
throw new \IPS\Api\Exception( 'NO_MESSAGE', '1X314/4', 403 );
}
/* Do it */
return $this->_create( $request, $author, 'message' );
}
/**
* Create
*
* @param \IPS\Content\Item $item Content Item
* @param \IPS\Member $author Author
* @param string $contentParam The parameter that contains the content body
* @return \IPS\Api\Response
*/
protected function _createComment( \IPS\Content\Item $item, \IPS\Member $author, $contentParam='content' )
{
$comment = parent::_createComment( $item, $author, $contentParam );
if ( \IPS\Request::i()->hidden )
{
$comment->type = $comment::REPLY_HIDDEN;
}
$comment->save();
return $comment;
}
/**
* POST /nexus/supportreplies/{id}
* Edit a reply
*
* @param int $id ID Number
* @apiparam int author The ID number of the member making the post (0 for guest)
* @apiparam string message The post content as HTML (e.g. "<p>This is a post.</p>")
* @throws 2X314/5 INVALID_ID The post ID does not exist
* @throws 1X314/6 NO_AUTHOR The author ID does not exist
* @return \IPS\forums\Topic\Post
*/
public function POSTitem( $id )
{
try
{
/* Load */
$post = \IPS\nexus\Support\Reply::load( $id );
/* Do it */
try
{
return $this->_edit( $post, 'message' );
}
catch ( \InvalidArgumentException $e )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X314/6', 400 );
}
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X314/5', 404 );
}
}
/**
* DELETE /nexus/supportreplies/{id}
* Deletes a reply
*
* @param int $id ID Number
* @throws 2X314/7 INVALID_ID The post ID does not exist
* @throws 1X314/8 CANNOT_DELETE_FIRST_POST You cannot delete the first reply to a request. Delete the request itself instead.
* @return void
*/
public function DELETEitem( $id )
{
try
{
$reply = \IPS\nexus\Support\Reply::load( $id );
if ( $reply->isFirst() )
{
throw new \IPS\Api\Exception( 'CANNOT_DELETE_FIRST_POST', '1X314/8', 403 );
}
$reply->delete();
return new \IPS\Api\Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X314/7', 404 );
}
}
}
+324
View File
@@ -0,0 +1,324 @@
<?php
/**
* @brief Support Requests API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 4 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 Support Requests API
*/
class _supportrequests extends \IPS\Content\Api\ItemController
{
/**
* Class
*/
protected $class = 'IPS\nexus\Support\Request';
/**
* GET /nexus/supportrequests
* Get list of support requests
*
* @apiparam string authors Comma-delimited list of member IDs - if provided, only support requests belonging to those members (or emails specified by email param) are returned
* @apiparam string email Comma-delimited list of email addresses - if provided, only support requests created by those emails (or members specified by authors param) are returned
* @apiparam string departments Comma-delimited list of department IDs
* @apiparam string statuses Comma-delimited list of status IDs
* @apiparam string severities Comma-delimited list of severity IDs
* @apiparam string purchases Comma-delimited list of purchase IDs - if provided, only support requests associated with one of the provided purchase IDs are returned
* @apiparam string staff Comma-delimited list of member IDs - if provided, only support requests assigned to the staff members with one of the provided IDs are returned
* @apiparam int hidden If 1, only replies which are hidden are returned, if 0 only not hidden
* @apiparam string sortBy What to sort by. Can be '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
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Support\Request>
*/
public function GETindex()
{
/* Init */
$where = array();
/* Authors */
if ( isset( \IPS\Request::i()->authors ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->authors ) ) ) ) );
}
if ( isset( \IPS\Request::i()->authors ) and isset( \IPS\Request::i()->emails ) )
{
$where[] = array( '( ' . \IPS\Db::i()->in( 'r_member', array_filter( explode( ',', \IPS\Request::i()->authors ) ) ) . ' OR ' . \IPS\Db::i()->in( 'r_email', array_filter( explode( ',', \IPS\Request::i()->emails ) ) ) . ' )' );
}
elseif ( isset( \IPS\Request::i()->authors ) )
{
$where[] = array( '( ' . \IPS\Db::i()->in( 'r_member', array_filter( explode( ',', \IPS\Request::i()->authors ) ) ) . ' OR r_email<>? )', '' );
}
elseif ( isset( \IPS\Request::i()->emails ) )
{
$where[] = array( '( r_member>0 OR ' . \IPS\Db::i()->findInSet( 'r_email', array_filter( explode( ',', \IPS\Request::i()->emails ) ) ) . ' )' );
}
/* Departments */
if ( isset( \IPS\Request::i()->departments ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_department', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->departments ) ) ) ) );
}
/* Statuses */
if ( isset( \IPS\Request::i()->statuses ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_status', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
}
/* Severities */
if ( isset( \IPS\Request::i()->severities ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_severity', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) ) );
}
/* Purchases */
if ( isset( \IPS\Request::i()->purchases ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_purchase', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->purchases ) ) ) ) );
}
/* Staff */
if ( isset( \IPS\Request::i()->staff ) )
{
$where[] = array( \IPS\Db::i()->in( 'r_staff', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->staff ) ) ) ) );
}
/* Return */
return $this->_list( $where );
}
/**
* GET /nexus/supportrequests/{id}
* Get information about and replies to a specific support request
*
* @param int $id ID Number
* @apiparam int hidden If 1, only posts which are hidden are returned, if 0 only not hidden
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @throws 2X313/1 INVALID_ID The topic ID does not exist
* @return \IPS\nexus\Support\Request
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Support\Request::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/1', 404 );
}
}
/**
* GET /nexus/supportrequests/{id}/replies
* Get replies to a specific support request
*
* @param int $id ID Number
* @apiparam int hidden If 1, only replies which are hidden are returned, if 0 only not hidden
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @throws 2X313/2 INVALID_ID The topic ID does not exist
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Support\Reply>
*/
public function GETitem_replies( $id )
{
try
{
return $this->_comments( $id, 'IPS\nexus\Support\Reply', array( array( 'reply_type<>?', \IPS\nexus\Support\Reply::REPLY_PENDING ) ) );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/2', 404 );
}
}
/**
* Create or update topic
*
* @param \IPS\Content\Item $item The item
* @return \IPS\Content\Item
*/
protected function _createOrUpdate( \IPS\Content\Item $item )
{
/* Department, statuc, etc */
foreach ( array( 'department' => 'IPS\nexus\Support\Department', 'status' => 'IPS\nexus\Support\Status', 'severity' => 'IPS\nexus\Support\Severity', 'purchase' => 'IPS\nexus\Purchase', 'staff' => 'IPS\Member' ) as $key => $class )
{
if ( isset( \IPS\Request::i()->$key ) )
{
try
{
$object = $class::load( \IPS\Request::i()->$key );
$item->$key = $object;
}
catch ( \OutOfRangeException $e ) {}
}
}
if ( !isset( \IPS\Request::i()->purchase ) and isset( \IPS\Request::i()->lkey ) )
{
try
{
$licenseKey = \IPS\nexus\Purchase\LicenseKey::load( \IPS\Request::i()->lkey );
$item->purchase = $licenseKey->purchase;
}
catch ( \OutOfRangeException $e ) {}
}
/* Defaults */
if ( !$item->id )
{
if ( !$item->_data['status'] )
{
$item->status = \IPS\nexus\Support\Status::load( TRUE, 'status_default_member' );
}
if ( !$item->_data['severity'] )
{
$item->severity = \IPS\nexus\Support\Severity::load( TRUE, 'sev_default' );
}
}
/* Pass up */
return parent::_createOrUpdate( $item );
}
/**
* POST /nexus/supportrequests
* Create a support request
*
* @reqapiparam string title The support request title
* @reqapiparam int department Department ID number
* @reqapiparam int account The ID number of the member creating the support request - not required if email is provided
* @reqapiparam string email The email address creating the support request - not required if account is provided
* @reqapiparam string message The content as HTML (e.g. "<p>This is a support request.</p>")
* @apiparam int status Status ID number. If not provided, will use the default.
* @apiparam int severity Severity ID number. If not provided, will use the default.
* @apiparam int purchase Associated purchase ID number.
* @apiparam string lkey License key of associated purchase ID number. (Will be ignored if "purchase" is provided)
* @apiparam int staff Assigned staff ID number.
* @apiparam datetime date The date/time that should be used for the support request date. If not provided, will use the current date/time
* @throws 1X313/3 NO_DEPARTMENT The forum ID does not exist
* @throws 1X313/4 NO_AUTHOR The author ID does not exist
* @throws 1X313/5 NO_TITLE No title was supplied
* @throws 1X313/4 NO_POST No post was supplied
* @return \IPS\forums\Topic
*/
public function POSTindex()
{
/* Get department */
try
{
$department = \IPS\nexus\Support\Department::load( \IPS\Request::i()->department );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'NO_DEPARTMENT', '1X313/3', 400 );
}
/* Get author */
if ( \IPS\Request::i()->account )
{
$author = \IPS\Member::load( \IPS\Request::i()->account );
if ( !$author->member_id )
{
throw new \IPS\Api\Exception( 'NO_AUTHOR', '1X313/4', 400 );
}
}
else
{
$author = new \IPS\Member;
}
/* Check we have a title and a post */
if ( !\IPS\Request::i()->title )
{
throw new \IPS\Api\Exception( 'NO_TITLE', '1X313/5', 400 );
}
if ( !\IPS\Request::i()->message )
{
throw new \IPS\Api\Exception( 'NO_POST', '1X313/4', 400 );
}
/* Create */
$item = $this->_create( NULL, $author, 'message' );
/* Email */
if ( isset( \IPS\Request::i()->email ) )
{
$item->email = \IPS\Request::i()->email;
}
/* Do it */
return new \IPS\Api\Response( 201, $item->apiOutput() );
}
/**
* POST /nexus/supportrequests/{id}
* Edit a support request
*
* @apiparam string title The support request title
* @apiparam int department Department ID number
* @apiparam int status Status ID number. If not provided, will use the default.
* @apiparam int severity Severity ID number. If not provided, will use the default.
* @apiparam int purchase Associated purchase ID number.
* @apiparam string lkey License key of associated purchase ID number. (Will be ignored if "purchase" is provided)
* @apiparam int staff Assigned staff ID number.
* @throws 2X313/7 INVALID_ID The topic ID does not exist
* @return \IPS\nexus\Support\Request
*/
public function POSTitem( $id )
{
try
{
$request = \IPS\nexus\Support\Request::load( $id );
/* Process */
$this->_createOrUpdate( $request );
/* Save and return */
$request->save();
return new \IPS\Api\Response( 200, $request->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/7', 404 );
}
}
/**
* DELETE /nexus/supportrequests/{id}
* Delete a support request
*
* @param int $id ID Number
* @throws 1F294/5 INVALID_ID The topic ID does not exist
* @return void
*/
public function DELETEitem( $id )
{
try
{
\IPS\nexus\Support\Request::load( $id )->delete();
return new \IPS\Api\Response( 200, NULL );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X313/8', 404 );
}
}
}
+102
View File
@@ -0,0 +1,102 @@
<?php
/**
* @brief Transactions API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 Transactions API
*/
class _transactions extends \IPS\Api\Controller
{
/**
* GET /nexus/transactions
* Get list of transactions
*
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only transactions from those customers are returned
* @apiparam string statuses Comma-delimited list of statuses - if provided, only transactions with those statuses are returned - see transaction object for status keys
* @apiparam string gateways Comma-delimited list of gateway IDs - if provided, only transactions from those gateways are returned
* @apiparam string sortBy What to sort by. Can be 'date', 'amount' or do not specify for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Transaction>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Customers */
if ( isset( \IPS\Request::i()->customers ) )
{
$where[] = array( \IPS\Db::i()->in( 't_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
}
/* Statuses */
if ( isset( \IPS\Request::i()->statuses ) )
{
$where[] = array( \IPS\Db::i()->in( 't_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
}
/* Methods */
if ( isset( \IPS\Request::i()->gateways ) )
{
$where[] = array( \IPS\Db::i()->in( 't_method', array_filter( explode( ',', \IPS\Request::i()->gateways ) ) ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'date', 'amount' ) ) )
{
$sortBy = 't_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 't_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'nexus_transactions', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\nexus\Transaction',
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_transactions', $where )->first()
);
}
/**
* GET /nexus/transactions/{id}
* Get information about a specific transaction
*
* @param int $id ID Number
* @throws 2X307/1 INVALID_ID The transaction ID does not exist
* @return \IPS\nexus\Transaction
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Transaction::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X307/1', 404 );
}
}
}
+95
View File
@@ -0,0 +1,95 @@
<?php
/**
* @brief Withdrawals API
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\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 Withdrawals API
*/
class _withdrawals extends \IPS\Api\Controller
{
/**
* GET /nexus/shipments
* Get list of shipments
*
* @apiparam string customers Comma-delimited list of customer IDs - if provided, only invoices belonging to those customers are returned
* @apiparam string statuses Comma-delimited list of statuses - if provided, only transactions with those statuses are returned - see payout object for status keys
* @apiparam string sortBy What to sort by. Can be 'date', 'completed' (for the date it was completed), 'amount' or do not specify for ID
* @apiparam string sortDir Sort direction. Can be 'asc' or 'desc' - defaults to 'asc'
* @apiparam int page Page number
* @return \IPS\Api\PaginatedResponse<IPS\nexus\Shipping\Order>
*/
public function GETindex()
{
/* Where clause */
$where = array();
/* Customers */
if ( isset( \IPS\Request::i()->customers ) )
{
$where[] = array( \IPS\Db::i()->in( 'po_member', array_map( 'intval', array_filter( explode( ',', \IPS\Request::i()->customers ) ) ) ) );
}
/* Statuses */
if ( isset( \IPS\Request::i()->statuses ) )
{
$where[] = array( \IPS\Db::i()->in( 'po_status', array_filter( explode( ',', \IPS\Request::i()->statuses ) ) ) );
}
/* Sort */
if ( isset( \IPS\Request::i()->sortBy ) and in_array( \IPS\Request::i()->sortBy, array( 'date', 'amount' ) ) )
{
$sortBy = 'po_' . \IPS\Request::i()->sortBy;
}
else
{
$sortBy = 'po_id';
}
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
/* Return */
return new \IPS\Api\PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'nexus_payouts', $where, "{$sortBy} {$sortDir}" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
'IPS\nexus\Payout`',
\IPS\Db::i()->select( 'COUNT(*)', 'nexus_payouts', $where )->first()
);
}
/**
* GET /nexus/withdrawals/{id}
* Get information about a specific invoice
*
* @param int $id ID Number
* @throws 2X307/1 INVALID_ID The withdrawal ID does not exist
* @return \IPS\nexus\Payout
*/
public function GETitem( $id )
{
try
{
return new \IPS\Api\Response( 200, \IPS\nexus\Payout::load( $id )->apiOutput() );
}
catch ( \OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '2X309/1', 404 );
}
}
}