Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -36,6 +36,11 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
* @brief Where clauses
|
||||
*/
|
||||
public $where = array();
|
||||
|
||||
/**
|
||||
* @brief Query joins
|
||||
*/
|
||||
public $joins = array();
|
||||
|
||||
/**
|
||||
* @brief Extra column to group by (useful for multi-data line charts)
|
||||
@@ -78,12 +83,11 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
{
|
||||
$this->table = $table;
|
||||
$this->dateField = $dateField;
|
||||
$this->identifier = \substr( md5( $table . $dateField ), 0, 6 ) . $identifier;
|
||||
$this->identifier = \substr( md5( $table . $dateField ), 0, 6 ) . ( $identifier ?: ( \IPS\Request::i()->chartId ?: '_default' ) );
|
||||
|
||||
if ( !empty( $tableInclude ) )
|
||||
{
|
||||
$this->tableInclude = $tableInclude;
|
||||
$this->availableTypes[] = 'Table';
|
||||
}
|
||||
|
||||
parent::__construct( $url, $title, $options, $defaultType, $defaultTimescale, $defaultTimes, $identifier, $minimumDate );
|
||||
@@ -155,6 +159,15 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
/* Auto-support tables where appropriate */
|
||||
if ( !empty( $this->tableInclude ) )
|
||||
{
|
||||
if( !array_search( 'Table', $this->availableTypes ) )
|
||||
{
|
||||
$this->availableTypes[] = 'Table';
|
||||
}
|
||||
}
|
||||
|
||||
/* Init data */
|
||||
$data = $this->initData();
|
||||
|
||||
@@ -173,6 +186,10 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
/* What's our SQL time? */
|
||||
switch ( $this->timescale )
|
||||
{
|
||||
case 'hourly':
|
||||
$timescale = '%Y-%c-%e-%H-%i-%s';
|
||||
break;
|
||||
|
||||
case 'daily':
|
||||
$timescale = '%Y-%c-%e';
|
||||
break;
|
||||
@@ -189,11 +206,27 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
/* 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 );
|
||||
$table->include = $this->tableInclude;
|
||||
$table->joins = $this->joins;
|
||||
|
||||
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 */
|
||||
@@ -210,6 +243,14 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
NULL,
|
||||
$this->groupBy
|
||||
)->setKeyField( $this->groupBy )->setValueField( $key );
|
||||
|
||||
if( count( $this->joins ) )
|
||||
{
|
||||
foreach( $this->joins as $join )
|
||||
{
|
||||
$stmt = $stmt->join( $join[0], $join[1], ( isset( $join[2] ) ? $join[2] : 'LEFT' ), ( isset( $join[3] ) ? $join[3] : FALSE ) );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $stmt as $k => $v )
|
||||
{
|
||||
@@ -241,6 +282,14 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
$this->groupBy ? array( 'time_as_alias', $this->groupBy ) : 'time_as_alias'
|
||||
);
|
||||
|
||||
if( count( $this->joins ) )
|
||||
{
|
||||
foreach( $this->joins as $join )
|
||||
{
|
||||
$stmt = $stmt->join( $join[0], $join[1], ( isset( $join[2] ) ? $join[2] : 'LEFT' ), ( isset( $join[3] ) ? $join[3] : FALSE ) );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $stmt as $row )
|
||||
{
|
||||
$result = array();
|
||||
@@ -300,26 +349,35 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
|
||||
$datetime->setTime( 0, 0, 0 );
|
||||
$exploded = explode( '-', $time );
|
||||
switch ( $this->timescale )
|
||||
{
|
||||
case 'none':
|
||||
$datetime = \IPS\DateTime::ts( $time );
|
||||
break;
|
||||
|
||||
case 'daily':
|
||||
$datetime->setDate( (float) $exploded[0], $exploded[1], $exploded[2] );
|
||||
//$datetime = $datetime->localeDate();
|
||||
break;
|
||||
|
||||
case 'weekly':
|
||||
$datetime->setISODate( (float) $exploded[0], $exploded[1] );
|
||||
//$datetime = $datetime->localeDate();
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
$datetime->setDate( (float) $exploded[0], $exploded[1], 1 );
|
||||
//$datetime = $datetime->format( 'F Y' );
|
||||
break;
|
||||
if( $this->enableHourly === TRUE AND $this->timescale == 'hourly' )
|
||||
{
|
||||
$datetime->setDate( (float) $exploded[0], $exploded[1], $exploded[2] );
|
||||
$datetime->setTime( $exploded[3], $exploded[4], $exploded[5] );
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( $this->timescale )
|
||||
{
|
||||
case 'none':
|
||||
$datetime = \IPS\DateTime::ts( $time );
|
||||
break;
|
||||
|
||||
case 'daily':
|
||||
$datetime->setDate( (float) $exploded[0], $exploded[1], $exploded[2] );
|
||||
//$datetime = $datetime->localeDate();
|
||||
break;
|
||||
|
||||
case 'weekly':
|
||||
$datetime->setISODate( (float) $exploded[0], $exploded[1] );
|
||||
//$datetime = $datetime->localeDate();
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
$datetime->setDate( (float) $exploded[0], $exploded[1], 1 );
|
||||
//$datetime = $datetime->format( 'F Y' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $d ) )
|
||||
|
||||
Reference in new issue
Block a user