Skip to content

Commit

Permalink
Merge pull request jdorn#105 from jdorn/dynamic_headers
Browse files Browse the repository at this point in the history
Dynamic headers
  • Loading branch information
jdorn committed Nov 12, 2013
2 parents a956e30 + ec297a6 commit 3988ef8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions classes/headers/OptionsHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class OptionsHeader extends HeaderBase {
'default_dataset'=>array(
'type'=>'number',
'default'=>0
),
'has_charts'=>array(
'type'=>'boolean'
)
);

Expand All @@ -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
Expand Down
17 changes: 16 additions & 1 deletion lib/PhpReports/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -412,6 +413,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'],$i);
}
}
}
}
}

protected function getTimeEstimate() {
Expand Down

0 comments on commit 3988ef8

Please sign in to comment.