$out['val'] = $this->rewrite($column, $data);
}
else {
- $out['val'] = $this->formatViewValue($column['key'], $rawValue, $data);
+ $dataType = $this->getSelectExpression($column['key'])['dataType'] ?? NULL;
+ $out['val'] = $this->formatViewValue($column['key'], $rawValue, $data, $dataType);
}
if ($this->hasValue($column['label']) && (!empty($column['forceLabel']) || $this->hasValue($out['val']))) {
$out['label'] = $this->replaceTokens($column['label'], $data, 'view');
foreach ($this->getTokens($tokenExpr) as $token) {
$val = $data[$token] ?? NULL;
if (isset($val) && $format === 'view') {
- $val = $this->formatViewValue($token, $val, $data);
+ $dataType = $this->getSelectExpression($token)['dataType'] ?? NULL;
+ $val = $this->formatViewValue($token, $val, $data, $dataType);
}
if (!(is_null($index))) {
$replacement = is_array($val) ? $val[$index] ?? '' : $val;
* @param string $key
* @param mixed $rawValue
* @param array $data
+ * @param string $dataType
* @return array|string
*/
- protected function formatViewValue($key, $rawValue, $data) {
+ protected function formatViewValue($key, $rawValue, $data, $dataType) {
if (is_array($rawValue)) {
return array_map(function($val) use ($key, $data) {
return $this->formatViewValue($key, $val, $data);
- }, $rawValue);
+ }, $rawValue, $dataType);
}
- $dataType = $this->getSelectExpression($key)['dataType'] ?? NULL;
-
$formatted = $rawValue;
switch ($dataType) {
case 'Date':
case 'Timestamp':
- if (!(isset($this->format) && in_array($this->format, ['csv', 'xlsx', 'ods']))) {
- $formatted = \CRM_Utils_Date::customFormat($rawValue);
- }
+ $formatted = \CRM_Utils_Date::customFormat($rawValue);
}
return $formatted;
\CRM_Utils_System::civiExit();
}
+ /**
+ * Return raw value if it is a single date, otherwise return parent
+ * {@inheritDoc}
+ */
+ protected function formatViewValue($key, $rawValue, $data, $dataType) {
+ if (is_array($rawValue)) {
+ return parent::formatViewValue($key, $rawValue, $data, $dataType);
+ }
+
+ if (($dataType === 'Date' || $dataType === 'Timestamp') && in_array($this->format, ['csv', 'xlsx', 'ods'])) {
+ return $rawValue;
+ }
+ else {
+ return parent::formatViewValue($key, $rawValue, $data, $dataType);
+ }
+ }
+
/**
* Outputs headers and CSV directly to browser for download
* @param array $rows