cops/resources/epub-loader/CsvExport.class.php

78 lines
1.6 KiB
PHP
Raw Normal View History

2013-09-12 00:51:45 +03:00
<?php
/**
* CsvExport class
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Didier Corbière <didier.corbiere@opale-concept.com>
*/
require_once(realpath(dirname(__FILE__)) . '/BaseExport.class.php');
class CsvExport extends BaseExport
{
private $mLines = null;
const CsvSeparator = "\t";
/**
* Open an export file (or create if file does not exist)
*
* @param string Export file name
* @param boolean Force file creation
*/
public function __construct($inFileName, $inCreate = false)
2013-09-12 00:51:45 +03:00
{
$this->mSearch = array("\r", "\n", self::CsvSeparator);
$this->mReplace = array('', '<br />', '');
// Init container
$this->mLines = array();
parent::__construct($inFileName, $inCreate);
2013-09-12 00:51:45 +03:00
}
/**
* Add the current properties into the export content
* and reset the properties
*/
public function AddContent()
{
$text = '';
foreach ($this->mProperties as $key => $value) {
$info = '';
if (is_array($value)) {
foreach ($value as $value1) {
// Escape quotes
if (strpos($value1, '\'') !== false) {
$value1 = '\'' . str_replace('\'', '\'\'', $value1) . '\'';
}
2013-09-12 00:51:45 +03:00
$text .= $value1 . self::CsvSeparator;
}
continue;
}
else {
// Escape quotes
if (strpos($value, '\'') !== false) {
$value = '\'' . str_replace('\'', '\'\'', $value) . '\'';
}
2013-09-12 00:51:45 +03:00
$info = $value;
}
$text .= $info . self::CsvSeparator;
}
$this->mLines[] = $text;
$this->ClearProperties();
}
protected function GetContent()
{
$text = implode("\n", $this->mLines) . "\n";
return $text;
}
}
?>