From e61ed71a2e05dd73ab874bc0971e88e9bc8e5989 Mon Sep 17 00:00:00 2001 From: jdorn Date: Tue, 12 Nov 2013 15:11:15 -0800 Subject: [PATCH 1/2] Initial support for defining dynamic headers for a dataset. --- classes/headers/FormattingHeader.php | 8 ++++++++ lib/PhpReports/Report.php | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/classes/headers/FormattingHeader.php b/classes/headers/FormattingHeader.php index f0cda581..f5e9edf3 100644 --- a/classes/headers/FormattingHeader.php +++ b/classes/headers/FormattingHeader.php @@ -34,12 +34,20 @@ class FormattingHeader extends HeaderBase { 'dataset'=>array( 'required'=>true, 'default'=>true + ), + 'has_charts'=>array( + 'type'=>'boolean' ) ); public static function init($params, &$report) { if(!isset($report->options['Formatting'])) $report->options['Formatting'] = array(); $report->options['Formatting'][] = $params; + + if(isset($params['has_charts']) && $params['has_charts']) { + $report->options['has_charts'] = true; + if(!isset($report->options['Charts'])) $report->options['Charts'] = array(); + } } public static function parseShortcut($value) { diff --git a/lib/PhpReports/Report.php b/lib/PhpReports/Report.php index f4a4af07..3c8ef478 100644 --- a/lib/PhpReports/Report.php +++ b/lib/PhpReports/Report.php @@ -412,6 +412,20 @@ protected function _runReport() { } $this->options['DataSets'] = $datasets; + + $this->parseDynamicHeaders(); + } + + protected function parseDynamicHeaders() { + foreach($this->options['DataSets'] as $i=>&$dataset) { + if(isset($dataset['headers'])) { + foreach($dataset['headers'] as $j=>$header) { + if(isset($header['header']) && isset($header['value'])) { + $this->parseHeader($header['header'],$header['value']); + } + } + } + } } protected function getTimeEstimate() { From ec297a61f79c98fdb8d4557219425a25dd62fed9 Mon Sep 17 00:00:00 2001 From: jdorn Date: Tue, 12 Nov 2013 15:21:29 -0800 Subject: [PATCH 2/2] Added has_charts to OPTIONS header for when you only have dynamic charts for a report. Made it so if you define a chart header for a dataset, it will use that dataset's properties without having to specify it. --- classes/headers/FormattingHeader.php | 8 -------- classes/headers/OptionsHeader.php | 7 +++++++ lib/PhpReports/Report.php | 5 +++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/classes/headers/FormattingHeader.php b/classes/headers/FormattingHeader.php index f5e9edf3..f0cda581 100644 --- a/classes/headers/FormattingHeader.php +++ b/classes/headers/FormattingHeader.php @@ -34,20 +34,12 @@ class FormattingHeader extends HeaderBase { 'dataset'=>array( 'required'=>true, 'default'=>true - ), - 'has_charts'=>array( - 'type'=>'boolean' ) ); public static function init($params, &$report) { if(!isset($report->options['Formatting'])) $report->options['Formatting'] = array(); $report->options['Formatting'][] = $params; - - if(isset($params['has_charts']) && $params['has_charts']) { - $report->options['has_charts'] = true; - if(!isset($report->options['Charts'])) $report->options['Charts'] = array(); - } } public static function parseShortcut($value) { diff --git a/classes/headers/OptionsHeader.php b/classes/headers/OptionsHeader.php index 5785ce2a..afd6f0b0 100644 --- a/classes/headers/OptionsHeader.php +++ b/classes/headers/OptionsHeader.php @@ -69,6 +69,9 @@ class OptionsHeader extends HeaderBase { 'default_dataset'=>array( 'type'=>'number', 'default'=>0 + ), + 'has_charts'=>array( + 'type'=>'boolean' ) ); @@ -78,6 +81,10 @@ public static function init($params, &$report) { $params['cache'] = $params['ttl']; unset($params['ttl']); } + + if(isset($params['has_charts']) && $params['has_charts']) { + if(!isset($report->options['Charts'])) $report->options['Charts'] = array(); + } // Some parameters were moved to a 'FORMATTING' header // We need to catch those and add the header to the report diff --git a/lib/PhpReports/Report.php b/lib/PhpReports/Report.php index 3c8ef478..2c7df9b1 100644 --- a/lib/PhpReports/Report.php +++ b/lib/PhpReports/Report.php @@ -220,9 +220,10 @@ protected function parseHeaders() { if(!isset($this->options['Name'])) $this->options['Name'] = $this->report; } - public function parseHeader($name,$value) { + public function parseHeader($name,$value,$dataset=null) { $classname = $name.'Header'; if(class_exists($classname)) { + if($dataset !== null && isset($classname::$validation) && isset($classname::$validation['dataset'])) $value['dataset'] = $dataset; $classname::parse($name,$value,$this); if(!in_array($name,$this->headers)) $this->headers[] = $name; } @@ -421,7 +422,7 @@ protected function parseDynamicHeaders() { if(isset($dataset['headers'])) { foreach($dataset['headers'] as $j=>$header) { if(isset($header['header']) && isset($header['value'])) { - $this->parseHeader($header['header'],$header['value']); + $this->parseHeader($header['header'],$header['value'],$i); } } }