Version 4.7.0
This commit is contained in:
1 parent
517a5e1f70
commit
8ba7d43898
1933 files changed
+65613
-11332
No files matched your search
@@ -61,6 +61,16 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
* @brief Table Column Formatters
|
||||
*/
|
||||
public $tableParsers = array();
|
||||
|
||||
/**
|
||||
* @brief Along with the other series, show one of the sum of all
|
||||
*/
|
||||
public $allRecordsSeries = FALSE;
|
||||
|
||||
/**
|
||||
* @brief The lang string used to label the 'all records' series
|
||||
*/
|
||||
public $allRecordsLang = 'database_chart_all_series';
|
||||
|
||||
/**
|
||||
* @brief Custom form
|
||||
@@ -182,7 +192,10 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
}
|
||||
|
||||
$this->groupBy = $this->customFiltersForm['groupBy'];
|
||||
$this->where = array( array( $whereFunction( $values ) ) );
|
||||
|
||||
$whereFunctionResult = $whereFunction( $values );
|
||||
|
||||
$this->where[] = \is_array( $whereFunctionResult ) ? $whereFunctionResult : array( $whereFunctionResult );
|
||||
|
||||
foreach( $seriesFunction( $values ) as $series )
|
||||
{
|
||||
@@ -195,7 +208,9 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
$seriesFunction = $this->customFiltersForm['series'];
|
||||
|
||||
$this->groupBy = $this->customFiltersForm['groupBy'];
|
||||
$this->where = array( array( $whereFunction( $this->savedCustomFilters ) ) );
|
||||
|
||||
$whereFunctionResult = $whereFunction( $this->savedCustomFilters );
|
||||
$this->where[] = \is_array( $whereFunctionResult ) ? $whereFunctionResult : array( $whereFunctionResult );
|
||||
|
||||
foreach( $seriesFunction( $this->savedCustomFilters ) as $series )
|
||||
{
|
||||
@@ -212,7 +227,65 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $this->allRecordsSeries )
|
||||
{
|
||||
/* 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() );
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
case 'weekly':
|
||||
$timescale = '%x-%v';
|
||||
break;
|
||||
|
||||
case 'monthly':
|
||||
$timescale = '%Y-%c';
|
||||
break;
|
||||
}
|
||||
|
||||
$fromUnixTime = "FROM_UNIXTIME( IFNULL( {$this->dateField}, 0 ) )";
|
||||
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 ) . "' )";
|
||||
}
|
||||
|
||||
$allRecordsStatement = \IPS\Db::i()->select(
|
||||
"SQL_BIG_RESULT DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time_as_alias, COUNT(*) as $this->allRecordsLang",
|
||||
$this->table,
|
||||
$where,
|
||||
'time_as_alias ASC',
|
||||
NULL,
|
||||
'time_as_alias'
|
||||
);
|
||||
|
||||
foreach ( $allRecordsStatement as $allRecordsRow )
|
||||
{
|
||||
$data[ $allRecordsRow['time_as_alias'] ] = $data[ $allRecordsRow['time_as_alias'] ] ?? array();
|
||||
$data[ $allRecordsRow['time_as_alias'] ][$this->allRecordsLang] = $allRecordsRow[$this->allRecordsLang];
|
||||
}
|
||||
|
||||
$this->addSeries( \IPS\Member::loggedIn()->language()->addToStack($this->allRecordsLang), 'number', 'COUNT(*)', FALSE, $this->allRecordsLang );
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -303,7 +376,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
}
|
||||
|
||||
$stmt = \IPS\Db::i()->select(
|
||||
"SQL_BIG_RESULT DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time_as_alias, " . implode( ', ', array_unique( $this->series ) ) . ( $this->groupBy ? ", " . $this->groupBy : '' ),
|
||||
"SQL_BIG_RESULT DATE_FORMAT( {$fromUnixTime}, '{$timescale}' ) AS time_as_alias" . ( \count( $this->series ) ? "," : "" ) . implode( ', ', array_unique( $this->series ) ) . ( $this->groupBy ? ", " . $this->groupBy : '' ),
|
||||
$this->table,
|
||||
$where,
|
||||
'time_as_alias ASC',
|
||||
@@ -330,7 +403,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach( $this->series as $column )
|
||||
{
|
||||
if( $this->groupBy )
|
||||
@@ -546,6 +619,7 @@ class _Database extends \IPS\Helpers\Chart\Dynamic
|
||||
}
|
||||
|
||||
$this->compileForOutput();
|
||||
|
||||
if ( isset( \IPS\Request::i()->download ) )
|
||||
{
|
||||
return $this->download();
|
||||
|
||||
Reference in new issue
Block a user