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

@@ -12,38 +12,65 @@
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateInterval;
use Exception;
use IPS\core\MemberACPProfile\TabbedBlock;
use IPS\DateTime;
use IPS\Helpers\Chart;
use IPS\Helpers\Table\Custom;
use IPS\Helpers\Table\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\nexus\Customer;
use IPS\nexus\Gateway;
use IPS\nexus\Money;
use IPS\nexus\Purchase;
use IPS\nexus\Subscription;
use IPS\nexus\Transaction;
use IPS\Patterns\ActiveRecordIterator;
use IPS\Request;
use IPS\Settings;
use IPS\Theme;
use OutOfRangeException;
use function count;
use function defined;
use function is_null;
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 ACP Member Profile Block
*
* @property Customer $member
*/
class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
class AccountInformation extends TabbedBlock
{
/**
* Get Tab Names
*
* @return string
* @return array
*/
public function tabs()
public function tabs(): array
{
$tabs = array(
'overview' => array(
'icon' => 'ellipsis-h',
'icon' => 'address-card',
'count' => 0
)
);
if ( \count( \IPS\nexus\Gateway::cardStorageGateways() ) )
if ( count( Gateway::cardStorageGateways() ) )
{
$tabs['cards'] = array(
'icon' => 'credit-card',
'count' => \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ) )->first()
);
}
if ( \count( \IPS\nexus\Gateway::billingAgreementGateways() ) )
if ( count( Gateway::billingAgreementGateways() ) )
{
$tabs['paypal'] = array(
'icon' => 'paypal',
@@ -61,44 +88,44 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
/**
* Get output: OVERVIEW
*
* @return string
* @return mixed
*/
protected function _overview()
protected function _overview(): mixed
{
/* Sparkline */
$sparkline = NULL;
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view_statistics' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_view_statistics' ) )
{
$rows = array();
$oneYearAgo = \IPS\DateTime::create()->sub( new \DateInterval( 'P1Y' ) );
$oneYearAgo = DateTime::create()->sub( new DateInterval( 'P1Y' ) );
$date = clone $oneYearAgo;
$endOfLastMonth = mktime( 23, 59, 59, date( 'n' ) - 1, date( 't' ), date( 'Y' ) );
while ( $date->getTimestamp() < $endOfLastMonth )
{
foreach ( \IPS\nexus\Money::currencies() as $currency )
foreach ( Money::currencies() as $currency )
{
$rows[$date->format( 'n Y' )][$currency] = 0;
}
$date->add( new \DateInterval( 'P1M' ) );
$date->add( new DateInterval( 'P1M' ) );
}
$sparkline = new \IPS\Helpers\Chart;
foreach ( \IPS\Db::i()->select( 'DATE_FORMAT( FROM_UNIXTIME(t_date), \'%c %Y\' ) AS time, SUM(t_amount)-SUM(t_partial_refund) AS amount, t_currency', 'nexus_transactions', array(array("t_member=? AND ( t_status=? OR t_status=? ) AND t_method>0 AND t_date>? AND t_date<?", $this->member->member_id, \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $oneYearAgo->getTimestamp(), time())), NULL, NULL, array('time', 't_currency') ) as $row )
$sparkline = new Chart;
foreach ( \IPS\Db::i()->select( 'DATE_FORMAT( FROM_UNIXTIME(t_date), \'%c %Y\' ) AS time, SUM(t_amount)-SUM(t_partial_refund) AS amount, t_currency', 'nexus_transactions', array(array("t_member=? AND ( t_status=? OR t_status=? ) AND t_method>0 AND t_date>? AND t_date<?", $this->member->member_id, Transaction::STATUS_PAID, Transaction::STATUS_PART_REFUNDED, $oneYearAgo->getTimestamp(), time())), NULL, NULL, array('time', 't_currency') ) as $row )
{
if ( isset( $rows[$row['time']][$row['t_currency']] ) ) // Currency may no longer exist
{
$rows[$row['time']][$row['t_currency']] += $row['amount'];
}
}
$sparkline->addHeader( \IPS\Member::loggedIn()->language()->addToStack( 'date' ), 'date' );
foreach ( \IPS\nexus\Money::currencies() as $currency )
$sparkline->addHeader( Member::loggedIn()->language()->addToStack( 'date' ), 'date' );
foreach ( Money::currencies() as $currency )
{
$sparkline->addHeader( $currency, 'number' );
}
foreach ( $rows as $time => $row )
{
$datetime = new \IPS\DateTime;
$datetime->setTime( 0, 0, 0 );
$datetime = new DateTime;
$datetime->setTime( 0, 0 );
$exploded = explode( ' ', $time );
$datetime->setDate( $exploded[1], $exploded[0], 1 );
@@ -145,20 +172,21 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
$addressCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_addresses', array( '`member`=?', $this->member->member_id ) )->first();
/* Display */
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationOverview( $this->member, $sparkline, $primaryBillingAddress, $addressCount );
return Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationOverview( $this->member, $sparkline, $primaryBillingAddress, $addressCount );
}
/**
* Get output: STORED PAYMENT METHODS
*
* @param bool $edit Edit view?
* @return string
* @return mixed
*/
protected function _cards( $edit = FALSE )
protected function _cards( bool $edit = FALSE ): mixed
{
$cards = array();
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ), NULL, $edit ? NULL : 10 ), 'IPS\nexus\Customer\CreditCard' ) as $card )
foreach ( new ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ), NULL, $edit ? NULL : 10 ), 'IPS\nexus\Customer\CreditCard' ) as $card )
{
/* @var Customer\CreditCard $card */
try
{
$cardData = $card->card;
@@ -167,21 +195,21 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
'card_type' => $cardData->type,
'card_member' => $card->member->member_id,
'card_number' => $cardData->lastFour ?: $cardData->number,
'card_expire' => ( !\is_null( $cardData->expMonth ) AND !\is_null( $cardData->expYear ) ) ? str_pad( $cardData->expMonth , 2, '0', STR_PAD_LEFT ). '/' . $cardData->expYear : NULL
'card_expire' => ( !is_null( $cardData->expMonth ) AND !is_null( $cardData->expYear ) ) ? str_pad( $cardData->expMonth , 2, '0', STR_PAD_LEFT ). '/' . $cardData->expYear : NULL
);
}
catch ( \Exception $e ) { }
catch ( Exception ) { }
}
$cards = new \IPS\Helpers\Table\Custom( $cards, $this->member->acpUrl()->setQueryString( 'view', 'cards' ) );
$cards = new Custom( $cards, $this->member->acpUrl()->setQueryString( 'view', 'cards' ) );
if ( \IPS\nexus\Gateway::cardStorageGateways( TRUE ) )
if ( Gateway::cardStorageGateways( TRUE ) )
{
$cards->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'addCard' ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'addCard' ),
'title' => 'add',
'icon' => 'plus',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add_card') )
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('add_card') )
)
);
}
@@ -189,7 +217,7 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
{
return array(
'delete' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteCard', 'card_id' => $row['id'] ) ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteCard', 'card_id' => $row['id'] ) ),
'title' => 'delete',
'icon' => 'times-circle',
'data' => array( 'delete' => '' )
@@ -199,18 +227,18 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
if ( $edit )
{
$cards->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsTable' );
$cards->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsTableRows' );
$cards->tableTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsTable' );
$cards->rowsTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsTableRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $cards );
return Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $cards );
}
else
{
$cards->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsOverview' );
$cards->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsOverviewRows' );
$cards->tableTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsOverview' );
$cards->rowsTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'cardsOverviewRows' );
$cardCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_cards', array( 'card_member=?', $this->member->member_id ) )->first();
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $cards, \IPS\Member::loggedIn()->language()->addToStack( 'num_credit_card', FALSE, array( 'pluralize' => array( $cardCount ) ) ), 'cards' );
return Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $cards, Member::loggedIn()->language()->addToStack( 'num_credit_card', FALSE, array( 'pluralize' => array( $cardCount ) ) ), 'cards' );
}
}
@@ -218,9 +246,9 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
* Get output: BILLING AGREEMENTS
*
* @param bool $edit Edit view?
* @return string
* @return mixed
*/
protected function _paypal( $edit = FALSE )
protected function _paypal( bool $edit = FALSE ): mixed
{
$billingAgreementCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_billing_agreements', array( 'ba_member=? AND ba_canceled=0', $this->member->member_id ) )->first();
$billingAgreements = array();
@@ -233,20 +261,20 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
'next_cycle' => $billingAgreement['ba_next_cycle'],
);
}
$billingAgreements = new \IPS\Helpers\Table\Custom( $billingAgreements, $this->member->acpUrl()->setQueryString( 'view', 'billingagreements' ) );
$billingAgreements = new Custom( $billingAgreements, $this->member->acpUrl()->setQueryString( 'view', 'billingagreements' ) );
$billingAgreements->parsers = array(
'started' => function( $val ) {
return $val ? \IPS\DateTime::ts( $val )->relative() : null;
return $val ? DateTime::ts( $val )->relative() : null;
},
'next_cycle' => function( $val ) {
return $val ? \IPS\DateTime::ts( $val )->relative() : null;
return $val ? DateTime::ts( $val )->relative() : null;
},
);
$billingAgreements->rowButtons = function( $row, $id )
{
return array(
'view' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=payments&controller=billingagreements&id={$id}"),
'link' => Url::internal("app=nexus&module=payments&controller=billingagreements&id={$id}"),
'title' => 'view',
'icon' => 'search',
)
@@ -256,14 +284,14 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
{
$billingAgreements->exclude = array( 'id', 'last_transaction_currency' );
$billingAgreements->langPrefix = 'ba_';
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $billingAgreements );
return Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $billingAgreements );
}
else
{
$billingAgreements->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'billingAgreementsOverview' );
$billingAgreements->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'billingAgreementsOverviewRows' );
$billingAgreements->tableTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'billingAgreementsOverview' );
$billingAgreements->rowsTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'billingAgreementsOverviewRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $billingAgreements, \IPS\Member::loggedIn()->language()->addToStack( 'num_billing_agreements', FALSE, array( 'pluralize' => array( $billingAgreementCount ) ) ), 'paypal' );
return Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $billingAgreements, Member::loggedIn()->language()->addToStack( 'num_billing_agreements', FALSE, array( 'pluralize' => array( $billingAgreementCount ) ) ), 'paypal' );
}
}
@@ -271,24 +299,24 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
* Get output: ALTERNATE CONTACTS
*
* @param bool $edit Edit view?
* @return string
* @return mixed
*/
protected function _alts( $edit = FALSE )
protected function _alts( bool $edit = FALSE ): mixed
{
$altContactCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_alternate_contacts', array( 'main_id=?', $this->member->member_id ) )->first();
$alternativeContacts = new \IPS\Helpers\Table\Db( 'nexus_alternate_contacts', $this->member->acpUrl()->setQueryString( 'view', 'alternatives' ), array( 'main_id=?', $this->member->member_id ) );
$alternativeContacts = new Db( 'nexus_alternate_contacts', $this->member->acpUrl()->setQueryString( 'view', 'alternatives' ), array( 'main_id=?', $this->member->member_id ) );
$alternativeContacts->langPrefix = 'altcontactTable_';
$alternativeContacts->include = array( 'alt_id', 'purchases', 'billing', 'support' );
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_edit_details' ) )
$alternativeContacts->include = array( 'alt_id', 'purchases', 'billing' );
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customers_edit_details' ) )
{
$alternativeContacts->parsers = array(
'alt_id' => function( $val )
{
return \IPS\Theme::i()->getTemplate( 'global', 'nexus' )->userLink( \IPS\nexus\Customer::load( $val ) );
return Theme::i()->getTemplate( 'global', 'nexus' )->userLink( Customer::load( $val ) );
},
'email' => function ( $val, $row )
{
return htmlspecialchars( \IPS\nexus\Customer::load( $row['alt_id'] )->email, ENT_DISALLOWED, 'UTF-8', FALSE );
return htmlspecialchars( Customer::load( $row['alt_id'] )->email, ENT_DISALLOWED, 'UTF-8', FALSE );
},
'purchases' => function( $val )
{
@@ -296,9 +324,9 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
{
try
{
return \IPS\Theme::i()->getTemplate( 'purchases', 'nexus' )->link( \IPS\nexus\Purchase::load( $id ) );
return Theme::i()->getTemplate( 'purchases', 'nexus' )->link( Purchase::load( $id ) );
}
catch ( \OutOfRangeException $e )
catch ( OutOfRangeException )
{
return '';
}
@@ -306,33 +334,29 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
},
'billing' => function( $val )
{
return $val ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
},
'support' => function( $val )
{
return $val ? "<i class='fa fa-check'></i>" : "<i class='fa fa-times'></i>";
return $val ? "<i class='fa-solid fa-check'></i>" : "<i class='fa-solid fa-xmark'></i>";
}
);
$alternativeContacts->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'alternativeContactForm' ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( 'do', 'alternativeContactForm' ),
'title' => 'add',
'icon' => 'plus',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('altcontact_add') )
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('altcontact_add') )
)
);
$alternativeContacts->rowButtons = function( $row )
{
return array(
'edit' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'alternativeContactForm', 'alt_id' => $row['alt_id'] ) ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'alternativeContactForm', 'alt_id' => $row['alt_id'] ) ),
'title' => 'edit',
'icon' => 'pencil',
'data' => array( 'ipsDialog' => true )
),
'delete' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteAlternativeContact', 'alt_id' => $row['alt_id'] ) ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteAlternativeContact', 'alt_id' => $row['alt_id'] ) ),
'title' => 'delete',
'icon' => 'times-circle',
'data' => array( 'delete' => '' )
@@ -342,25 +366,26 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
}
if ( $edit )
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $alternativeContacts );
return Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $alternativeContacts );
}
else
{
$alternativeContacts->include[] = 'email';
$alternativeContacts->limit = 2;
$alternativeContacts->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'altContactsOverview' );
$alternativeContacts->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'altContactsOverviewRows' );
$alternativeContacts->tableTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'altContactsOverview' );
$alternativeContacts->rowsTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'altContactsOverviewRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $alternativeContacts, \IPS\Member::loggedIn()->language()->addToStack( 'num_alternate_contacts', FALSE, array( 'pluralize' => array( $altContactCount ) ) ), 'alts' );
return Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformationTablePreview( $this->member, $alternativeContacts, Member::loggedIn()->language()->addToStack( 'num_alternate_contacts', FALSE, array( 'pluralize' => array( $altContactCount ) ) ), 'alts' );
}
}
/**
* Get output
*
* @return string
* @param string $tab
* @return mixed
*/
public function tabOutput( $tab )
public function tabOutput( string $tab ): mixed
{
$method = "_{$tab}";
return $this->$method();
@@ -371,11 +396,11 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
*
* @return string
*/
public function edit()
public function edit(): string
{
if ( array_key_exists( \IPS\Request::i()->type, $this->tabs() ) )
if ( array_key_exists( Request::i()->type, $this->tabs() ) )
{
$method = "_" . \IPS\Request::i()->type;
$method = "_" . Request::i()->type;
return $this->$method( TRUE );
}
return parent::edit();
@@ -386,22 +411,22 @@ class _AccountInformation extends \IPS\core\MemberACPProfile\TabbedBlock
*
* @return string
*/
public function output()
public function output(): string
{
$tabs = $this->tabs();
if ( !\count( $tabs ) )
if ( !count( $tabs ) )
{
return '';
}
$tabKeys = array_keys( $tabs );
$activeTabKey = ( isset( \IPS\Request::i()->block['nexus_AccountInformation'] ) and array_key_exists( \IPS\Request::i()->block['nexus_AccountInformation'], $tabs ) ) ? \IPS\Request::i()->block['nexus_AccountInformation'] : array_shift( $tabKeys );
$activeTabKey = ( isset( Request::i()->block['nexus_AccountInformation'] ) and array_key_exists( Request::i()->block['nexus_AccountInformation'], $tabs ) ) ? Request::i()->block['nexus_AccountInformation'] : array_shift( $tabKeys );
$activeSubscription = FALSE;
if ( \IPS\Settings::i()->nexus_subs_enabled )
if ( Settings::i()->nexus_subs_enabled )
{
$activeSubscription = \IPS\nexus\Subscription::loadActiveByMember( $this->member );
$activeSubscription = Subscription::loadByMember( $this->member, TRUE );
}
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformation( $this->member, $tabs, $activeTabKey, $this->tabOutput( $activeTabKey ), $activeSubscription );
return (string) Theme::i()->getTemplate( 'customers', 'nexus' )->accountInformation( $this->member, $tabs, $activeTabKey, $this->tabOutput( $activeTabKey ), $activeSubscription );
}
}
@@ -11,40 +11,49 @@
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\MemberACPProfile\Block;
use IPS\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\nexus\Invoice;
use IPS\Theme;
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 ACP Member Profile: Invoices
*/
class _Invoices extends \IPS\core\MemberACPProfile\Block
class Invoices extends Block
{
/**
* Get output
*
* @return string
*/
public function output()
public function output(): string
{
$invoiceCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_invoices', array( 'i_member=?', $this->member->member_id ) )->first();
$invoices = \IPS\nexus\Invoice::table( array( 'i_member=?', $this->member->member_id ), $this->member->acpUrl()->setQueryString( 'tab', 'invoices' ), 'c' );
$invoiceCount = Db::i()->select( 'COUNT(*)', 'nexus_invoices', array( 'i_member=?', $this->member->member_id ) )->first();
$invoices = Invoice::table( array( 'i_member=?', $this->member->member_id ), $this->member->acpUrl()->setQueryString( 'tab', 'invoices' ), 'c' );
$invoices->limit = 15;
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_add' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'invoices_add' ) )
{
$invoices->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal( "app=nexus&module=payments&controller=invoices&do=generate&member={$this->member->member_id}" ),
'link' => Url::internal( "app=nexus&module=payments&controller=invoices&do=generate&member={$this->member->member_id}" ),
'title' => 'add',
'icon' => 'plus',
)
);
}
$invoices->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'invoicesTable' );
$invoices->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'invoicesTableRows' );
$invoices->tableTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'invoicesTable' );
$invoices->rowsTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'invoicesTableRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->invoices( $this->member, $invoices, $invoiceCount );
return (string) Theme::i()->getTemplate( 'customers', 'nexus' )->invoices( $this->member, $invoices, $invoiceCount );
}
}
@@ -11,51 +11,59 @@
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\MemberACPProfile\Block;
use IPS\Helpers\Table\Db;
use IPS\Http\Url;
use IPS\Member;
use IPS\Theme;
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 ACP Member Profile: Notes
*/
class _Notes extends \IPS\core\MemberACPProfile\Block
class Notes extends Block
{
/**
* @brief Notes
*/
protected $notes;
protected ?Db $notes = NULL;
/**
* @brief Note Count
*/
protected $noteCount;
protected ?int $noteCount = NULL;
/**
* Constructor
*
* @param \IPS\Member $member Member
* @param Member $member Member
* @return void
*/
public function __construct( \IPS\Member $member )
public function __construct( Member $member )
{
parent::__construct( $member );
$this->notes = NULL;
$this->noteCount = 0;
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_view' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_view' ) )
{
$this->noteCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_notes', array( 'note_member=?', $this->member->member_id ) )->first();
$this->notes = new \IPS\Helpers\Table\Db( 'nexus_notes', $this->member->acpUrl()->setQueryString( array( 'view' => 'notes', 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ), array( 'note_member=?', $this->member->member_id ) );
$this->notes->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'notes' );
$this->notes = new Db( 'nexus_notes', $this->member->acpUrl()->setQueryString( array( 'view' => 'notes' ) ), array( 'note_member=?', $this->member->member_id ) );
$this->notes->tableTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'notes' );
$this->notes->sortBy = 'note_date';
$this->notes->parsers = array(
'note_member' => function( $val )
{
return \IPS\Member::load( $val );
return Member::load( $val );
},
'note_text' => function( $val )
{
@@ -66,30 +74,19 @@ class _Notes extends \IPS\core\MemberACPProfile\Block
$this->notes->rowButtons = function( $row )
{
$return = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_edit' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_edit' ) )
{
if ( !isset( \IPS\Request::i()->support ) or !\IPS\Request::i()->support )
{
$return['edit'] = array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
'title' => 'edit',
'icon' => 'pencil',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('edit_note') )
);
}
else
{
$return['edit'] = array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
'title' => 'edit',
'icon' => 'pencil',
);
}
$return['edit'] = array(
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm', 'note_id' => $row['note_id'] ) ),
'title' => 'edit',
'icon' => 'pencil',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('edit_note') )
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_delete' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_delete' ) )
{
$return['delete'] = array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteNote', 'note_id' => $row['note_id'], 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) )->csrf(),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'deleteNote', 'note_id' => $row['note_id'] ) )->csrf(),
'title' => 'delete',
'icon' => 'times-circle',
'data' => array( 'confirm' => '' )
@@ -98,14 +95,14 @@ class _Notes extends \IPS\core\MemberACPProfile\Block
return $return;
};
if ( ( !isset( \IPS\Request::i()->support ) or !\IPS\Request::i()->support ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_add' ) )
if ( Member::loggedIn()->hasAcpRestriction( 'nexus', 'customers', 'customer_notes_add' ) )
{
$this->notes->rootButtons = array(
'add' => array(
'link' => \IPS\Http\Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm', 'support' => isset( \IPS\Request::i()->support ) ? \IPS\Request::i()->support : 0 ) ),
'link' => Url::internal("app=nexus&module=customers&controller=view&id={$this->member->member_id}")->setQueryString( array( 'do' => 'noteForm' ) ),
'title' => 'add',
'icon' => 'plus',
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add_note') )
'data' => array( 'ipsDialog' => true, 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('add_note') )
)
);
}
@@ -117,13 +114,13 @@ class _Notes extends \IPS\core\MemberACPProfile\Block
*
* @return string
*/
public function output()
public function output(): string
{
$this->notes->limit = 2;
$this->notes->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'notesOverview' );
$this->notes->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'customers', 'nexus' ), 'notesOverviewRows' );
$this->notes->tableTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'notesOverview' );
$this->notes->rowsTemplate = array( Theme::i()->getTemplate( 'customers', 'nexus' ), 'notesOverviewRows' );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->notesBlock( $this->member, $this->noteCount, $this->notes );
return (string) Theme::i()->getTemplate( 'customers', 'nexus' )->notesBlock( $this->member, $this->noteCount, $this->notes );
}
/**
@@ -131,8 +128,8 @@ class _Notes extends \IPS\core\MemberACPProfile\Block
*
* @return string
*/
public function lazyOutput()
public function lazyOutput(): string
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $this->notes );
return (string) Theme::i()->getTemplate( 'customers', 'nexus' )->customerPopup( $this->notes );
}
}
@@ -11,33 +11,43 @@
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\MemberACPProfile\Block;
use IPS\Db;
use IPS\nexus\Customer;
use IPS\Theme;
use function count;
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 ACP Member Profile: Customer Statistics Block
*/
class _ParentAccounts extends \IPS\core\MemberACPProfile\Block
class ParentAccounts extends Block
{
/**
* Get output
*
* @return string
*/
public function output()
public function output(): string
{
$parents = array();
foreach ( \IPS\Db::i()->select( 'main_id', 'nexus_alternate_contacts', array( 'alt_id=?', $this->member->member_id ) ) as $row )
foreach ( Db::i()->select( 'main_id', 'nexus_alternate_contacts', array( 'alt_id=?', $this->member->member_id ) ) as $row )
{
$parents[] = \IPS\nexus\Customer::load( $row );
$parents[] = Customer::load( $row );
}
if ( \count( $parents ) )
if ( count( $parents ) )
{
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->parentAccounts( $parents );
return (string) Theme::i()->getTemplate( 'customers', 'nexus' )->parentAccounts( $parents );
}
return '';
}
}
@@ -11,44 +11,55 @@
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\MemberACPProfile\TabbedBlock;
use IPS\DateTime;
use IPS\Db;
use IPS\Helpers\Tree\Tree;
use IPS\nexus\Purchase;
use IPS\Request;
use IPS\Theme;
use function count;
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 ACP Member Profile: Purchases
*/
class _Purchases extends \IPS\core\MemberACPProfile\TabbedBlock
class Purchases extends TabbedBlock
{
/**
* Purchase tree
*/
protected $_purchases = NULL;
protected ?Tree $_purchases = NULL;
/**
* Get Tab Names
*
* @return string
* @return array
*/
public function tabs()
public function tabs(): array
{
$tabs = array();
$activeCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1 AND ps_active=1 AND ps_parent = 0', $this->member->member_id ) )->first();
$activeCount = Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_show=1 AND ps_active=1 AND ps_parent = 0', $this->member->member_id ) )->first();
$tabs['active'] = array(
'icon' => 'credit-card',
'count' => $activeCount,
);
$expiredCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_active = 0 AND ps_cancelled = 0 AND ps_parent = 0 AND ps_expire <?', $this->member->member_id, \IPS\DateTime::create()->getTimestamp() ) )->first();
$expiredCount = Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_active = 0 AND ps_cancelled = 0 AND ps_parent = 0 AND ps_expire <?', $this->member->member_id, DateTime::create()->getTimestamp() ) )->first();
$tabs['expired'] = array(
'icon' => 'credit-card',
'count' => $expiredCount,
);
$canceledCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_cancelled=1 AND ps_parent = 0', $this->member->member_id ) )->first();
$canceledCount = Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( 'ps_member=? AND ps_cancelled=1 AND ps_parent = 0', $this->member->member_id ) )->first();
$tabs['canceled'] = array(
'icon' => 'credit-card',
'count' => $canceledCount,
@@ -62,32 +73,33 @@ class _Purchases extends \IPS\core\MemberACPProfile\TabbedBlock
*
* @return string
*/
public function output()
public function output(): string
{
$tabs = $this->tabs();
if ( !\count( $tabs ) )
if ( !count( $tabs ) )
{
return '';
}
$tabKeys = array_keys( $tabs );
$activeTabKey = ( isset( \IPS\Request::i()->block['nexus_Purchase'] ) and array_key_exists( \IPS\Request::i()->block['nexus_Purchases'], $tabs ) ) ? \IPS\Request::i()->block['nexus_Purchases'] : array_shift( $tabKeys );
$activeTabKey = ( isset( Request::i()->block['nexus_Purchase'] ) and array_key_exists( Request::i()->block['nexus_Purchases'], $tabs ) ) ? Request::i()->block['nexus_Purchases'] : array_shift( $tabKeys );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->purchases( $this->member, $tabs, $activeTabKey, $this->tabOutput( $activeTabKey ) );
return (string) Theme::i()->getTemplate( 'customers', 'nexus' )->purchases( $this->member, $tabs, $activeTabKey, $this->tabOutput( $activeTabKey ) );
}
/**
* Get output
*
* @return string
* @param string $tab
* @return mixed
*/
public function tabOutput( $activeTabKey )
public function tabOutput(string $tab ): mixed
{
if ( $this->_purchases === NULL )
{
$where = array();
$where[] = array( 'ps_member=?', $this->member->member_id );
switch ( $activeTabKey )
switch ( $tab )
{
case 'active':
$where[] = array( 'ps_active=1' );
@@ -96,11 +108,11 @@ class _Purchases extends \IPS\core\MemberACPProfile\TabbedBlock
$where[] = array( 'ps_cancelled=1' );
break;
case 'expired':
$where[] = array( 'ps_active = 0 and ps_cancelled = 0 and ps_expire <?', \IPS\DateTime::create()->getTimestamp() );
$where[] = array( 'ps_active = 0 and ps_cancelled = 0 and ps_expire <?', DateTime::create()->getTimestamp() );
break;
}
$this->_purchases = \IPS\nexus\Purchase::tree( $this->member->acpUrl()->setQueryString( 'blockKey', 'nexus_Purchases' ), $where );
$this->_purchases = Purchase::tree( $this->member->acpUrl()->setQueryString( 'blockKey', 'nexus_Purchases' ), $where );
$this->_purchases->getTotalRoots = function()
{
return NULL;
@@ -11,36 +11,48 @@
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\core\MemberACPProfile\LazyLoadingBlock;
use IPS\Db;
use IPS\Member;
use IPS\nexus\Invoice;
use IPS\nexus\Money;
use IPS\nexus\Transaction;
use IPS\Theme;
use UnderflowException;
use function defined;
use function floatval;
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 ACP Member Profile: Customer Statistics Block
*/
class _Statistics extends \IPS\core\MemberACPProfile\LazyLoadingBlock
class Statistics extends LazyLoadingBlock
{
/**
* Get output
*
* @return string
*/
public function lazyOutput()
public function lazyOutput(): string
{
$standing = array();
$time = time();
foreach ( \IPS\nexus\Money::currencies() as $currency )
foreach ( Money::currencies() as $currency )
{
/* Total spent */
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "(SUM(t_amount)-SUM(t_partial_refund)) as xval", 'nexus_transactions', array( '( t_status=? OR t_status=? ) AND t_method>0 AND t_currency=? AND t_member<>0', \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $currency ), NULL, NULL, 't_member' ), 'xval>0' )->first();
$val = \IPS\Db::i()->select( 'SUM(t_amount)-SUM(t_partial_refund)', 'nexus_transactions', array( 't_member=? AND ( t_status=? OR t_status=? ) AND t_method>0 AND t_currency=?', $this->member->member_id, \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $currency ) )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'total_spent_currency', FALSE, array( 'sprintf' => array( $currency ) ) ) ] = array(
'value' => new \IPS\nexus\Money( $val ?: '0', $currency ),
'avg' => new \IPS\nexus\Money( $comparisons['avg'], $currency ),
'highest' => new \IPS\nexus\Money( $comparisons['max'], $currency ),
'lowest' => new \IPS\nexus\Money( $comparisons['min'], $currency ),
$comparisons = Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', Db::i()->select( "(SUM(t_amount)-SUM(t_partial_refund)) as xval", 'nexus_transactions', array( '( t_status=? OR t_status=? ) AND t_method>0 AND t_currency=? AND t_member<>0', Transaction::STATUS_PAID, Transaction::STATUS_PART_REFUNDED, $currency ), NULL, NULL, 't_member' ), 'xval>0' )->first();
$val = Db::i()->select( 'SUM(t_amount)-SUM(t_partial_refund)', 'nexus_transactions', array( 't_member=? AND ( t_status=? OR t_status=? ) AND t_method>0 AND t_currency=?', $this->member->member_id, Transaction::STATUS_PAID, Transaction::STATUS_PART_REFUNDED, $currency ) )->first();
$standing[ Member::loggedIn()->language()->addToStack( 'total_spent_currency', FALSE, array( 'sprintf' => array( $currency ) ) ) ] = array(
'value' => new Money( $val ?: '0', $currency ),
'avg' => new Money( $comparisons['avg'] ?: 0, $currency ),
'highest' => new Money( $comparisons['max'] ?: 0, $currency ),
'lowest' => new Money( $comparisons['min'] ?: 0, $currency ),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
@@ -52,21 +64,21 @@ class _Statistics extends \IPS\core\MemberACPProfile\LazyLoadingBlock
/* Average monthly spend */
$sum = "( SUM(t_amount) / ( ( {$time} - core_members.joined ) / 2592000 ) )";
$where = array( array( "( t_status=? OR t_status=? ) AND ({$time} - core_members.joined > 2592000) AND t_currency=?", \IPS\nexus\Transaction::STATUS_PAID, \IPS\nexus\Transaction::STATUS_PART_REFUNDED, $currency ) );
$where = array( array( "( t_status=? OR t_status=? ) AND ({$time} - core_members.joined > 2592000) AND t_currency=?", Transaction::STATUS_PAID, Transaction::STATUS_PART_REFUNDED, $currency ) );
try
{
$val = \IPS\Db::i()->select( "{$sum} as sum", 'nexus_transactions', array_merge( $where, array( array( 't_member=?', $this->member->member_id ) ) ), 'joined', NULL, 'joined' )->join( 'core_members', 'member_id=t_member' )->first();
$val = Db::i()->select( "{$sum} as sum", 'nexus_transactions', array_merge( $where, array( array( 't_member=?', $this->member->member_id ) ) ), 'joined', NULL, 'joined' )->join( 'core_members', 'member_id=t_member' )->first();
}
catch( \UnderflowException $e )
catch( UnderflowException )
{
$val = 0;
}
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "{$sum} as xval", 'nexus_transactions', array_merge( $where, array( array( 't_member<>0' ) ) ), NULL, NULL, array( 't_member', 'joined' ) ), 'xval>0' )->join( 'core_members', 'member_id=t_member' )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'average_spend_currency', FALSE, array( 'sprintf' => array( $currency ) ) ) ] = array(
'value' => new \IPS\nexus\Money( $val, $currency ),
'avg' => new \IPS\nexus\Money( $comparisons['avg'], $currency ),
'highest' => new \IPS\nexus\Money( $comparisons['max'], $currency ),
'lowest' => new \IPS\nexus\Money( $comparisons['min'], $currency ),
$comparisons = Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', Db::i()->select( "{$sum} as xval", 'nexus_transactions', array_merge( $where, array( array( 't_member<>0' ) ) ), NULL, NULL, array( 't_member', 'joined' ) ), 'xval>0' )->join( 'core_members', 'member_id=t_member' )->first();
$standing[ Member::loggedIn()->language()->addToStack( 'average_spend_currency', FALSE, array( 'sprintf' => array( $currency ) ) ) ] = array(
'value' => new Money( $val ?: 0, $currency ),
'avg' => new Money( $comparisons['avg'] ?: 0, $currency ),
'highest' => new Money( $comparisons['max'] ?: 0, $currency ),
'lowest' => new Money( $comparisons['min'] ?: 0, $currency ),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
@@ -78,47 +90,24 @@ class _Statistics extends \IPS\core\MemberACPProfile\LazyLoadingBlock
}
$sum = "ROUND( ( AVG( i_paid - i_date ) / 86400 ), 2 )";
$where = array( array( "i_status=? AND i_date>0 AND i_paid>0", \IPS\nexus\Invoice::STATUS_PAID ) );
$val = \IPS\Db::i()->select( "{$sum} as sum", 'nexus_invoices', array_merge( $where, array( array( 'i_member=?', $this->member->member_id ) ) ) )->join( 'core_members', 'member_id=i_member' )->first();
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "{$sum} as xval", 'nexus_invoices', array_merge( $where, array( array( 'i_member<>0' ) ) ), NULL, NULL, array( 'i_member', 'joined' ) ), 'xval>0' )->join( 'core_members', 'member_id=i_member' )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'average_time_to_pay' ) ] = array(
'value' => \IPS\Member::loggedIn()->language()->formatNumber( $val, 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
'avg' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['avg'], 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
'highest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['max'], 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
'lowest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['min'], 2 ) . ' ' . \IPS\Member::loggedIn()->language()->addToStack('days'),
$where = array( array( "i_status=? AND i_date>0 AND i_paid>0", Invoice::STATUS_PAID ) );
$val = Db::i()->select( "{$sum} as sum", 'nexus_invoices', array_merge( $where, array( array( 'i_member=?', $this->member->member_id ) ) ) )->join( 'core_members', 'member_id=i_member' )->first();
$comparisons = Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', Db::i()->select( "{$sum} as xval", 'nexus_invoices', array_merge( $where, array( array( 'i_member<>0' ) ) ), NULL, NULL, array( 'i_member', 'joined' ) ), 'xval>0' )->join( 'core_members', 'member_id=i_member' )->first();
$standing[ Member::loggedIn()->language()->addToStack( 'average_time_to_pay' ) ] = array(
'value' => Member::loggedIn()->language()->formatNumber( $val, 2 ) . ' ' . Member::loggedIn()->language()->addToStack('days'),
'avg' => Member::loggedIn()->language()->formatNumber( $comparisons['avg'], 2 ) . ' ' . Member::loggedIn()->language()->addToStack('days'),
'highest' => Member::loggedIn()->language()->formatNumber( $comparisons['max'], 2 ) . ' ' . Member::loggedIn()->language()->addToStack('days'),
'lowest' => Member::loggedIn()->language()->formatNumber( $comparisons['min'], 2 ) . ' ' . Member::loggedIn()->language()->addToStack('days'),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
'thisval' => $val,
'avgpct' => \floatval( $comparisons['max'] ) ? round( ( ( $comparisons['avg'] - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'thispct' => \floatval( $comparisons['max'] ) ? round( ( ( $val - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'avgpct' => floatval( $comparisons['max'] ) ? round( ( ( $comparisons['avg'] - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'thispct' => floatval( $comparisons['max'] ) ? round( ( ( $val - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'type' => 'timetopay'
);
$sum = "LEAST( ( count(*) / ( ( {$time} - core_members.joined ) / 2592000 ) ), count(*) )";
try
{
$val = \IPS\Db::i()->select( "{$sum} as sum", 'nexus_support_requests', array( 'r_member=?', $this->member->member_id ), 'joined', NULL, 'joined' )->join( 'core_members', 'member_id=r_member' )->first();
}
catch( \UnderflowException $e )
{
$val = 0;
}
$comparisons = \IPS\Db::i()->select( 'AVG(xval) AS avg, MAX(xval) AS max, MIN(xval) AS min', \IPS\Db::i()->select( "{$sum} as xval", 'nexus_support_requests', 'r_member<>0', NULL, NULL, 'joined' ) )->join( 'core_members', 'member_id=r_member' )->first();
$standing[ \IPS\Member::loggedIn()->language()->addToStack( 'average_monthly_support_requests' ) ] = array(
'value' => \IPS\Member::loggedIn()->language()->formatNumber( $val, 2 ),
'avg' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['avg'], 2 ),
'highest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['max'], 2 ),
'lowest' => \IPS\Member::loggedIn()->language()->formatNumber( $comparisons['min'], 2 ),
'lowval' => $comparisons['min'],
'highval' => $comparisons['max'],
'avgval' => $comparisons['avg'],
'thisval' => $val,
'avgpct' => $comparisons['max'] ? round( ( ( $comparisons['avg'] - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'thispct' => $comparisons['max'] ? round( ( ( $val - $comparisons['min'] ) / $comparisons['max'] ) * 100, 1 ) : 0,
'type' => 'support'
);
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->standing( $standing );
return (string) Theme::i()->getTemplate( 'customers', 'nexus' )->standing( $standing );
}
}
@@ -1,42 +0,0 @@
<?php
/**
* @brief ACP Member Profile: Support
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @since 5 Dec 2017
*/
namespace IPS\nexus\extensions\core\MemberACPProfileBlocks;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* @brief ACP Member Profile: Support
*/
class _Support extends \IPS\core\MemberACPProfile\Block
{
/**
* Get output
*
* @return string
*/
public function output()
{
$customerStream = \IPS\nexus\Support\Stream::customer( $this->member );
$supportCount = $customerStream->count( \IPS\Member::loggedIn() );
$results = $customerStream->results( \IPS\Member::loggedIn(), 'r_started DESC', 1, 15 );
$supportRequestsInView = array_keys( iterator_to_array( $results ) );
$tracked = iterator_to_array( \IPS\Db::i()->select( array( 'request_id', 'notify' ), 'nexus_support_tracker', array( array( 'member_id=?', \IPS\Member::loggedIn()->member_id ), array( \IPS\Db::i()->in( 'request_id', $supportRequestsInView ) ) ) )->setKeyField( 'request_id' )->setValueField( 'notify' ) );
$participatedIn = iterator_to_array( \IPS\Db::i()->select( 'DISTINCT reply_request', 'nexus_support_replies', array( array( 'reply_member=?', \IPS\Member::loggedIn()->member_id ), array( \IPS\Db::i()->in( 'reply_request', $supportRequestsInView ) ) ) ) );
$support = \IPS\Theme::i()->getTemplate( 'support', 'nexus' )->requestsTableResults( $results, NULL, FALSE, $tracked, $participatedIn, FALSE );
return \IPS\Theme::i()->getTemplate( 'customers', 'nexus' )->support( $this->member, $support, $supportCount );
}
}