/** * Creates and returns output to be written to a CSV / etc. file. * * @return string formatted output */ public function getFormattedOutput() { switch ($this->_dataItemType) { case DATA_ITEM_CANDIDATE: $dataItem = new Candidates($this->_siteID); break; default: return false; break; } $this->_rs = $dataItem->getExport($this->_IDs); if (empty($this->_rs)) { return false; } /* Column names. */ $outputString = implode($this->_separator, array_keys($this->_rs[0])) . "\r\n"; foreach ($this->_rs as $rowIndex => $row) { foreach ($row as $key => $value) { /* Escape any double-quotes and place the value inside * double quotes. */ $this->_rs[$rowIndex][$key] = '"' . str_replace('"', '""', $value) . '"'; } $outputString .= implode($this->_separator, $this->_rs[$rowIndex]) . "\r\n"; } return $outputString; }