Skip to content

Commit

Permalink
Experimenting with auto header handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Shaw committed Mar 11, 2012
1 parent f9730ba commit b4744d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
24 changes: 21 additions & 3 deletions library/Gridola/Export.php
Expand Up @@ -27,8 +27,6 @@ public function __construct($dataSource, $dataGrid, $dataGridName, $settings)

abstract protected function deploy();

abstract protected function header();

protected function setDataSource($dataSource)
{
$this->_dataSource = $dataSource;
Expand Down Expand Up @@ -104,7 +102,7 @@ protected function disableLayout()

protected function filter($string)
{
$string = str_replace(array("\r","\t","\n",","), " ", $string);
$string = str_replace(array("\r","\t","\n"), " ", $string);
$string = str_replace('"', '""', $string);
return stripslashes($string);
}
Expand Down Expand Up @@ -138,6 +136,26 @@ protected function getSettings()
return $this->_settings;
}

protected function header()
{
header('Content-Description: File Transfer');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
switch($this->getExportType()) {
case 'csv':
header("Content-Type: application/" . $this->getExportType());
break;
case 'xml';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
break;
}
header('Content-Disposition: attachment; filename="' . $this->getGridFileName() . '"');
header('Content-Transfer-Encoding: binary');
return $this;
}

protected function getRowCount()
{
return count($this->getDataSource());
Expand Down
13 changes: 0 additions & 13 deletions library/Gridola/Export/Csv.php
Expand Up @@ -8,19 +8,6 @@ class Gridola_Export_Csv extends Gridola_Export
{
protected $_exportType = 'csv';

protected function header()
{
header('Content-Description: File Transfer');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header("Content-Type: application/" . $this->getExportType());
header('Content-Disposition: attachment; filename="' . $this->getGridFileName() . '"');
header('Content-Transfer-Encoding: binary');
return $this;
}

/**
* Important note. A column header that start with an upper case ID in column A1
* throws errors when opening in excel. This is a qwirk with Microsoft Excel. The
Expand Down
17 changes: 4 additions & 13 deletions library/Gridola/Export/Xml.php
Expand Up @@ -6,21 +6,12 @@
*/
class Gridola_Export_Xml extends Gridola_Export
{
/**
* SpreadsheetML
* @var string
*/
protected $_exportType = 'xml';

protected function header()
{
header('Content-Description: File Transfer');
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: public');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="' . $this->getGridFileName() . '"');
header('Content-Transfer-Encoding: binary');
return $this;
}

/**
* SpreadsheetML
*
Expand Down

0 comments on commit b4744d8

Please sign in to comment.