class CSV in Forena Reports 8
Provides CSV file exports
Plugin annotation
@FrxDocument(
id= "csv",
name="Comma Separated Values",
ext="csv"
)
Hierarchy
- class \Drupal\forena\FrxPlugin\Document\DocumentBase implements DocumentInterface uses FrxAPI
- class \Drupal\forena\FrxPlugin\Document\CSV
Expanded class hierarchy of CSV
File
- src/
FrxPlugin/ Document/ CSV.php, line 18 - Implements \Drupal\forena\FrxPlugin\Document\CSV
Namespace
Drupal\forena\FrxPlugin\DocumentView source
class CSV extends DocumentBase {
public function __construct() {
$this->content_type = 'application/csv';
}
public function flush() {
$doc = $this->write_buffer;
$dom = new \DOMDocument();
$dom->strictErrorChecking = FALSE;
$xmlBody = '<?xml version="1.0" encoding="UTF-8"?>' . $doc;
libxml_use_internal_errors(TRUE);
@$dom
->loadHTML($xmlBody);
libxml_clear_errors();
/** @var \SimpleXMLElement $xml */
$xml = simplexml_import_dom($dom);
$output = '';
$rows = array();
if (!empty($xml)) {
$rows = $xml
->xpath('//tr');
}
$rowspans = array();
if ($rows) {
foreach ($rows as $row) {
$c = 0;
$line = '';
/** @var \SimpleXMLElement $column */
foreach ($row as $column) {
$c++;
if (@$rowspans[$c]) {
$cont = TRUE;
while ($rowspans[$c] && $cont) {
$rowspans[$c]--;
$output .= ',';
$c++;
}
}
$value = $column
->asXML();
$value = strip_tags($value);
$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
$value = str_replace('"', '""', $value);
$value = str_replace(array(
"\n",
), '', $value);
$value = strpos($value, ',') !== FALSE || strpos($value, '"') !== FALSE ? '"' . $value . '",' : "{$value},";
$line .= $value;
// Add Column span elements
if ((int) $column['colspan'] > 1) {
for ($i = 2; $i <= (int) $column['colspan']; $i++) {
$c++;
$line .= ',';
}
}
// Check to see if we have some rowspans that we need to save
if ((int) $column['rowspan'] > 1) {
$rowspans[$c] = (int) $column['rowspan'] - 1;
}
}
// Trim off the last comma so we don't put in an extra null column
$line = substr($line, 0, -1);
$output .= "{$line}\n";
}
}
return $output;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CSV:: |
public | function |
Write the output to disk. Overrides DocumentBase:: |
|
CSV:: |
public | function | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | property | ||
DocumentBase:: |
protected | property | ||
DocumentBase:: |
public | function | ||
DocumentBase:: |
public | function | Wrapper function for check output to default the right type. | |
DocumentBase:: |
public | function |
Clear the buffer Overrides DocumentInterface:: |
|
DocumentBase:: |
public | function | Perform character set conversion | |
DocumentBase:: |
public | function |
No default footer. Overrides DocumentInterface:: |
1 |
DocumentBase:: |
public | function | ||
DocumentBase:: |
public | function |
Default implementation to put in content type based headers. Overrides DocumentInterface:: |
8 |
DocumentBase:: |
public | function |
Overrides DocumentInterface:: |
|
DocumentBase:: |
public | function |
Overrides DocumentInterface:: |
|
DocumentBase:: |
public | function |
Write Overrides DocumentInterface:: |
|
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. |