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
File diff suppressed because it is too large.
Load diff
@@ -11,43 +11,53 @@
|
||||
namespace IPS\nexus;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Subscription\Package;
|
||||
use IPS\Patterns\ActiveRecord;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* User subscription model
|
||||
*/
|
||||
class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
class Subscription extends ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'nexus_member_subscriptions';
|
||||
public static ?string $databaseTable = 'nexus_member_subscriptions';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'sub_';
|
||||
public static string $databasePrefix = 'sub_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array( 'sub_purchase_id' );
|
||||
protected static array $databaseIdFields = array( 'sub_purchase_id' );
|
||||
|
||||
/**
|
||||
* Get the DateTime object for when this little subscription doth run out
|
||||
*
|
||||
* @return \IPS\DateTime|NULL
|
||||
* @return DateTime|NULL
|
||||
*/
|
||||
public function get__expire()
|
||||
public function get__expire() : DateTime|null
|
||||
{
|
||||
if ( $this->expire )
|
||||
{
|
||||
@@ -56,17 +66,17 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
/* This has been invoiced, so there is a purchase row - fetch the expiration from that */
|
||||
try
|
||||
{
|
||||
$purchase = \IPS\nexus\Purchase::load( $this->purchase_id );
|
||||
$purchase = Purchase::load( $this->purchase_id );
|
||||
|
||||
if ( $purchase->expire )
|
||||
{
|
||||
return $purchase->expire;
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $e ) { }
|
||||
catch( OutOfRangeException ) { }
|
||||
}
|
||||
|
||||
return \IPS\DateTime::ts( $this->expire );
|
||||
return DateTime::ts( $this->expire );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -75,15 +85,15 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get the package (ooh, very mysterious, sounds like something from Narcos)
|
||||
*
|
||||
* @return \IPS\nexus\Subscription\Package or NULL, I don't really care at this point.
|
||||
* @return Package|null
|
||||
*/
|
||||
public function get_package()
|
||||
public function get_package() : Package|null
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Subscription\Package::load( $this->package_id );
|
||||
return Package::load( $this->package_id );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -92,15 +102,15 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Get the purchase
|
||||
*
|
||||
* @return \IPS\nexus\Subscription\Package or NULL, I don't really care at this point.
|
||||
* @return Purchase|null
|
||||
*/
|
||||
public function get_purchase()
|
||||
public function get_purchase() : Purchase|null
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\nexus\Purchase::load( $this->purchase_id );
|
||||
return Purchase::load( $this->purchase_id );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -109,11 +119,11 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Change the subscription package
|
||||
*
|
||||
* @param \IPS\nexus\Subscription\Package $package The new package innit
|
||||
* @param \IPS\DateTime|NULL $expires The new expiration date
|
||||
* @param Package $package The new package innit
|
||||
* @param DateTime|NULL $expires The new expiration date
|
||||
* @return void
|
||||
*/
|
||||
public function changePackage( \IPS\nexus\Subscription\Package $package, $expires=NULL )
|
||||
public function changePackage( Package $package, ?DateTime $expires=NULL ) : void
|
||||
{
|
||||
$this->package_id = $package->id;
|
||||
$this->expire = ( $expires === NULL ) ? 0 : $expires->getTimeStamp();
|
||||
@@ -126,36 +136,36 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function currentBlurb()
|
||||
public function currentBlurb() : string
|
||||
{
|
||||
if ( !$this->active AND !$this->purchase->cancelled )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_expired' );
|
||||
return Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_expired' );
|
||||
}
|
||||
elseif( $this->purchase->cancelled AND $this->purchase->can_reactivate )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_cancelled' );
|
||||
return Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_cancelled' );
|
||||
}
|
||||
elseif( $this->purchase->cancelled )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_cancelled_no_reactivate' );
|
||||
return Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_cancelled_no_reactivate' );
|
||||
}
|
||||
if ( $this->expire and $this->renews and !$this->manually_added )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_with_expire' . ( ( $this->purchase and $this->purchase->renewals ) ? '' : '_no_renewal' ), NULL, array( 'sprintf' => array( $this->_expire->dayAndMonth() . ' ' . $this->_expire->format('Y') ) ) );
|
||||
return Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed_with_expire' . ( ( $this->purchase and $this->purchase->renewals ) ? '' : '_no_renewal' ), NULL, array( 'sprintf' => array( $this->_expire->dayAndMonth() . ' ' . $this->_expire->format('Y') ) ) );
|
||||
}
|
||||
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed' );
|
||||
return Member::loggedIn()->language()->addToStack( 'nexus_subs_subscribed' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Find and return the package this person is currently subscribed to, or NULL
|
||||
*
|
||||
* @param \IPS\Member $member The member
|
||||
* @param Member $member The member
|
||||
* @param bool $activeOnly If TRUE, returns only active subscription
|
||||
* @return ?\IPS\nexus\Subscription
|
||||
* @return static|ActiveRecord|null
|
||||
*/
|
||||
public static function loadByMember( \IPS\Member $member, bool $activeOnly )
|
||||
public static function loadByMember( Member $member, bool $activeOnly ) : static|ActiveRecord|null
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -166,9 +176,9 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
$where[] = [ 'sub_active=1' ];
|
||||
}
|
||||
|
||||
return static::constructFromData( \IPS\Db::i()->select( '*', 'nexus_member_subscriptions', $where, 'sub_active DESC, sub_start DESC' )->first() );
|
||||
return static::constructFromData( Db::i()->select( '*', 'nexus_member_subscriptions', $where, 'sub_active DESC, sub_start DESC' )->first() );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -177,25 +187,25 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
/**
|
||||
* Find and return the package this person is currently subscribed to, or NULL
|
||||
*
|
||||
* @param \IPS\Member|NULL $member Pass a member in if you like, no pressure really up to you
|
||||
* @return \IPS\nexus\Subscription or NULL
|
||||
* @param Member|NULL $member Pass a member in if you like, no pressure really up to you
|
||||
* @return static|null
|
||||
* @deprecated Use loadByMember() instead
|
||||
*/
|
||||
public static function loadActiveByMember( $member=NULL )
|
||||
public static function loadActiveByMember( ?Member $member=NULL ) : static|null
|
||||
{
|
||||
return static::loadByMember( $member ? $member : \IPS\Member::loggedIn(), TRUE );
|
||||
return static::loadByMember( $member ?: Member::loggedIn(), TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a subscription by member and package
|
||||
*
|
||||
* @param \IPS\Member $member Take a guess
|
||||
* @param \IPS\nexus\Subscription\Package $package I mean it's really writing itself
|
||||
* @param Member $member Take a guess
|
||||
* @param Package $package I mean it's really writing itself
|
||||
* @param boolean $activeOnly Only get active packages
|
||||
* @return \IPS\nexus\Subscription
|
||||
* @throws \OutOfRangeException
|
||||
* @return static|ActiveRecord
|
||||
* @throws OutOfRangeException
|
||||
*/
|
||||
public static function loadByMemberAndPackage( \IPS\Member $member, \IPS\nexus\Subscription\Package $package, $activeOnly = TRUE )
|
||||
public static function loadByMemberAndPackage( Member $member, Package $package, bool $activeOnly = TRUE ) : static|ActiveRecord
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -206,22 +216,22 @@ class _Subscription extends \IPS\Patterns\ActiveRecord
|
||||
$where[] = array( 'sub_active=1' );
|
||||
}
|
||||
|
||||
return static::constructFromData( \IPS\Db::i()->select( '*', 'nexus_member_subscriptions', $where )->first() );
|
||||
return static::constructFromData( Db::i()->select( '*', 'nexus_member_subscriptions', $where )->first() );
|
||||
}
|
||||
catch( \Exception $ex )
|
||||
catch( Exception )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark all subscriptions by this member as inactive
|
||||
*
|
||||
* @param \IPS\Member $member I dunno, take a guess
|
||||
* @param Member $member I dunno, take a guess
|
||||
* @return void
|
||||
*/
|
||||
public static function markInactiveByUser( \IPS\Member $member )
|
||||
public static function markInactiveByUser( Member $member ) : void
|
||||
{
|
||||
\IPS\Db::i()->update( 'nexus_member_subscriptions', array( 'sub_active' => 0 ), array( 'sub_member_id=?', $member->member_id ) );
|
||||
Db::i()->update( 'nexus_member_subscriptions', array( 'sub_active' => 0 ), array( 'sub_member_id=?', $member->member_id ) );
|
||||
}
|
||||
}
|
||||
@@ -11,74 +11,85 @@
|
||||
namespace IPS\nexus\Subscription;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Table\Table as TableHelper;
|
||||
use IPS\Http\Url;
|
||||
use IPS\nexus\Subscription;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function is_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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscriptions table
|
||||
*/
|
||||
class _Table extends \IPS\Helpers\Table\Table
|
||||
class Table extends TableHelper
|
||||
{
|
||||
/**
|
||||
* @brief Sort options
|
||||
*/
|
||||
public $sortOptions = array( 'sp_position' );
|
||||
public array $sortOptions = array( 'sp_position' );
|
||||
|
||||
/**
|
||||
* @brief Active Subscription
|
||||
*/
|
||||
public $activeSubscription = NULL;
|
||||
public Subscription|null $activeSubscription = NULL;
|
||||
|
||||
/**
|
||||
* @brief Rows
|
||||
*/
|
||||
protected static $rows = null;
|
||||
protected static ?array $rows = null;
|
||||
|
||||
/**
|
||||
* @brief WHERE clause
|
||||
*/
|
||||
protected $where = array();
|
||||
protected array $where = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\Http\Url $url Base URL
|
||||
* @param Url|null $url Base URL
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( \IPS\Http\Url $url=NULL )
|
||||
public function __construct( ?Url $url=NULL )
|
||||
{
|
||||
/* Init */
|
||||
parent::__construct( $url );
|
||||
|
||||
$this->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'subscription', 'nexus', 'front' ), 'table' );
|
||||
$this->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'subscription', 'nexus', 'front' ), 'rows' );
|
||||
$this->tableTemplate = array( Theme::i()->getTemplate( 'subscription', 'nexus', 'front' ), 'table' );
|
||||
$this->rowsTemplate = array( Theme::i()->getTemplate( 'subscription', 'nexus', 'front' ), 'rows' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rows
|
||||
*
|
||||
* @param array $advancedSearchValues Values from the advanced search form
|
||||
* @param array|null $advancedSearchValues Values from the advanced search form
|
||||
* @return array
|
||||
*/
|
||||
public function getRows( $advancedSearchValues=NULL )
|
||||
public function getRows( ?array $advancedSearchValues=NULL ): array
|
||||
{
|
||||
if ( static::$rows === NULL )
|
||||
{
|
||||
/* Check sortBy */
|
||||
$this->sortBy = \in_array( $this->sortBy, $this->sortOptions ) ? $this->sortBy : 'sp_position';
|
||||
$this->sortBy = in_array( $this->sortBy, $this->sortOptions ) ? $this->sortBy : 'sp_position';
|
||||
|
||||
/* What are we sorting by? */
|
||||
$sortBy = $this->sortBy . ' ' . ( mb_strtolower( $this->sortDirection ) == 'desc' ? 'desc' : 'asc' );
|
||||
$sortBy = $this->sortBy . ' ' . ( ( $this->sortDirection and mb_strtolower( $this->sortDirection ) == 'desc' ) ? 'desc' : 'asc' );
|
||||
|
||||
/* Specify filter in where clause */
|
||||
$where = isset( $this->where ) ? \is_array( $this->where ) ? $this->where : array( $this->where ) : array();
|
||||
$where = $this->where;
|
||||
|
||||
if ( $this->filter and isset( $this->filters[ $this->filter ] ) )
|
||||
{
|
||||
$where[] = \is_array( $this->filters[ $this->filter ] ) ? $this->filters[ $this->filter ] : array( $this->filters[ $this->filter ] );
|
||||
$where[] = is_array( $this->filters[ $this->filter ] ) ? $this->filters[ $this->filter ] : array( $this->filters[ $this->filter ] );
|
||||
}
|
||||
|
||||
// We want also the disabled but active subscription
|
||||
@@ -92,20 +103,21 @@ class _Table extends \IPS\Helpers\Table\Table
|
||||
}
|
||||
|
||||
/* Get Count */
|
||||
$count = \IPS\Db::i()->select( 'COUNT(*) as cnt', 'nexus_member_subscription_packages', $where )->first();
|
||||
$count = Db::i()->select( 'COUNT(*) as cnt', 'nexus_member_subscription_packages', $where )->first();
|
||||
$this->pages = ceil( $count / $this->limit );
|
||||
|
||||
/* Get results */
|
||||
$it = \IPS\Db::i()->select( '*', 'nexus_member_subscription_packages', $where, $sortBy, array( ( $this->limit * ( $this->page - 1 ) ), $this->limit ) );
|
||||
$it = Db::i()->select( '*', 'nexus_member_subscription_packages', $where, $sortBy, array( ( $this->limit * ( $this->page - 1 ) ), $this->limit ) );
|
||||
$rows = iterator_to_array( $it );
|
||||
|
||||
|
||||
static::$rows = array();
|
||||
foreach( $rows as $index => $row )
|
||||
{
|
||||
try
|
||||
{
|
||||
static::$rows[ $index ] = \IPS\nexus\Subscription\Package::constructFromData( $row );
|
||||
static::$rows[ $index ] = Package::constructFromData( $row );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
catch ( Exception ) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +131,7 @@ class _Table extends \IPS\Helpers\Table\Table
|
||||
* @param array|NULL $advancedSearchValues Advanced search values
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders( $advancedSearchValues )
|
||||
public function getHeaders( array $advancedSearchValues=NULL ): array
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user