class FrxCrosstab in Forena Reports 8
Same name in this branch
- 8 src/FrxPlugin/Template/FrxCrosstab.php \Drupal\forena\Template\FrxCrosstab
- 8 src/FrxPlugin/Renderer/FrxCrosstab.php \Drupal\forena\FrxPlugin\Renderer\FrxCrosstab
Crosstab Renderer
Plugin annotation
@FrxRenderer(id = "FrxCrosstab")
Hierarchy
- class \Drupal\forena\FrxPlugin\Renderer\RendererBase implements RendererInterface uses FrxAPI
- class \Drupal\forena\FrxPlugin\Renderer\FrxCrosstab uses FrxAPI
Expanded class hierarchy of FrxCrosstab
2 string references to 'FrxCrosstab'
- FrxCrosstab::generate in src/
FrxPlugin/ Template/ FrxCrosstab.php - FrxSVGGraph::generateCrossTab in src/
FrxPlugin/ Template/ FrxSVGGraph.php - Generate a crosstab table.
File
- src/
FrxPlugin/ Renderer/ FrxCrosstab.php, line 13
Namespace
Drupal\forena\FrxPlugin\RendererView source
class FrxCrosstab extends RendererBase {
use FrxAPI;
public $templateName = 'Crosstab';
private $dim_columns = array();
private $group_columns = array();
private $dim_headers = array();
private $group_headers = array();
/**
* Generate default headers from Embedded xml.
*/
private function defaultHeaders() {
$node = $this->reportNode;
if ($node->thead && $node->thead->tr) {
/** @var \SimpleXMLElement $cell */
foreach ($node->thead->tr
->children() as $name => $cell) {
$hcol = array();
$hcol['data'] = $this
->innerXML($cell);
$hcol['depth'] = 1;
foreach ($cell
->attributes() as $k => $v) {
$hcol[$k] = (string) $v;
}
if ($name == 'th') {
$this->group_headers[] = $hcol;
}
else {
$this->dim_headers[] = $hcol;
}
}
}
if ($node->tbody && $node->tbody->tr) {
foreach ($node->tbody->tr
->children() as $name => $cell) {
$col = array();
$col['data'] = $this
->innerXML($cell);
foreach ($cell
->attributes() as $k => $v) {
$col[$k] = (string) $v;
}
if ($name == 'th') {
$this->group_columns[] = $col;
}
else {
$this->dim_columns[] = $col;
}
}
}
}
/**
* Render the crosstab
*/
public function render() {
$variables = $this
->mergedAttributes();
$attributes = $this
->replacedAttributes();
$format = $this
->documentManager()
->getDocumentType();
if (!empty($variables['hidden']) && $format != 'csv' && $format != 'xls') {
return '';
}
$path = isset($variables['path']) ? $variables['path'] : '*';
if (!$path) {
$path = "*";
}
$group = $variables['group'];
$dim = $variables['dim'];
$sum = (array) @$variables['sum'];
// Get the current context
$data = $this
->currentDataContext();
// Generate the data nodes.
if (is_object($data)) {
if (method_exists($data, 'xpath')) {
$nodes = $data
->xpath($path);
}
else {
$nodes = $data;
}
}
else {
$nodes = (array) $data;
}
// Group the data.
$data = $this->report
->group($nodes, $group, $sum);
$this->dim_headers = array();
$dim_rows = array();
$this->dim_columns = array();
$this->group_columns = array();
$this->group_headers = array();
$dim_values = array();
$rows = array();
foreach ($data as $gk => $group_rows) {
$dims = $this->report
->group($group_rows, $dim);
$rows[$gk] = $group_rows[0];
foreach ($dims as $dk => $r) {
$dim_values[$dk] = $dk;
$dim_rows[$gk][$dk] = $r[0];
}
}
// Default controling attributes
$this
->defaultHeaders();
$hrow = array();
foreach ($this->group_headers as $col) {
$cell = $col;
if (count($this->dim_columns) > 1) {
$cell['rowspan'] = 2;
}
$hrow[] = $cell;
}
// Add the dimension headers.
foreach ($dim_values as $dk) {
foreach ($this->dim_headers as $i => $col) {
$cell = $col;
$cell['data'] = $dk;
if (count($this->dim_columns) > 1) {
$cell['data'] = $i ? $col['data'] : $dk . ' ' . $col['data'];
}
$hrow[] = $cell;
}
}
$trows = array();
foreach ($rows as $k => $row) {
$this
->pushData($row, '_group');
$trow = array();
// Base group
foreach ($this->group_columns as $col) {
$cell = $col;
foreach ($col as $key => $v) {
$cell[$key] = $this->report
->replace($v);
}
$trow[] = $cell;
}
$this
->popData();
// Dimensions
$dim_data = $dim_rows[$k];
foreach ($dim_values as $dk) {
$dim_row = isset($dim_data[$dk]) ? $dim_data[$dk] : array();
$this
->pushData($dim_row, '_dim');
foreach ($this->dim_columns as $col) {
$cell = $col;
foreach ($col as $k => $v) {
$cell[$k] = $this->report
->replace($v);
}
$trow[] = $cell;
}
$this
->popData();
}
$trows[] = $trow;
}
$class = 'crosstab-table';
if (isset($attributes['class'])) {
$class .= ' ' . $attributes['class'];
}
$elements[] = [
'#type' => 'table',
'#header' => $hrow,
'#rows' => $trows,
'#attributes' => array(
'class' => array(
$class,
),
),
];
$output = AppService::instance()
->drupalRender($elements);
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FrxAPI:: |
public | function | Returns containing application service | |
FrxAPI:: |
public | function | Get the current data context. | |
FrxAPI:: |
public | function | ||
FrxAPI:: |
public | function | Returns the data manager service | |
FrxAPI:: |
public | function | Return Data Service | |
FrxAPI:: |
public | function | Returns the fornea document manager | |
FrxAPI:: |
public | function | Report an error | |
FrxAPI:: |
public | function | Get the context of a specific id. | |
FrxAPI:: |
public | function | Get the current document | |
FrxAPI:: |
public | function | Load the contents of a file in the report file system. | |
FrxAPI:: |
function | Enter description here... | 1 | |
FrxAPI:: |
public | function | Pop data off of the stack. | |
FrxAPI:: |
public | function | Push data onto the Stack | |
FrxAPI:: |
public | function | Run a report with a particular format. | 1 |
FrxAPI:: |
public | function | Get the current report file system. | |
FrxAPI:: |
public | function | Set Data context by id. | |
FrxAPI:: |
public | function | Change to a specific document type. | |
FrxAPI:: |
public | function | Get list of skins. | |
FrxCrosstab:: |
private | property | ||
FrxCrosstab:: |
private | property | ||
FrxCrosstab:: |
private | property | ||
FrxCrosstab:: |
private | property | ||
FrxCrosstab:: |
public | property | ||
FrxCrosstab:: |
private | function | Generate default headers from Embedded xml. | |
FrxCrosstab:: |
public | function |
Render the crosstab Overrides RendererBase:: |
|
RendererBase:: |
public | property | ||
RendererBase:: |
protected | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public | property | ||
RendererBase:: |
public static | function | Helper function for convergint methods to a standard associated array. | |
RendererBase:: |
function | Append a textual XHTML fragment to the dom. We do not use the DOMDocumentFragment optioin because they don't properly import namespaces. . | ||
RendererBase:: |
function | Add a node to the existing dom element with attributes | ||
RendererBase:: |
function | Add a text node to the current dom node. | ||
RendererBase:: |
public | function | Puts attributes back in array format prior to rendering. | |
RendererBase:: |
public | function | Generate generic div tag. | |
RendererBase:: |
public | function | Extract a list of columns from the data context. | |
RendererBase:: |
public | function | Generate ajax configuration attributes for use in template configurtion forms. | |
RendererBase:: |
public | function | Default configuration validator. Simply validates header and footer attributes. | |
RendererBase:: |
public | function | Render a drupal form in a forena template | |
RendererBase:: |
public | function | Extract a configuration var removing it from the array | |
RendererBase:: |
public | function | Get the textual representations of html for the configuration engine. | |
RendererBase:: |
public | function | Get the textual representations of html for the configuration engine. | |
RendererBase:: |
public | function | Get the textual representations of html for the configuration engine. | |
RendererBase:: |
public | function | Extracts the inner html of all nodes that match a particular xpath expression. | |
RendererBase:: |
public | function | Extracts the inner html of all nodes that match a particular xpath expression. | |
RendererBase:: |
public | function | Generate the template from the configuration. | |
RendererBase:: |
public | function | Simple function to get id from node. | |
RendererBase:: |
public | function |
This function is called to give the renderer the current conetxt in report rendering.
It makes sure the renderer has the current DOM nodes dom documnent, and other attributes. Overrides RendererInterface:: |
|
RendererBase:: |
public | function | Standard php array containing merged attributes Enter description here ... | |
RendererBase:: |
public | function | Rmove all the children of a dom node in the current report. | |
RendererBase:: |
public | function | Removes all chidren from the dome node expect those with a tagname specified by the the $tags argurment | |
RendererBase:: |
public | function | ||
RendererBase:: |
public | function | Recursive report renderer Walks the nodes rendering the report. | |
RendererBase:: |
public | function | Gives the token replaced attributes of a node. | |
RendererBase:: |
public | function | A helper function to allow replacement of tokens from inside a renderer wihout needing to understand the object | |
RendererBase:: |
public | function | Starting at the current report node, this function removes all child nodes. It aso removes any FRX attributes on the current as well. | |
RendererBase:: |
public | function | Default method for extracting configuration information from the template. This just scrapes teh current child html as the template. | |
RendererBase:: |
public | function | Set FRX attributes. | |
RendererBase:: |
public | function | Sets the first child element to a node and returns it. IF the node | |
RendererBase:: |
public | function | Helper function for validating text_format type controls. | |
RendererBase:: |
public | function | Sort a column list by weight. | |
RendererBase:: |
public static | function | ||
RendererBase:: |
public | function | ||
RendererBase:: |
public | function | Convert XML to key value pairs. This is used in support of graping to get specific key/value pairs in an array format suitable for passing off to php libraries. | |
RendererBase:: |
public | function |
Overrides RendererInterface:: |
1 |