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

+55 -43
View File
@@ -11,9 +11,21 @@
namespace IPS\Helpers\Chart;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DateTimeZone;
use Exception;
use IPS\DateTime;
use IPS\Http\Url;
use IPS\Member;
use IPS\Request;
use function count;
use function defined;
use function in_array;
use function substr;
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,36 +34,36 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
* This is similar to \IPS\Helpers\Chart\Database but with results supplied manually in user-land code.
* Useful when you need to merge results from multiple sources.
*/
class _Callback extends \IPS\Helpers\Chart\Dynamic
class Callback extends Dynamic
{
/**
* @brief Callback to retrieve results
*/
public $callback;
public mixed $callback = NULL;
/**
* @brief Custom form
*/
public $customFiltersForm = FALSE;
public bool|array $customFiltersForm = FALSE;
/**
* Constructor
*
* @param \IPS\Http\Url $url The URL the chart will be displayed on
* @param callable $callback Callback to fetch results
* @param string $title Title
* @param array $options Options
* @param string $defaultType The default chart type
* @param string $defaultTimescale The default timescale to use
* @param array $defaultTimes The default start/end times to use
* @param string $identifier If there will be more than one chart per page, provide a unique identifier
* @param \IPS\DateTime|NULL $minimumDate The earliest available date for this chart
* @see <a href='https://google-developers.appspot.com/chart/interactive/docs/gallery'>Charts Gallery - Google Charts - Google Developers</a>
* @param Url $url The URL the chart will be displayed on
* @param callable|null $callback Callback to fetch results
* @param string $title Title
* @param array $options Options
* @param string $defaultType The default chart type
* @param string $defaultTimescale The default timescale to use
* @param array $defaultTimes The default start/end times to use
* @param string $identifier If there will be more than one chart per page, provide a unique identifier
* @param DateTime|null $minimumDate The earliest available date for this chart
* @return void
*@see <a href='https://google-developers.appspot.com/chart/interactive/docs/gallery'>Charts Gallery - Google Charts - Google Developers</a>
*/
public function __construct( \IPS\Http\Url $url, $callback=NULL, $title='', $options=array(), $defaultType='AreaChart', $defaultTimescale='monthly', $defaultTimes=array( 'start' => 0, 'end' => 0 ), $identifier='', $minimumDate=NULL )
public function __construct( Url $url, callable $callback=NULL, string $title='', array $options=array(), string $defaultType='AreaChart', string $defaultTimescale='monthly', array $defaultTimes=array( 'start' => 0, 'end' => 0 ), string $identifier='', DateTime $minimumDate=NULL )
{
$this->identifier = \substr( md5( (string) $url ), 0, 6 ) . $identifier . ( \IPS\Request::i()->chartId ?: '_default' );
$this->identifier = substr( md5( (string) $url ), 0, 6 ) . $identifier . ( Request::i()->chartId ?: '_default' );
$this->callback = $callback;
parent::__construct( $url, $title, $options, $defaultType, $defaultTimescale, $defaultTimes, $identifier, $minimumDate );
@@ -60,23 +72,23 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
/**
* Add Series
*
* @param string $name Name
* @param string $type Type of value
* @param string $name Name
* @param string $type Type of value
* @li string
* @li number
* @li boolean
* @li date
* @li datetime
* @li timeofday
* @param bool $filterable If TRUE, will show as a filter option to be toggled on/off
* @param bool $filterable If TRUE, will show as a filter option to be toggled on/off
* @return void
*/
public function addSeries( $name, $type, $filterable=TRUE )
public function addSeries( string $name, string $type, bool $filterable=TRUE ) : void
{
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $name );
Member::loggedIn()->language()->parseOutputForDisplay( $name );
$filterKey = $name;
if ( !$filterable or !isset( \IPS\Request::i()->filters[ $this->identifier ] ) or \in_array( $filterKey, \IPS\Request::i()->filters[ $this->identifier ] ) )
if ( !$filterable or !isset( Request::i()->filters[ $this->identifier ] ) or in_array( $filterKey, Request::i()->filters[ $this->identifier ] ) )
{
if ( $this->type !== 'PieChart' and $this->type !== 'GeoChart' )
{
@@ -89,7 +101,7 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
{
$this->currentFilters[] = $filterKey;
if ( isset( \IPS\Request::i()->filters[ $this->identifier ] ) )
if ( isset( Request::i()->filters[ $this->identifier ] ) )
{
$this->url = $this->url->setQueryString( 'filters', array( $this->identifier => $this->currentFilters ) );
}
@@ -101,14 +113,13 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
$this->availableFilters[ $filterKey ] = $name;
}
}
/**
* Compile Data for Output
*
* @param array $data The data
* @return void
* @return void
*/
public function compileForOutput()
public function compileForOutput() : void
{
/* Init data */
$data = $this->initData();
@@ -122,7 +133,7 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
{
foreach ( $rows as $k => $v )
{
if( \count( $this->availableFilters ) and !\in_array( $k, $this->currentFilters ) )
if( count( $this->availableFilters ) and !in_array( $k, $this->currentFilters ) )
{
continue;
}
@@ -153,18 +164,18 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
$max = NULL;
foreach ( $data as $time => $d )
{
$datetime = new \IPS\DateTime;
$datetime = new DateTime;
if ( \IPS\Member::loggedIn()->timezone )
if ( Member::loggedIn()->timezone )
{
try
{
$datetime->setTimezone( new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) );
$datetime->setTimezone( new DateTimeZone( Member::loggedIn()->timezone ) );
}
catch ( \Exception $e )
catch ( Exception $e )
{
\IPS\Member::loggedIn()->timezone = null;
\IPS\Member::loggedIn()->save();
Member::loggedIn()->timezone = null;
Member::loggedIn()->save();
}
}
@@ -181,7 +192,7 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
switch ( $this->timescale )
{
case 'none':
$datetime = \IPS\DateTime::ts( $time );
$datetime = DateTime::ts( $time );
break;
case 'daily':
@@ -209,14 +220,14 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
}
else
{
$this->addRow( array_merge( array( $datetime ), array_fill( 0, \count( $this->series ), 0 ) ) );
$this->addRow( array_merge( array( $datetime ), array_fill( 0, count( $this->series ), 0 ) ) );
}
}
else
{
if( \count($d) < \count($this->series) )
if( count($d) < count($this->series) )
{
$this->addRow( array_merge( array( $datetime ), $d, array_fill( 0, \count($this->series) - \count($d), 0 ) ) );
$this->addRow( array_merge( array( $datetime ), $d, array_fill( 0, count($this->series) - count($d), 0 ) ) );
}
else
{
@@ -225,7 +236,7 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
}
}
if ( \count( $data ) === 1 )
if ( count( $data ) === 1 )
{
$this->options['domainAxis']['type'] = 'category';
}
@@ -237,12 +248,13 @@ class _Callback extends \IPS\Helpers\Chart\Dynamic
*
* @return string
*/
public function getOutput()
public function getOutput(): string
{
$this->compileForOutput();
if ( isset( \IPS\Request::i()->download ) )
if ( isset( Request::i()->download ) )
{
return $this->download();
$this->download();
return '';
}
else
{