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

+185 -154
View File
@@ -11,16 +11,36 @@
namespace IPS\core\api;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use IPS\Api\Controller;
use IPS\Api\Exception;
use IPS\Api\PaginatedResponse;
use IPS\Api\Response;
use IPS\Application;
use IPS\core\extensions\nexus\Item\ClubMembership;
use IPS\Db;
use IPS\GeoLocation;
use IPS\Member;
use IPS\Member\Club;
use IPS\nexus\Customer;
use IPS\Request;
use IPS\Settings;
use IPS\Task;
use OutOfRangeException;
use function defined;
use function in_array;
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 Clubs API
*/
class _clubs extends \IPS\Api\Controller
class clubs extends Controller
{
/**
* GET /core/clubs
@@ -30,18 +50,19 @@ class _clubs extends \IPS\Api\Controller
* @apiparam int perPage Number of results per page - defaults to 25
* @apiparam int member_id Member ID to return only clubs the member is allowed to view.
* @note For requests using an OAuth Access Token for a particular member, only clubs the authorized user can view will be included and the member_id parameter will be ignored.
* @return \IPS\Api\PaginatedResponse<IPS\Member\Club>
* @apireturn PaginatedResponse<IPS\Member\Club>
* @return PaginatedResponse<Club>
*/
public function GETindex()
public function GETindex(): PaginatedResponse
{
$page = isset( \IPS\Request::i()->page ) ? \IPS\Request::i()->page : 1;
$perPage = isset( \IPS\Request::i()->perPage ) ? \IPS\Request::i()->perPage : 25;
$page = isset( Request::i()->page ) ? Request::i()->page : 1;
$perPage = isset( Request::i()->perPage ) ? Request::i()->perPage : 25;
$forMember = $this->member;
if( !$this->member AND isset( \IPS\Request::i()->member_id ) )
if( !$this->member AND isset( Request::i()->member_id ) )
{
$forMember = \IPS\Member::load( \IPS\Request::i()->member_id );
$forMember = Member::load( Request::i()->member_id );
if( !$forMember->member_id )
{
@@ -50,12 +71,12 @@ class _clubs extends \IPS\Api\Controller
}
/* Return */
return new \IPS\Api\PaginatedResponse(
return new PaginatedResponse(
200,
\IPS\Member\Club::clubs( $forMember, array( ( $page - 1 ) * $perPage, $perPage ), 'created' ),
Club::clubs( $forMember, array( ( $page - 1 ) * $perPage, $perPage ), 'created' ),
$page,
'IPS\Member\Club',
\IPS\Member\Club::clubs( $forMember, array( ( $page - 1 ) * $perPage, $perPage ), 'created', FALSE, array(), NULL, TRUE ),
Club::clubs( $forMember, array( ( $page - 1 ) * $perPage, $perPage ), 'created', FALSE, array(), NULL, TRUE ),
$this->member,
$perPage
);
@@ -67,23 +88,24 @@ class _clubs extends \IPS\Api\Controller
*
* @param int $id ID Number
* @throws 1C386/1 INVALID_ID The club does not exist or the authorized user does not have permission to view it
* @return \IPS\Member\Club
* @apireturn \IPS\Member\Club
* @return Response
*/
public function GETitem( $id )
public function GETitem( int $id ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
if ( $this->member and !$club->canView( $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
return new \IPS\Api\Response( 200, $club->apiOutput( $this->member ) );
return new Response( 200, $club->apiOutput( $this->member ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C386/1', 404 );
throw new Exception( 'INVALID_ID', '1C386/1', 404 );
}
}
@@ -102,26 +124,27 @@ class _clubs extends \IPS\Api\Controller
* @apiparam string showMemberTab Who can see the list of members: nonmember = Everyone can see, member = Only members can see, moderator = Only moderators can see. Defaults to nonmember.
* @apiparam \IPS\nexus\Money joiningFee Cost to join the club (Nexus must be installed, paid clubs must be enabled, and the owner must be allowed to create paid clubs)
* @apiparam \IPS\nexus\Purchase\RenewalTerm renewalTerm Renewal term for the club (joiningFee must be set)
* @return \IPS\Member\Club
* @apireturn \IPS\Member\Club
* @note For requests using an OAuth Access Token for a particular member, the authorized user will be the club owner, otherwise you must pass an owner parameter with a valid member ID to set the club owner
* @throws 1C386/3 OWNER_REQUIRED An owner for the club is required. For requests NOT using an OAuth Access Token for a particular member, you must supply a member ID for the owner property
* @throws 1C386/4 NAME_REQUIRED A name is required for the club
* @throws 1C386/J CANNOT_CREATE The authorized member or supplied owner cannot create the type of club requested
* @throws 1C386/K CLUB_LIMIT_REACHED The authorized member or supplied owner has reached the maximum number of clubs they are allowed to create based on group restrictions
* @return Response
*/
public function POSTindex()
public function POSTindex(): Response
{
/* We need an owner */
if( !$this->member AND !\IPS\Request::i()->owner )
if( !$this->member AND !Request::i()->owner )
{
throw new \IPS\Api\Exception( 'OWNER_REQUIRED', '1C386/3', 400 );
throw new Exception( 'OWNER_REQUIRED', '1C386/3', 400 );
}
$owner = $this->member ?: \IPS\Member::load( \IPS\Request::i()->owner );
$owner = $this->member ?: Member::load( Request::i()->owner );
if( !\IPS\Request::i()->name )
if( !Request::i()->name )
{
throw new \IPS\Api\Exception( 'NAME_REQUIRED', '1C386/4', 400 );
throw new Exception( 'NAME_REQUIRED', '1C386/4', 400 );
}
$availableTypes = array();
@@ -135,40 +158,40 @@ class _clubs extends \IPS\Api\Controller
}
/* Default club type to 'open' if not specified */
if( !isset( \IPS\Request::i()->type ) OR !\IPS\Request::i()->type )
if( !isset( Request::i()->type ) OR !Request::i()->type )
{
\IPS\Request::i()->type = 'open';
Request::i()->type = 'open';
}
if ( !$availableTypes OR !\in_array( \IPS\Request::i()->type, array_keys( $availableTypes ) ) )
if ( !$availableTypes OR !in_array( Request::i()->type, array_keys( $availableTypes ) ) )
{
throw new \IPS\Api\Exception( 'CANNOT_CREATE', '1C386/J', 403 );
throw new Exception( 'CANNOT_CREATE', '1C386/J', 403 );
}
if ( $owner->group['g_club_limit'] )
{
if ( \IPS\Db::i()->select( 'COUNT(*)', 'core_clubs', array( 'owner=?', $owner->member_id ) )->first() >= $owner->group['g_club_limit'] )
if ( Db::i()->select( 'COUNT(*)', 'core_clubs', array( 'owner=?', $owner->member_id ) )->first() >= $owner->group['g_club_limit'] )
{
throw new \IPS\Api\Exception( 'CLUB_LIMIT_REACHED', '1C386/K', 403 );
throw new Exception( 'CLUB_LIMIT_REACHED', '1C386/K', 403 );
}
}
$club = new \IPS\Member\Club;
$club = new Club;
$club->owner = $owner;
$this->setClubProperties( $club );
$club->save();
$club->addMember( $owner, \IPS\Member\Club::STATUS_LEADER );
$club->addMember( $owner, Club::STATUS_LEADER );
$club->recountMembers();
if( \IPS\Settings::i()->clubs_require_approval and !$club->approved )
if( Settings::i()->clubs_require_approval and !$club->approved )
{
$club->sendModeratorApprovalNotification( $owner );
}
return new \IPS\Api\Response( 201, $club->apiOutput( $this->member ) );
return new Response( 201, $club->apiOutput( $this->member ) );
}
/**
@@ -186,28 +209,29 @@ class _clubs extends \IPS\Api\Controller
* @apiparam \IPS\nexus\Money joiningFee Cost to join the club (Nexus must be installed, paid clubs must be enabled, and the owner must be allowed to create paid clubs)
* @apiparam \IPS\nexus\Purchase\RenewalTerm renewalTerm Renewal term for the club (joiningFee must be set)
* @param int $id ID Number
* @return \IPS\Member\Club
* @apireturn \IPS\Member\Club
* @throws 1C386/5 INVALID_ID The club ID was invalid or the authorized member does not have permission to edit it
* @throws 1C386/L CANNOT_CREATE The authorized member or supplied owner cannot create the type of club requested
* @return Response
*/
public function POSTitem( $id )
public function POSTitem( int $id ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
if( $this->member AND !$club->isLeader( $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C386/5', 404 );
throw new Exception( 'INVALID_ID', '1C386/5', 404 );
}
/* Make sure the club type is allowed */
if( isset( \IPS\Request::i()->type ) )
if( isset( Request::i()->type ) )
{
$owner = $this->member ?: $club->owner;
@@ -221,9 +245,9 @@ class _clubs extends \IPS\Api\Controller
}
}
if ( !$availableTypes OR !\in_array( \IPS\Request::i()->type, array_keys( $availableTypes ) ) )
if ( !$availableTypes OR !in_array( Request::i()->type, array_keys( $availableTypes ) ) )
{
throw new \IPS\Api\Exception( 'CANNOT_CREATE', '1C386/L', 403 );
throw new Exception( 'CANNOT_CREATE', '1C386/L', 403 );
}
}
@@ -231,61 +255,61 @@ class _clubs extends \IPS\Api\Controller
$club->save();
return new \IPS\Api\Response( 200, $club->apiOutput( $this->member ) );
return new Response( 200, $club->apiOutput( $this->member ) );
}
/**
* Set common club properties
*
* @param \IPS\Member\Club $club The club object to set the properties on
* @param Club $club The club object to set the properties on
* @return void
*/
protected function setClubProperties( $club )
protected function setClubProperties( Club $club ) : void
{
if( \IPS\Request::i()->name )
if( Request::i()->name )
{
$club->name = \IPS\Request::i()->name;
$club->name = Request::i()->name;
}
if( isset( \IPS\Request::i()->about ) )
if( isset( Request::i()->about ) )
{
$club->about = \IPS\Request::i()->about;
$club->about = Request::i()->about;
}
if( isset( \IPS\Request::i()->showMemberTab ) AND \in_array( \IPS\Request::i()->showMemberTab, array( 'member', 'nonmember', 'moderator' ) ) )
if( isset( Request::i()->showMemberTab ) AND in_array( Request::i()->showMemberTab, array( 'member', 'nonmember', 'moderator' ) ) )
{
$club->show_membertab = \IPS\Request::i()->showMemberTab;
$club->show_membertab = Request::i()->showMemberTab;
}
else
{
$club->show_membertab = 'nonmember';
}
if( isset( \IPS\Request::i()->type ) AND \in_array( \IPS\Request::i()->type, array( 'open', 'public', 'readonly', 'closed', 'private' ) ) )
if( isset( Request::i()->type ) AND in_array( Request::i()->type, array( 'open', 'public', 'readonly', 'closed', 'private' ) ) )
{
$club->type = \IPS\Request::i()->type;
$club->type = Request::i()->type;
}
if( !$this->member AND isset( \IPS\Request::i()->approved ) )
if( !$this->member AND isset( Request::i()->approved ) )
{
$club->approved = \IPS\Request::i()->approved;
$club->approved = Request::i()->approved;
}
/* Set club approval based on AdminCP settings, but only if this is a new club */
elseif( !$club->id )
{
$club->approved = \IPS\Settings::i()->clubs_require_approval ? 0 : 1;
$club->approved = Settings::i()->clubs_require_approval ? 0 : 1;
}
if( !$this->member AND isset( \IPS\Request::i()->featured ) )
if( !$this->member AND isset( Request::i()->featured ) )
{
$club->featured = \IPS\Request::i()->featured;
$club->featured = Request::i()->featured;
}
if( \IPS\Settings::i()->clubs_locations AND isset( \IPS\Request::i()->lat ) AND isset( \IPS\Request::i()->long ) )
if( Settings::i()->clubs_locations AND isset( Request::i()->lat ) AND isset( Request::i()->long ) )
{
try
{
$location = \IPS\GeoLocation::getByLatLong( \IPS\Request::i()->lat, \IPS\Request::i()->long );
$location = GeoLocation::getByLatLong( Request::i()->lat, Request::i()->long );
$club->location_json = json_encode( $location );
$club->location_lat = $location->lat;
@@ -294,17 +318,17 @@ class _clubs extends \IPS\Api\Controller
catch( \Exception $e ){}
}
if( isset( \IPS\Request::i()->joiningFee ) AND \IPS\Request::i()->joiningFee )
if( isset( Request::i()->joiningFee ) AND Request::i()->joiningFee )
{
if ( $club->owner->member_id AND \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->clubs_paid_on and $club->owner->group['gbw_paid_clubs'] )
if ( $club->owner->member_id AND Application::appIsEnabled( 'nexus' ) and Settings::i()->clubs_paid_on and $club->owner->group['gbw_paid_clubs'] )
{
$club->fee = json_encode( \IPS\Request::i()->joiningFee );
$club->fee = json_encode( Request::i()->joiningFee );
if ( isset( \IPS\Request::i()->renewalTerm ) AND \IPS\Request::i()->renewalTerm )
if ( isset( Request::i()->renewalTerm ) AND Request::i()->renewalTerm )
{
$club->renewal_term = \IPS\Request::i()->renewalTerm['term'];
$club->renewal_units = \IPS\Request::i()->renewalTerm['unit'];
$club->renewal_price = json_encode( \IPS\Request::i()->renewalTerm['cost'] );
$club->renewal_term = Request::i()->renewalTerm['term'];
$club->renewal_units = Request::i()->renewalTerm['unit'];
$club->renewal_price = json_encode( Request::i()->renewalTerm['cost'] );
}
else
{
@@ -322,24 +346,25 @@ class _clubs extends \IPS\Api\Controller
*
* @apiclientonly
* @param int $id ID Number
* @return null
* @apireturn null
* @throws 1C386/2 INVALID_ID The club does not exist
* @return Response
*/
public function DELETEitem( $id )
public function DELETEitem( int $id ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
/* Deletions cannot be performed by a regular user */
if( $this->member )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
catch ( \Exception $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C386/2', 404 );
throw new Exception( 'INVALID_ID', '1C386/2', 404 );
}
/* Get nodes and queue for deletion */
@@ -364,7 +389,7 @@ class _clubs extends \IPS\Api\Controller
foreach ( $nodesToQueue as $_node )
{
\IPS\Task::queue( 'core', 'DeleteOrMoveContent', array( 'class' => $class, 'id' => $_node->_id, 'deleteWhenDone' => TRUE, 'additional' => array() ) );
Task::queue( 'core', 'DeleteOrMoveContent', array( 'class' => $class, 'id' => $_node->_id, 'deleteWhenDone' => TRUE, 'additional' => array() ) );
}
}
catch( \Exception $e ){}
@@ -372,11 +397,11 @@ class _clubs extends \IPS\Api\Controller
/* Now delete the club and associated data */
$club->delete();
\IPS\Db::i()->delete( 'core_clubs_memberships', array( 'club_id=?', $club->id ) );
\IPS\Db::i()->delete( 'core_clubs_node_map', array( 'club_id=?', $club->id ) );
\IPS\Db::i()->delete( 'core_clubs_fieldvalues', array( 'club_id=?', $club->id ) );
Db::i()->delete( 'core_clubs_memberships', array( 'club_id=?', $club->id ) );
Db::i()->delete( 'core_clubs_node_map', array( 'club_id=?', $club->id ) );
Db::i()->delete( 'core_clubs_fieldvalues', array( 'club_id=?', $club->id ) );
return new \IPS\Api\Response( 200, NULL );
return new Response( 200, NULL );
}
/**
@@ -390,21 +415,22 @@ class _clubs extends \IPS\Api\Controller
* @apiresponse [\IPS\Member] members Club members
* @apiresponse [\IPS\Member] leaders Club leaders
* @apiresponse [\IPS\Member] moderators Club moderators
* @return array
* @apireturn array
* @return Response
*/
public function GETitem_members( $id )
public function GETitem_members( int $id ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
if( $this->member AND !$club->canView( $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
elseif( $club->type === \IPS\Member\Club::TYPE_PUBLIC )
elseif( $club->type === Club::TYPE_PUBLIC )
{
throw new \BadMethodCallException;
throw new BadMethodCallException;
}
$members = array();
@@ -413,7 +439,7 @@ class _clubs extends \IPS\Api\Controller
foreach( $club->members( array( 'member', 'moderator', 'leader' ), 250, 'core_clubs_memberships.joined DESC', 2 ) as $member )
{
$member = \IPS\Member::constructFromData( $member );
$member = Member::constructFromData( $member );
if( $club->owner != $member )
{
@@ -432,15 +458,15 @@ class _clubs extends \IPS\Api\Controller
}
}
return new \IPS\Api\Response( 200, array( 'owner' => $club->owner ? $club->owner->apiOutput() : NULL, 'members' => $members, 'leaders' => $leaders, 'moderators' => $moderators ) );
return new Response( 200, array( 'owner' => $club->owner ? $club->owner->apiOutput() : NULL, 'members' => $members, 'leaders' => $leaders, 'moderators' => $moderators ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C386/6', 404 );
throw new Exception( 'INVALID_ID', '1C386/6', 404 );
}
catch( \BadMethodCallException $e )
catch( BadMethodCallException $e )
{
throw new \IPS\Api\Exception( 'NO_MEMBERS_PUBLIC_CLUB', '1C386/I', 400 );
throw new Exception( 'NO_MEMBERS_PUBLIC_CLUB', '1C386/I', 400 );
}
}
@@ -454,33 +480,34 @@ class _clubs extends \IPS\Api\Controller
* @apiparam int waiveFee If set to 1 and the request is made by a club leader, the join fee will be waived for the member being invited
* @throws 1C386/7 INVALID_ID The club does not exist or the authorized user does not have permission to add members to it
* @throws 1C386/8 INVALID_MEMBER The member to be added could not be found or the member cannot join the club
* @return array
* @apireturn array
* @apiresponse \IPS\Member owner Club owner
* @apiresponse [\IPS\Member] members Club members
* @apiresponse [\IPS\Member] leaders Club leaders
* @apiresponse [\IPS\Member] moderators Club moderators
* @note If the member already exists they will be updated. This can be used to ban a member from a club or promote a member to a leader, for instance.
* @note If using an API key, the id parameter is required and will indicate the member being added to the club. If using an OAuth access token and the request is made by a club leader, the id parameter is required. If the user is already a member of the club they can be moved to a different status (such as banned or moderator), and if the user is not a member of the club, they will be invited (and the waiveFee parameter can be passed to bypass any club joining fee). If using an OAuth access token and no id is passed, a request to join will be submitted if necessary, or they will be added to the club (the status parameter is ignored). Finally, if using an OAuth access token and an id parameter is provided, an invitation will be sent to that user.
* @return Response
*/
public function POSTitem_members( $id )
public function POSTitem_members( int $id ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
if( $this->member AND isset( \IPS\Request::i()->id ) )
if( $this->member AND isset( Request::i()->id ) )
{
$member = \IPS\Member::load( \IPS\Request::i()->id );
$member = Member::load( Request::i()->id );
}
else
{
$member = $this->member ?: \IPS\Member::load( \IPS\Request::i()->id );
$member = $this->member ?: Member::load( Request::i()->id );
}
/* Do we have the member? */
if( !$member OR !$member->member_id )
{
throw new \IPS\Api\Exception( 'INVALID_MEMBER', '1C386/8', 404 );
throw new Exception( 'INVALID_MEMBER', '1C386/8', 404 );
}
$currentStatus = $club->memberStatus( $member );
@@ -488,65 +515,65 @@ class _clubs extends \IPS\Api\Controller
/* If this is an API key request, just do it */
if( !$this->member )
{
$newStatus = \IPS\Request::i()->status ?: \IPS\Member\Club::STATUS_MEMBER;
$newStatus = Request::i()->status ?: Club::STATUS_MEMBER;
if( !\in_array( $newStatus, array( \IPS\Member\Club::STATUS_MEMBER, \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_REQUESTED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT, \IPS\Member\Club::STATUS_WAITING_PAYMENT, \IPS\Member\Club::STATUS_EXPIRED, \IPS\Member\Club::STATUS_EXPIRED_MODERATOR, \IPS\Member\Club::STATUS_DECLINED, \IPS\Member\Club::STATUS_BANNED, \IPS\Member\Club::STATUS_MODERATOR, \IPS\Member\Club::STATUS_LEADER ) ) )
if( !in_array( $newStatus, array( Club::STATUS_MEMBER, Club::STATUS_INVITED, Club::STATUS_REQUESTED, Club::STATUS_INVITED_BYPASSING_PAYMENT, Club::STATUS_WAITING_PAYMENT, Club::STATUS_EXPIRED, Club::STATUS_EXPIRED_MODERATOR, Club::STATUS_DECLINED, Club::STATUS_BANNED, Club::STATUS_MODERATOR, Club::STATUS_LEADER ) ) )
{
$newStatus = \IPS\Member\Club::STATUS_MEMBER;
$newStatus = Club::STATUS_MEMBER;
}
$club->addMember( $member, $newStatus, TRUE );
}
/* If this is an OAuth member request for their _own_ account, we need to check joining fees, etc. */
elseif( $this->member AND $member == $this->member )
elseif( $member === $this->member )
{
if( !$club->canJoin( $member ) )
{
throw new \IPS\Api\Exception( 'CANNOT_JOIN', '1C386/M', 403 );
throw new Exception( 'CANNOT_JOIN', '1C386/M', 403 );
}
/* If this is an open club, or the member was invited, or they have mod access anyway go ahead and add them */
if ( \in_array( $currentStatus, array( \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT, \IPS\Member\Club::STATUS_WAITING_PAYMENT ) ) or $club->type === \IPS\Member\Club::TYPE_OPEN or $member->modPermission('can_access_all_clubs') )
if ( in_array( $currentStatus, array( Club::STATUS_INVITED, Club::STATUS_INVITED_BYPASSING_PAYMENT, Club::STATUS_WAITING_PAYMENT ) ) or $club->type === Club::TYPE_OPEN or $member->modPermission('can_access_all_clubs') )
{
/* Unless they have to pay */
if ( $club->isPaid() and $currentStatus !== \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT )
if ( $club->isPaid() and $currentStatus !== Club::STATUS_INVITED_BYPASSING_PAYMENT )
{
if ( $club->joiningFee() )
{
$club->generateInvoice( \IPS\nexus\Customer::load( $member->member_id ) );
$club->generateInvoice( Customer::load( $member->member_id ) );
}
}
else
{
$club->addMember( $member, \IPS\Member\Club::STATUS_MEMBER, TRUE, NULL, NULL, TRUE );
$club->addMember( $member, Club::STATUS_MEMBER, TRUE, NULL, NULL, TRUE );
$club->recountMembers();
}
}
/* Otherwise, add the request */
else
{
$club->addMember( $member, \IPS\Member\Club::STATUS_REQUESTED, TRUE, ( $this->member AND $this->member != $member ) ? $this->member : NULL );
$club->addMember( $member, Club::STATUS_REQUESTED, TRUE );
}
}
/* If this is an OAuth request for someone else's account and we are not a leader, then we should send an invite */
elseif( $this->member AND $member != $this->member AND !$club->isLeader( $this->member ) )
elseif( !$club->isLeader( $this->member ) )
{
if ( !$club->canInvite( $this->member ) )
{
throw new \IPS\Api\Exception( 'CANNOT_INVITE', '1C386/N', 403 );
throw new Exception( 'CANNOT_INVITE', '1C386/N', 403 );
}
$club->addMember( $member, $club::STATUS_INVITED, TRUE, $member, $this->member, TRUE );
$club->sendInvitation( $this->member, array( $member ) );
}
/* And finally, if this is an OAuth request for someone else's account and we are the leader, we should either send an invite or promote the member if the status is mod/leader */
elseif( $this->member AND $member != $this->member AND $club->isLeader( $this->member ) )
elseif( $club->isLeader( $this->member ) )
{
/* If the member is not currently a part of the club, send an invite */
if( $currentStatus === NULL )
{
$status = $club::STATUS_INVITED;
if ( $club->isPaid() and \IPS\Request::i()->waiveFee )
if ( $club->isPaid() and Request::i()->waiveFee )
{
$status = $club::STATUS_INVITED_BYPASSING_PAYMENT;
}
@@ -554,13 +581,13 @@ class _clubs extends \IPS\Api\Controller
$club->addMember( $member, $status, TRUE, $this->member, $this->member, TRUE );
$club->sendInvitation( $this->member, array( $member ) );
}
elseif( !\in_array( \IPS\Request::i()->status, array( \IPS\Member\Club::STATUS_REQUESTED, \IPS\Member\Club::STATUS_INVITED, \IPS\Member\Club::STATUS_INVITED_BYPASSING_PAYMENT ) ) )
elseif( !in_array( Request::i()->status, array( Club::STATUS_REQUESTED, Club::STATUS_INVITED, Club::STATUS_INVITED_BYPASSING_PAYMENT ) ) )
{
$club->addMember( $member, \IPS\Request::i()->status, TRUE, $this->member, $this->member, TRUE );
$club->addMember( $member, Request::i()->status, TRUE, $this->member, $this->member, TRUE );
}
else
{
throw new \IPS\Api\Exception( 'CANNOT_INVITE', '1C386/O', 403 );
throw new Exception( 'CANNOT_INVITE', '1C386/O', 403 );
}
}
@@ -568,9 +595,9 @@ class _clubs extends \IPS\Api\Controller
return $this->GETitem_members( $id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C386/7', 404 );
throw new Exception( 'INVALID_ID', '1C386/7', 404 );
}
}
@@ -586,33 +613,34 @@ class _clubs extends \IPS\Api\Controller
* @apiresponse [\IPS\Member] members Club members
* @apiresponse [\IPS\Member] leaders Club leaders
* @apiresponse [\IPS\Member] moderators Club moderators
* @return array
* @apireturn array
* @return Response
*/
public function DELETEitem_members( $id, $memberId = 0 )
public function DELETEitem_members( int $id, int $memberId = 0 ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
if( $this->member AND !$club->isLeader( $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
$member = \IPS\Member::load( $memberId );
$member = Member::load( $memberId );
if( !$member->member_id )
{
throw new \IPS\Api\Exception( 'INVALID_MEMBER', '1C386/9', 404 );
throw new Exception( 'INVALID_MEMBER', '1C386/9', 404 );
}
$club->removeMember( $member );
$club->recountMembers();
/* Cancel purchase */
if ( \IPS\Application::appIsEnabled('nexus') and \IPS\Settings::i()->clubs_paid_on )
if ( Application::appIsEnabled('nexus') and Settings::i()->clubs_paid_on )
{
foreach ( \IPS\core\extensions\nexus\Item\ClubMembership::getPurchases( \IPS\nexus\Customer::load( $member->member_id ), $club->id ) as $purchase )
foreach ( ClubMembership::getPurchases( Customer::load( $member->member_id ), $club->id ) as $purchase )
{
$purchase->cancelled = TRUE;
$purchase->member->log( 'purchase', array( 'type' => 'cancel', 'id' => $purchase->id, 'name' => $purchase->name, 'by' => 'api' ) );
@@ -623,9 +651,9 @@ class _clubs extends \IPS\Api\Controller
return $this->GETitem_members( $id );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C386/A', 404 );
throw new Exception( 'INVALID_ID', '1C386/A', 404 );
}
}
@@ -636,13 +664,14 @@ class _clubs extends \IPS\Api\Controller
* @apiparam int memberId Restrict the returned types to only those that can be created by the supplied member ID
* @note For requests using an OAuth Access Token for a particular member, the memberId parameter is ignored and the authorized member is checked
* @apiresponse array contentTypes Available content types
* @return array
* @apireturn array
* @return Response
*/
public function GETcontenttypes()
public function GETcontenttypes(): Response
{
$member = $this->member ?: ( ( isset( \IPS\Request::i()->memberId ) ) ? \IPS\Member::load( \IPS\Request::i()->memberId ) : NULL );
$member = $this->member ?: ( ( isset( Request::i()->memberId ) ) ? Member::load( Request::i()->memberId ) : NULL );
return new \IPS\Api\Response( 200, array( 'contentTypes' => \IPS\Member\Club::availableNodeTypes( $member ) ) );
return new Response( 200, array( 'contentTypes' => Club::availableNodeTypes( $member ) ) );
}
/**
@@ -652,17 +681,18 @@ class _clubs extends \IPS\Api\Controller
* @param int $id ID Number
* @throws 1C386/6 INVALID_ID The club does not exist or the authorized user does not have permission to view it
* @apiresponse [\IPS\Node\Model] nodes Club nodes
* @return array
* @apireturn array
* @return Response
*/
public function GETitem_nodes( $id )
public function GETitem_nodes( int $id ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
if( $this->member AND !$club->canView( $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
/* Format in a useful manner */
@@ -679,11 +709,11 @@ class _clubs extends \IPS\Api\Controller
}
}
return new \IPS\Api\Response( 200, array( 'nodes' => $nodes ) );
return new Response( 200, array( 'nodes' => $nodes ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_ID', '1C386/B', 404 );
throw new Exception( 'INVALID_ID', '1C386/B', 404 );
}
}
@@ -696,33 +726,34 @@ class _clubs extends \IPS\Api\Controller
* @reqapiparam string class Node (class) to remove
* @throws 1C386/H INVALID_ID The club does not exist or the current authorized member is not a leader of the club
* @throws 1C386/G INVALID_NODE The node to be deleted could not be found or the authorized user does not have permission to delete it
* @return null
* @apireturn void
* @return Response
*/
public function DELETEitem_nodes( $id )
public function DELETEitem_nodes( int $id ): Response
{
try
{
$club = \IPS\Member\Club::load( $id );
$club = Club::load( $id );
if( $this->member AND !$club->isLeader( $this->member ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
try
{
$class = \IPS\Request::i()->class;
$class = Request::i()->class;
if( !is_subclass_of( $class, "\IPS\Node\Model" ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
$node = $class::load( (int) \IPS\Request::i()->id );
$node = $class::load( (int) Request::i()->id );
if ( !$node->club() or $node->club()->id !== $club->id )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
/* Permission check */
@@ -731,23 +762,23 @@ class _clubs extends \IPS\Api\Controller
$itemClass = $node::$contentItemClass;
if ( !$node->modPermission( 'delete', $this->member ) and $itemClass::contentCount( $node, TRUE, TRUE, TRUE, 1 ) )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
throw new \IPS\Api\Exception( 'INVALID_NODE', '1C386/G', 404 );
throw new Exception( 'INVALID_NODE', '1C386/G', 404 );
}
\IPS\Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $class, $node->_id ) );
Db::i()->delete( 'core_clubs_node_map', array( 'club_id=? AND node_class=? AND node_id=?', $club->id, $class, $node->_id ) );
$node->deleteOrMoveFormSubmit( array() );
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', '1C386/H', 404 );
throw new Exception( 'INVALID_ID', '1C386/H', 404 );
}
}
}