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,9 +12,18 @@
|
||||
namespace IPS\nexus\CommissionRule;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Countable;
|
||||
use FilterIterator;
|
||||
use IPS\Db;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Invoice;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -22,47 +31,47 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
* Commission Rule Filter Iterator
|
||||
* @note When we require PHP 5.4+ this can just be replaced with a CallbackFilterIterator
|
||||
*/
|
||||
class _Iterator extends \FilterIterator implements \Countable
|
||||
class Iterator extends FilterIterator implements Countable
|
||||
{
|
||||
/**
|
||||
* @brief Member
|
||||
*/
|
||||
protected $member;
|
||||
protected ?Member $member = NULL;
|
||||
|
||||
/**
|
||||
* @brief Number of purchases
|
||||
*/
|
||||
protected $numberOfPurchases = NULL;
|
||||
protected ?int $numberOfPurchases = NULL;
|
||||
|
||||
/**
|
||||
* @brief Value of purchases
|
||||
*/
|
||||
protected $valueOfPurchases = NULL;
|
||||
protected mixed $valueOfPurchases = NULL;
|
||||
|
||||
/**
|
||||
* @brief Number of referral rules
|
||||
*/
|
||||
protected $numberOfRules= NULL;
|
||||
protected ?int $numberOfRules= NULL;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param \IPS\Patterns\ActiveRecordIterator $iterator Iterator
|
||||
* @param \IPS\Member $member Member
|
||||
* @param ActiveRecordIterator $iterator Iterator
|
||||
* @param Member $member Member
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( \IPS\Patterns\ActiveRecordIterator $iterator, \IPS\Member $member )
|
||||
public function __construct( ActiveRecordIterator $iterator, Member $member )
|
||||
{
|
||||
$this->member = $member;
|
||||
return parent::__construct( $iterator );
|
||||
parent::__construct( $iterator );
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this rule apply?
|
||||
*
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function accept()
|
||||
public function accept(): bool
|
||||
{
|
||||
$rule = $this->getInnerIterator()->current();
|
||||
|
||||
@@ -129,11 +138,11 @@ class _Iterator extends \FilterIterator implements \Countable
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function numberOfPurchases()
|
||||
protected function numberOfPurchases(): int
|
||||
{
|
||||
if ( $this->numberOfPurchases === NULL )
|
||||
{
|
||||
$this->numberOfPurchases = \IPS\Db::i()->select( 'COUNT( i_id )', 'nexus_invoices', array( "i_member=? AND i_status=?", $this->member->member_id, \IPS\nexus\Invoice::STATUS_PAID ) )->first();
|
||||
$this->numberOfPurchases = Db::i()->select( 'COUNT( i_id )', 'nexus_invoices', array( "i_member=? AND i_status=?", $this->member->member_id, Invoice::STATUS_PAID ) )->first();
|
||||
}
|
||||
return $this->numberOfPurchases;
|
||||
}
|
||||
@@ -141,13 +150,13 @@ class _Iterator extends \FilterIterator implements \Countable
|
||||
/**
|
||||
* Get the amounts spent
|
||||
*
|
||||
* @return int
|
||||
* @return mixed
|
||||
*/
|
||||
protected function valueOfPurchases()
|
||||
protected function valueOfPurchases(): mixed
|
||||
{
|
||||
if ( $this->valueOfPurchases === NULL )
|
||||
{
|
||||
$this->valueOfPurchases = iterator_to_array( \IPS\Db::i()->select( 'i_currency, SUM( i_total ) as value', 'nexus_invoices', array( "i_member=? AND i_status=?", $this->member->member_id, \IPS\nexus\Invoice::STATUS_PAID ), NULL, NULL, 'i_currency' )->setKeyField( 'i_currency' )->setValueField( 'value' ) );
|
||||
$this->valueOfPurchases = iterator_to_array( Db::i()->select( 'i_currency, SUM( i_total ) as value', 'nexus_invoices', array( "i_member=? AND i_status=?", $this->member->member_id, Invoice::STATUS_PAID ), NULL, NULL, 'i_currency' )->setKeyField( 'i_currency' )->setValueField( 'value' ) );
|
||||
}
|
||||
return $this->valueOfPurchases;
|
||||
}
|
||||
@@ -161,7 +170,7 @@ class _Iterator extends \FilterIterator implements \Countable
|
||||
{
|
||||
if ( $this->numberOfRules === NULL )
|
||||
{
|
||||
$this->numberOfRules = (int) \IPS\Db::i()->select( 'COUNT(*)', 'nexus_referral_rules' )->first();
|
||||
$this->numberOfRules = (int) Db::i()->select( 'COUNT(*)', 'nexus_referral_rules' )->first();
|
||||
}
|
||||
return $this->numberOfRules;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user