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,21 +12,33 @@
|
||||
namespace IPS\nexus\extensions\core\OverviewStatistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\OverviewStatisticsAbstract;
|
||||
use IPS\Member;
|
||||
use IPS\nexus\Subscription\Package;
|
||||
use IPS\Settings;
|
||||
use IPS\Theme;
|
||||
use function count;
|
||||
use function defined;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Overview statistics extension: Subscriptions
|
||||
*/
|
||||
class _Subscriptions
|
||||
class Subscriptions extends OverviewStatisticsAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Which statistics page (activity or user)
|
||||
*/
|
||||
public $page = 'user';
|
||||
public string $page = 'user';
|
||||
|
||||
/**
|
||||
* Return the sub-block keys
|
||||
@@ -34,7 +46,7 @@ class _Subscriptions
|
||||
* @note This is designed to allow one class to support multiple blocks, for instance using the ContentRouter to generate blocks.
|
||||
* @return array
|
||||
*/
|
||||
public function getBlocks()
|
||||
public function getBlocks(): array
|
||||
{
|
||||
return array( 'subscriptions' );
|
||||
}
|
||||
@@ -45,20 +57,20 @@ class _Subscriptions
|
||||
* @param string|NULL $subBlock The subblock we are loading as returned by getBlocks()
|
||||
* @return array
|
||||
*/
|
||||
public function getBlockDetails( $subBlock = NULL )
|
||||
public function getBlockDetails( string $subBlock = NULL ): array
|
||||
{
|
||||
/* Description can be null and will not be shown if so */
|
||||
return \IPS\Settings::i()->nexus_subs_enabled ? array( 'app' => 'nexus', 'title' => 'stats_overview_subscriptions', 'description' => null, 'refresh' => 60 ) : NULL;
|
||||
return Settings::i()->nexus_subs_enabled ? array( 'app' => 'nexus', 'title' => 'stats_overview_subscriptions', 'description' => null, 'refresh' => 60 ) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the block HTML to show
|
||||
*
|
||||
* @param array|NULL $dateRange NULL for all time, or an array with 'start' and 'end' \IPS\DateTime objects to restrict to
|
||||
* @param array|string|null $dateRange String for a fixed time period in days, NULL for all time, or an array with 'start' and 'end' \IPS\DateTime objects to restrict to
|
||||
* @param string|NULL $subBlock The subblock we are loading as returned by getBlocks()
|
||||
* @return string
|
||||
*/
|
||||
public function getBlock( $dateRange = NULL, $subBlock = NULL )
|
||||
public function getBlock( array|string $dateRange = NULL, string $subBlock = NULL ): string
|
||||
{
|
||||
/* Init Chart */
|
||||
$pieBarData = array();
|
||||
@@ -67,61 +79,37 @@ class _Subscriptions
|
||||
$where = array( array( 'ps_app=?', 'nexus' ), array( 'ps_type=?', 'subscription' ) );
|
||||
$previousCount = NULL;
|
||||
|
||||
if( \is_array( $dateRange ) )
|
||||
if( is_array( $dateRange ) )
|
||||
{
|
||||
$where[] = array( 'ps_start > ?', $dateRange['start']->getTimestamp() );
|
||||
$where[] = array( 'ps_start < ?', $dateRange['end']->getTimestamp() );
|
||||
}
|
||||
elseif( $dateRange !== NULL )
|
||||
{
|
||||
$currentDate = new \IPS\DateTime;
|
||||
$interval = NULL;
|
||||
|
||||
switch( $dateRange )
|
||||
{
|
||||
case '7':
|
||||
$interval = new \DateInterval( 'P7D' );
|
||||
break;
|
||||
|
||||
case '30':
|
||||
$interval = new \DateInterval( 'P1M' );
|
||||
break;
|
||||
|
||||
case '90':
|
||||
$interval = new \DateInterval( 'P3M' );
|
||||
break;
|
||||
|
||||
case '180':
|
||||
$interval = new \DateInterval( 'P6M' );
|
||||
break;
|
||||
|
||||
case '365':
|
||||
$interval = new \DateInterval( 'P1Y' );
|
||||
break;
|
||||
}
|
||||
|
||||
$currentDate = new DateTime;
|
||||
$interval = static::getInterval( $dateRange );
|
||||
$initialTimestamp = $currentDate->sub( $interval )->getTimestamp();
|
||||
$where = array( array( 'ps_start > ?', $initialTimestamp ) );
|
||||
|
||||
$previousCount = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( array( 'ps_app=?', 'nexus' ), array( 'ps_type=?', 'subscription' ), array( 'ps_start BETWEEN ? AND ?', $currentDate->sub( $interval )->getTimestamp(), $initialTimestamp ) ) )->first();
|
||||
$previousCount = Db::i()->select( 'COUNT(*)', 'nexus_purchases', array( array( 'ps_app=?', 'nexus' ), array( 'ps_type=?', 'subscription' ), array( 'ps_start BETWEEN ? AND ?', $currentDate->sub( $interval )->getTimestamp(), $initialTimestamp ) ) )->first();
|
||||
}
|
||||
|
||||
$total = 0;
|
||||
$chart = NULL;
|
||||
|
||||
foreach( \IPS\nexus\Subscription\Package::roots() as $package )
|
||||
foreach( Package::roots() as $package )
|
||||
{
|
||||
$filter = $where;
|
||||
$filter[] = array( 'ps_item_id=?', $package->id );
|
||||
|
||||
$value = \IPS\Db::i()->select( 'COUNT(*)', 'nexus_purchases', $filter )->first();
|
||||
$value = Db::i()->select( 'COUNT(*)', 'nexus_purchases', $filter )->first();
|
||||
|
||||
if( $value > 0 )
|
||||
{
|
||||
$total += $value;
|
||||
|
||||
$pieBarData[] = array(
|
||||
'name' => \IPS\Member::loggedIn()->language()->addToStack('nexus_subs_' . $package->id ),
|
||||
'name' => Member::loggedIn()->language()->addToStack('nexus_subs_' . $package->id ),
|
||||
'value' => $value,
|
||||
'percentage' => 0
|
||||
);
|
||||
@@ -133,11 +121,11 @@ class _Subscriptions
|
||||
$package['percentage'] = round( ( $package['value'] / $total ) * 100, 2 );
|
||||
}
|
||||
|
||||
if( \count( $pieBarData ) )
|
||||
if( count( $pieBarData ) )
|
||||
{
|
||||
$chart = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->applePieChart( $pieBarData );
|
||||
$chart = Theme::i()->getTemplate( 'global', 'core', 'global' )->applePieChart( $pieBarData );
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'stats' )->overviewComparisonCount( $total, $previousCount, $chart );
|
||||
return Theme::i()->getTemplate( 'stats' )->overviewComparisonCount( $total, $previousCount, $chart );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user