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

+39 -25
View File
@@ -11,16 +11,27 @@
namespace IPS\core\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Api\Controller;
use IPS\Api\Exception;
use IPS\Api\PaginatedResponse;
use IPS\Api\Response;
use IPS\Db;
use IPS\Member\Group;
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 Member Groups API
*/
class _groups extends \IPS\Api\Controller
class groups extends Controller
{
/**
* GET /core/groups
@@ -28,22 +39,23 @@ class _groups extends \IPS\Api\Controller
*
* @apiparam int page Page number
* @apiparam int perPage Number of results per page - defaults to 25
* @return \IPS\Api\PaginatedResponse<IPS\Member\Group>
* @apireturn PaginatedResponse<IPS\Member\Group>
* @return PaginatedResponse<Group>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
/* Where clause */
$where = array();
/* Return */
return new \IPS\Api\PaginatedResponse(
return new PaginatedResponse(
200,
\IPS\Db::i()->select( '*', 'core_groups', $where, "g_id asc" ),
isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1,
Db::i()->select( '*', 'core_groups', $where, "g_id asc" ),
isset( Request::i()->page ) ? Request::i()->page : 1,
'IPS\Member\Group',
\IPS\Db::i()->select( 'COUNT(*)', 'core_groups', $where )->first(),
Db::i()->select( 'COUNT(*)', 'core_groups', $where )->first(),
$this->member,
isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : NULL
isset( Request::i()->perPage ) ? Request::i()->perPage : NULL
);
}
@@ -53,23 +65,24 @@ class _groups extends \IPS\Api\Controller
*
* @param int $id ID Number
* @throws 1C358/1 INVALID_ID The group ID does not exist
* @return \IPS\Member\Group
* @apireturn \IPS\Member\Group
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
try
{
$group = \IPS\Member\Group::load( $id );
$group = Group::load( $id );
if ( !$group->g_id )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
return new \IPS\Api\Response( 200, $group->apiOutput( $this->member ) );
return new Response( 200, $group->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C358/1', 404 );
throw new Exception( 'INVALID_ID', '1C358/1', 404 );
}
}
@@ -81,30 +94,31 @@ class _groups extends \IPS\Api\Controller
* @param int $id ID Number
* @throws 2C358/3 CANNOT_DELETE The group can't be deleted
* @throws 1C358/2 INVALID_ID The group ID does not exist
* @return void
* @apireturn void
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
try
{
$group = \IPS\Member\Group::load( $id );
$group = Group::load( $id );
if ( !$group->g_id )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
if( !$group->canDelete() )
{
throw new \IPS\Api\Exception( 'CANNOT_DELETE', '2C358/3', 403 );
throw new Exception( 'CANNOT_DELETE', '2C358/3', 403 );
}
$group->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', '1C358/2', 404 );
throw new Exception( 'INVALID_ID', '1C358/2', 404 );
}
}
}