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,16 +12,29 @@
|
||||
namespace IPS\nexus\Form;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\Helpers\Form\FormAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\nexus\Purchase\RenewalTerm as RenewalTermClass;
|
||||
use IPS\Theme;
|
||||
use LengthException;
|
||||
use OutOfRangeException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renewal Term input class for Form Builder
|
||||
*/
|
||||
class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
class RenewalTerm extends FormAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Default Options
|
||||
@@ -41,7 +54,7 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
);
|
||||
* @endcode
|
||||
*/
|
||||
protected $defaultOptions = array(
|
||||
protected array $defaultOptions = array(
|
||||
'customer' => NULL,
|
||||
'currency' => NULL,
|
||||
'allCurrencies' => FALSE,
|
||||
@@ -60,9 +73,9 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function html()
|
||||
public function html(): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->renewalTerm( $this->name, $this->value, $this->options );
|
||||
return Theme::i()->getTemplate( 'forms', 'nexus', 'global' )->renewalTerm( $this->name, $this->value, $this->options );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,9 +83,9 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function formatValue()
|
||||
public function formatValue(): mixed
|
||||
{
|
||||
if ( \is_array( $this->value ) )
|
||||
if ( is_array( $this->value ) )
|
||||
{
|
||||
if ( isset( $this->value['null'] ) /* or !isset( $this->value['term'] ) or !$this->value['term'] or !isset( $this->value['unit'] ) or !$this->value['unit'] */ )
|
||||
{
|
||||
@@ -84,11 +97,11 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
if ( $this->options['allCurrencies'] )
|
||||
{
|
||||
$costs = array();
|
||||
foreach ( \IPS\nexus\Money::currencies() as $currency )
|
||||
foreach ( Money::currencies() as $currency )
|
||||
{
|
||||
if ( isset( $this->value[ 'amount_' . $currency ] ) )
|
||||
{
|
||||
$costs[ $currency ] = new \IPS\nexus\Money( $this->value[ 'amount_' . $currency ], $currency );
|
||||
$costs[ $currency ] = new Money( $this->value[ 'amount_' . $currency ], $currency );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -104,10 +117,16 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
}
|
||||
else
|
||||
{
|
||||
$currencies = \IPS\nexus\Money::currencies();
|
||||
$currencies = Money::currencies();
|
||||
$currency = array_shift( $currencies );
|
||||
}
|
||||
$costs = isset( $this->value['amount'] ) ? new \IPS\nexus\Money( $this->value['amount'], $currency ) : NULL;
|
||||
$costs = isset( $this->value['amount'] ) ? new Money( $this->value['amount'], $currency ) : NULL;
|
||||
}
|
||||
|
||||
/* If we have no price specified, stop here */
|
||||
if( $costs === NULL OR ( is_array( $costs ) AND !count( $costs ) ) )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Work out term */
|
||||
@@ -124,20 +143,20 @@ class _RenewalTerm extends \IPS\Helpers\Form\FormAbstract
|
||||
|
||||
if ( $this->value['term'] < 1 )
|
||||
{
|
||||
$this->value = new \IPS\nexus\Purchase\RenewalTerm( $costs, new \DateInterval( 'P' . 1 . mb_strtoupper( $this->value['unit'] ) ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new \LengthException( \IPS\Member::loggedIn()->language()->addToStack('form_number_min', FALSE, array( 'sprintf' => array( 0 ) ) ) );
|
||||
$this->value = new RenewalTermClass( $costs, new DateInterval( 'P' . 1 . mb_strtoupper( $this->value['unit'] ) ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new LengthException( Member::loggedIn()->language()->addToStack('form_number_min', FALSE, array( 'sprintf' => array( 0 ) ) ) );
|
||||
}
|
||||
if ( !\in_array( $this->value['unit'], array( 'd', 'm', 'y' ) ) )
|
||||
if ( !in_array( $this->value['unit'], array( 'd', 'm', 'y' ) ) )
|
||||
{
|
||||
$this->value = new \IPS\nexus\Purchase\RenewalTerm( $costs, new \DateInterval( 'P' . $this->value['term'] . 'D' ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new \OutOfRangeException( 'form_bad_value' );
|
||||
$this->value = new RenewalTermClass( $costs, new DateInterval( 'P' . $this->value['term'] . 'D' ), NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
throw new OutOfRangeException( 'form_bad_value' );
|
||||
}
|
||||
|
||||
$term = new \DateInterval( 'P' . $this->value['term'] . mb_strtoupper( $this->value['unit'] ) );
|
||||
$term = new DateInterval( 'P' . $this->value['term'] . mb_strtoupper( $this->value['unit'] ) );
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return new \IPS\nexus\Purchase\RenewalTerm( $costs, $term, NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
return new RenewalTermClass( $costs, $term, NULL, $this->options['addToBase'] ? isset( $this->value['add'] ) : FALSE );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user