class FrxTable in Forena Reports 8
Hierarchy
- class \Drupal\forena\Template\TemplateBase implements TemplateInterface uses FrxAPI
- class \Drupal\forena\Template\FrxTable
Expanded class hierarchy of FrxTable
4 string references to 'FrxTable'
- forena_data_block_preview in forena_ui/
forena.data.inc - forena_report_data_block_form in ./
forena.report.inc - A form to preview and add data blocks to an existing report
- FrxTable::generate in src/
FrxPlugin/ Template/ FrxTable.php - ReportEditor::addBlock in src/
Editor/ ReportEditor.php - Add a data blcok
File
- src/
FrxPlugin/ Template/ FrxTable.php, line 7 - FrxTable Template that lays out a report in a particular table format.
Namespace
Drupal\forena\TemplateView source
class FrxTable extends TemplateBase {
public $templateName = 'Simple Table';
/**
* Extract table configuration from the HTML
* @see FrxRenderer::scrapeConfig()
*/
public function scrapeConfig(\SimpleXMLElement $xml) {
$config = array();
$caption = $this
->extractXPath('*//caption', $this->reportDocDomNode);
$this
->extractTemplateHTML($this->reportDocDomNode, $config, array(
'table',
));
$tds = $this
->extractXPathInnerHTML('*//td', $this->reportDocDomNode, FALSE);
$ths = $this
->extractXPathInnerHTML('*//th', $this->reportDocDomNode, FALSE);
$columns = array_combine($ths, $tds);
$weight = 0;
foreach ($columns as $label => $token) {
$key = trim($token, '{}');
$weight++;
$config['columns'][$key] = array(
'contents' => $token,
'label' => $label,
'include' => 1,
'weight' => $weight,
);
}
return $config;
}
public function generate() {
$config = $this->configuration;
$block = @$config['block'];
$id = @$config['id'];
if ($block) {
$id = $this
->idFromBlock($block);
$config['id'] = $id . '_block';
}
$config['class'] = @$config['class'] ? $config['class'] . ' FrxTable' : 'FrxTable';
$div = $this
->blockDiv($config);
// PUt on the header
$this
->removeChildren($div);
if (isset($config['header']['value'])) {
$this
->addFragment($div, $config['header']['value']);
}
// Decide to inlcude columns
$found_columns = $this
->columns($xml);
if (!$found_columns) {
$found_columns = $this
->columns($xml, '/*');
$attrs = array();
}
$include_column = 0;
$weight = 0;
if (!@$config['columns']) {
$include_column = 1;
}
else {
$weight = count($config['columns']);
}
foreach ($found_columns as $column => $label) {
$token = '{' . $column . '}';
if (!isset($config['columns'][$column])) {
$weight++;
$config['columns'][$column] = array(
'contents' => $token,
'include' => $include_column,
'label' => $label,
'weight' => $weight,
);
}
}
$attrs = array(
'foreach' => '*',
);
$table = $this
->setFirstNode($div, 4, 'table');
if (@$config['caption']) {
$this
->setFirstNode($table, 6, 'caption', $config['caption']);
}
$thead = $this
->setFirstNode($table, 6, 'thead');
$throw = $this
->setFirstNode($thead, 8, 'tr');
$tbody = $this
->setFirstNode($table, 6, 'tbody');
$tdrow = $this
->setFirstNode($tbody, 8, 'tr', NULL, array(
'id' => $id,
), $attrs);
if (isset($config['columns'])) {
foreach ($config['columns'] as $key => $col) {
if ($col['include']) {
$this
->addNode($throw, 10, 'th', $col['label']);
$this
->addNode($tdrow, 10, 'td', $col['contents']);
}
}
}
if (isset($config['footer']['value'])) {
$this
->addFragment($div, $config['footer']['value']);
}
}
public function configForm($config) {
// Load header informationi from parent config.
$form = parent::configForm($config);
$this
->weight_sort($config['columns']);
$form['columns'] = array(
'#theme' => 'forena_element_draggable',
'#draggable_id' => 'FrxTable-columns',
);
$form['caption'] = array(
'#type' => 'textfield',
'#title' => t('Caption'),
'#default_value' => @$config['caption'],
);
foreach ($config['columns'] as $key => $col) {
$ctl = array();
$ctl['label'] = array(
'#type' => 'textfield',
'#size' => 30,
'#title' => t('Label'),
'#default_value' => $col['label'],
);
$ctl['contents'] = array(
'#type' => 'textfield',
'#size' => '30',
'#title' => t('Data'),
'#default_value' => $col['contents'],
);
$ctl['include'] = array(
'#type' => 'checkbox',
'#title' => t('Include'),
'#default_value' => $col['include'],
);
$ctl['weight'] = array(
"#type" => 'weight',
'#title' => t('Weight'),
"#delta" => 50,
'#default_value' => $col['weight'],
);
$form['columns'][$key] = $ctl;
}
return $form;
}
public function configValidate(&$config) {
parent::configValidate($config);
$this
->weight_sort($config['columns']);
}
}
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:: |
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. | |
FrxTable:: |
public | property | ||
FrxTable:: |
public | function | ||
FrxTable:: |
public | function | ||
FrxTable:: |
public | function |
Overrides TemplateInterface:: |
|
FrxTable:: |
public | function |
Extract table configuration from the HTML Overrides TemplateInterface:: |
|
TemplateBase:: |
public | property | ||
TemplateBase:: |
public | property | @var array Confiuration of template | |
TemplateBase:: |
public | property | ||
TemplateBase:: |
public | property | ||
TemplateBase:: |
public | property | ||
TemplateBase:: |
public | property | ||
TemplateBase:: |
public | function | Extract a list of columns from the data context. | |
TemplateBase:: |
public | function |
Overrides TemplateInterface:: |
|
TemplateBase:: |
public | function |
Return the inside xml of the current node Overrides FrxAPI:: |