Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+119 -64
View File
@@ -11,7 +11,7 @@
namespace IPS\Helpers\Chart;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
@@ -83,7 +83,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
{
$this->table = $table;
$this->dateField = $dateField;
$this->identifier = \substr( md5( $table . $dateField ), 0, 6 ) . ( $identifier ?: ( \IPS\Request::i()->chartId ?: '_default' ) );
$this->identifier = \substr( md5( $table . $dateField ), 0, 6 ) . $identifier . ( \IPS\Request::i()->chartId ?: '_default' );
if ( !empty( $tableInclude ) )
{
@@ -121,7 +121,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
$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( \IPS\Request::i()->filters[ $this->identifier ] ) or \in_array( $filterKey, \IPS\Request::i()->filters[ $this->identifier ] ) )
{
if ( $this->type !== 'PieChart' and $this->type !== 'GeoChart' )
{
@@ -153,21 +153,13 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
}
/**
* Get the chart output
* Compile Data for Output
*
* @return string
* @param array $data The data
* @return void
*/
public function getOutput()
public function compileForOutput(): void
{
/* Auto-support tables where appropriate */
if ( !empty( $this->tableInclude ) )
{
if( !array_search( 'Table', $this->availableTypes ) )
{
$this->availableTypes[] = 'Table';
}
}
/* Init data */
$data = $this->initData();
@@ -195,7 +187,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
break;
case 'weekly':
$timescale = '%Y-%u';
$timescale = '%x-%v';
break;
case 'monthly':
@@ -203,40 +195,6 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
break;
}
/* Table... */
if ( $this->type === 'Table' )
{
/* Are we filtering? */
if( $this->groupBy )
{
if( count( $this->availableFilters ) AND count( $this->currentFilters ) )
{
$where[] = array( \IPS\Db::i()->in( $this->groupBy, $this->currentFilters ) );
}
}
$table = new \IPS\Helpers\Table\Db( $this->table, $this->url, $where );
/* Reformat chart join for the table helper */
if( \is_array( $this->joins ) )
{
array_walk( $this->joins, function ( $item ) use ( $table )
{
$table->joins[] = array('from' => $item[0], 'where' => $item[1], 'type' => isset( $item[2] ) ? $item[2] : 'LEFT');
} );
}
if( count( $this->tableInclude ) )
{
$table->include = $this->tableInclude;
}
$table->parsers = $this->tableParsers;
$table->sortBy = $table->sortBy ?: $this->dateField;
$output = (string) $table;
return $output;
}
/* Pie Chart */
if ( $this->type === 'PieChart' or $this->type === 'GeoChart' )
{
@@ -252,7 +210,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
$this->groupBy
)->setKeyField( $this->groupBy )->setValueField( $key );
if( count( $this->joins ) )
if( \count( $this->joins ) )
{
foreach( $this->joins as $join )
{
@@ -262,14 +220,12 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
foreach ( $stmt as $k => $v )
{
if( count( $this->availableFilters ) and !in_array( $k, $this->currentFilters ) )
if( \count( $this->availableFilters ) and !\in_array( $k, $this->currentFilters ) )
{
continue;
}
$this->addRow( array( 'key' => $this->availableFilters[ $k ], 'value' => $v ) );
}
$output = $this->render( $this->type, $this->options, $this->format );
}
/* Graph */
@@ -277,7 +233,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
{
/* Fetch */
$fromUnixTime = "FROM_UNIXTIME( IFNULL( {$this->dateField}, 0 ) )";
if ( !$this->timezoneError and \IPS\Member::loggedIn()->timezone and in_array( \IPS\Member::loggedIn()->timezone, \DateTimeZone::listIdentifiers() ) )
if ( !$this->timezoneError and \IPS\Member::loggedIn()->timezone and \in_array( \IPS\Member::loggedIn()->timezone, \DateTimeZone::listIdentifiers() ) )
{
$fromUnixTime = "CONVERT_TZ( {$fromUnixTime}, @@session.time_zone, '" . \IPS\Db::i()->escape_string( \IPS\Member::loggedIn()->timezone ) . "' )";
}
@@ -290,7 +246,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
$this->groupBy ? array( 'time_as_alias', $this->groupBy ) : 'time_as_alias'
);
if( count( $this->joins ) )
if( \count( $this->joins ) )
{
foreach( $this->joins as $join )
{
@@ -304,7 +260,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
if( $this->groupBy )
{
if( count( $this->availableFilters ) AND !in_array( $row[ $this->groupBy ], $this->currentFilters ) )
if( \count( $this->availableFilters ) AND !\in_array( $row[ $this->groupBy ], $this->currentFilters ) )
{
continue;
}
@@ -396,7 +352,7 @@ class _Database 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
@@ -413,9 +369,9 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
}
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
{
@@ -425,14 +381,113 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
}
}
if ( count( $data ) === 1 )
if ( \count( $data ) === 1 )
{
$this->options['domainAxis']['type'] = 'category';
}
$output = $this->render( $this->type, $this->options, $this->format );
}
}
/**
* Get the chart output
*
* @return string
*/
public function getOutput()
{
/* Auto-support tables where appropriate */
if ( !empty( $this->tableInclude ) )
{
if( !array_search( 'Table', $this->availableTypes ) )
{
$this->availableTypes[] = 'Table';
}
}
/* Work out where clause */
$where = $this->where;
$where[] = array( "{$this->dateField}>?", 0 );
if ( $this->start )
{
$where[] = array( "{$this->dateField}>?", $this->start->getTimestamp() );
}
if ( $this->end )
{
$where[] = array( "{$this->dateField}<?", $this->end->getTimestamp() );
}
/* Table... */
if ( $this->type === 'Table' )
{
/* Are we filtering? */
if( $this->groupBy )
{
if( \count( $this->availableFilters ) AND \count( $this->currentFilters ) )
{
$where[] = array( \IPS\Db::i()->in( $this->groupBy, $this->currentFilters ) );
}
}
return $output;
$table = new \IPS\Helpers\Table\Db( $this->table, $this->url, $where );
/* Reformat chart join for the table helper */
if( \is_array( $this->joins ) )
{
array_walk( $this->joins, function ( $item ) use ( $table )
{
$table->joins[] = array('from' => $item[0], 'where' => $item[1], 'type' => isset( $item[2] ) ? $item[2] : 'LEFT');
} );
}
if( \count( $this->tableInclude ) )
{
$table->include = $this->tableInclude;
}
$table->parsers = $this->tableParsers;
$table->sortBy = $table->sortBy ?: $this->dateField;
if ( isset( \IPS\Request::i()->download ) )
{
$headers = array();
foreach( $table->getHeaders( $table->getAdvancedSearchValues() ) AS $header )
{
if ( $header === '_buttons' )
{
continue;
}
$headers[] = array(
'label' => \IPS\Member::loggedIn()->language()->addToStack( $header ),
'type' => 'string'
);
}
$rows = array();
foreach( $table->getRows( $table->getAdvancedSearchValues() ) AS $k => $v )
{
$rows[$k] = array();
foreach( $v AS $j => $value )
{
$rows[$k][] = trim( strip_tags( (string) $value ) );
}
}
return $this->download( $headers, $rows, \IPS\Output::i()->title );
}
$output = (string) $table;
return $output;
}
$this->compileForOutput();
if ( isset( \IPS\Request::i()->download ) )
{
return $this->download();
}
else
{
return $this->render( $this->type, $this->options, $this->format );
}
}
}