function generateExportFileData(&$numColumns, &$numRows) { $separator = $this->csvSeparator; $csvColumns = $this->fieldListCsv ? $this->fieldListCsv : $this->fieldList; $fileData = ''; $columnData = array(); $fieldItems = new DataObjectSet(); if ($this->csvHasHeader) { $fileData .= "\"" . implode("\"{$separator}\"", array_values($csvColumns)) . "\""; $fileData .= "\n"; } if (isset($this->customSourceItems)) { $items = $this->customSourceItems; } else { $dataQuery = $this->getCsvQuery(); $items = $dataQuery->execute(); } // temporary override to adjust TableListField_Item behaviour $this->setFieldFormatting(array()); $this->fieldList = $csvColumns; if ($items) { foreach ($items as $item) { if (is_array($item)) { $className = isset($item['RecordClassName']) ? $item['RecordClassName'] : $item['ClassName']; $item = new $className($item); } $fieldItem = new TableListField_Item($item, $this); $fields = $fieldItem->Fields(); $columnData = array(); if ($fields) { foreach ($fields as $field) { $value = $field->Value; // TODO This should be replaced with casting if (array_key_exists($field->Name, $this->csvFieldFormatting)) { $format = str_replace('$value', "__VAL__", $this->csvFieldFormatting[$field->Name]); $format = preg_replace('/\\$([A-Za-z0-9-_]+)/', '$item->$1', $format); $format = str_replace('__VAL__', '$value', $format); eval('$value = "' . $format . '";'); } $value = str_replace(array("\r", "\n"), "\n", $value); $tmpColumnData = "\"" . str_replace("\"", "\"\"", $value) . "\""; $columnData[] = $tmpColumnData; } } $fileData .= implode($separator, $columnData); $fileData .= "\n"; $item->destroy(); unset($item); unset($fieldItem); } $numColumns = count($columnData); $numRows = $fieldItems->count(); return $fileData; } else { return null; } }