Skip to content

Commit

Permalink
Added has_charts to OPTIONS header for when you only have dynamic cha…
Browse files Browse the repository at this point in the history
…rts 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.
  • Loading branch information
jdorn committed Nov 12, 2013
1 parent e61ed71 commit ec297a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 0 additions & 8 deletions classes/headers/FormattingHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
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
5 changes: 3 additions & 2 deletions 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 @@ -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);
}
}
}
Expand Down

0 comments on commit ec297a6

Please sign in to comment.