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,22 +12,35 @@
|
||||
namespace IPS\blog\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\blog\Entry\Category;
|
||||
use IPS\Db;
|
||||
use IPS\Node\Api\NodeController;
|
||||
use IPS\Request;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
|
||||
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 Blog Categories API
|
||||
*/
|
||||
class _entrycategories extends \IPS\Node\Api\NodeController
|
||||
class entrycategories extends NodeController
|
||||
{
|
||||
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = 'IPS\blog\Entry\Category';
|
||||
protected string $class = 'IPS\blog\Entry\Category';
|
||||
|
||||
/**
|
||||
* GET /blog/entrycategories
|
||||
@@ -38,47 +51,49 @@ class _entrycategories extends \IPS\Node\Api\NodeController
|
||||
* @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\blog\Entry\Category>
|
||||
* @apireturn PaginatedResponse<IPS\blog\Entry\Category>
|
||||
* @return PaginatedResponse<Category>
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): PaginatedResponse
|
||||
{
|
||||
/* Where clause */
|
||||
$where = array();
|
||||
|
||||
/* @var Category $class */
|
||||
$class = $this->class;
|
||||
|
||||
if ( isset( \IPS\Request::i()->ids ) )
|
||||
if ( isset( Request::i()->ids ) )
|
||||
{
|
||||
$idField = $class::$databaseTable . '.' . $class::$databasePrefix . '.' . $class::$databaseColumnId;
|
||||
$where[] = array( \IPS\Db::i()->in( $idField, array_map( 'intval', explode( ',', \IPS\Request::i()->ids ) ) ) );
|
||||
$where[] = array( Db::i()->in( $idField, array_map( 'intval', explode( ',', Request::i()->ids ) ) ) );
|
||||
}
|
||||
|
||||
/* Blog */
|
||||
if ( isset( \IPS\Request::i()->blog ) )
|
||||
if ( isset( Request::i()->blog ) )
|
||||
{
|
||||
$where[] = array( 'entry_category_blog_id=?', \intval( \IPS\Request::i()->blog ) );
|
||||
$where[] = array( 'entry_category_blog_id=?', intval( Request::i()->blog ) );
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
if ( isset( \IPS\Request::i()->sortBy ) and \in_array( \IPS\Request::i()->sortBy, array( 'position' ) ) )
|
||||
if ( isset( Request::i()->sortBy ) and Request::i()->sortBy == 'position' )
|
||||
{
|
||||
$sortBy = 'entry_category_' . \IPS\Request::i()->sortBy;
|
||||
$sortBy = 'entry_category_' . Request::i()->sortBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sortBy = 'entry_category_id';
|
||||
}
|
||||
$sortDir = ( isset( \IPS\Request::i()->sortDir ) and \in_array( mb_strtolower( \IPS\Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? \IPS\Request::i()->sortDir : 'asc';
|
||||
$sortDir = ( isset( Request::i()->sortDir ) and in_array( mb_strtolower( Request::i()->sortDir ), array( 'asc', 'desc' ) ) ) ? Request::i()->sortDir : 'asc';
|
||||
|
||||
/* Return */
|
||||
return new \IPS\Api\PaginatedResponse(
|
||||
return new PaginatedResponse(
|
||||
200,
|
||||
\IPS\Db::i()->select( '*', 'blog_entry_categories', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
|
||||
Db::i()->select( '*', 'blog_entry_categories', $where, "{$sortBy} {$sortDir}" ),
|
||||
isset( Request::i()->page ) ? Request::i()->page : 1,
|
||||
'IPS\blog\Entry\Category',
|
||||
\IPS\Db::i()->select( 'COUNT(*)', 'blog_entry_categories', $where )->first(),
|
||||
Db::i()->select( 'COUNT(*)', 'blog_entry_categories', $where )->first(),
|
||||
$this->member,
|
||||
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
|
||||
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,9 +102,10 @@ class _entrycategories extends \IPS\Node\Api\NodeController
|
||||
* Get information about a specific entry category
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @return \IPS\blog\Entry\Category
|
||||
* @apireturn \IPS\blog\Entry\Category
|
||||
* @return Response
|
||||
*/
|
||||
public function GETitem( $id )
|
||||
public function GETitem( int $id ): Response
|
||||
{
|
||||
return $this->_view( $id );
|
||||
}
|
||||
@@ -99,11 +115,13 @@ class _entrycategories extends \IPS\Node\Api\NodeController
|
||||
* Delete an entry category
|
||||
*
|
||||
* @param int $id ID Number
|
||||
* @return void
|
||||
* @apireturn void
|
||||
* @throws 2B408/5 INVALID_ID The category ID does not exist or the authorized user does not have permission to delete it
|
||||
* @return Response
|
||||
*/
|
||||
public function DELETEitem( $id )
|
||||
public function DELETEitem( int $id ): Response
|
||||
{
|
||||
/* @var Category $class */
|
||||
$class = $this->class;
|
||||
|
||||
try
|
||||
@@ -111,15 +129,15 @@ class _entrycategories extends \IPS\Node\Api\NodeController
|
||||
$category = $class::load( $id );
|
||||
if ( !$category->canDelete( $this->member ) )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/5', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2B408/5', 404 );
|
||||
}
|
||||
$category->delete();
|
||||
|
||||
return new \IPS\Api\Response( 200, NULL );
|
||||
return new Response( 200, NULL );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\Exception( 'INVALID_ID', '2B408/6', 404 );
|
||||
throw new Exception( 'INVALID_ID', '2B408/6', 404 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user