* replace %*% text variables in name and subheader * * @param array $datasetMetadata * @return array */
($datasetMetadata)
| 53 | * @return array |
| 54 | */ |
| 55 | public function replaceTextVariables($datasetMetadata) { |
| 56 | $fields = ['name', 'subheader']; |
| 57 | foreach ($fields as $field) { |
| 58 | isset($datasetMetadata[$field]) ? $name = $datasetMetadata[$field] : $name = ''; |
| 59 | |
| 60 | preg_match_all("/%.*?%/", $name, $matches); |
| 61 | if (count($matches[0]) > 0) { |
| 62 | foreach ($matches[0] as $match) { |
| 63 | $replace = null; |
| 64 | if ($match === '%currentDate%') { |
| 65 | $replace = $this->IDateTimeFormatter->formatDate(time(), 'short'); |
| 66 | } elseif ($match === '%currentTime%') { |
| 67 | $replace = $this->IDateTimeFormatter->formatTime(time(), 'short'); |
| 68 | } elseif ($match === '%now%') { |
| 69 | $replace = time(); |
| 70 | } elseif ($match === '%lastUpdateDate%') { |
| 71 | $timestamp = $this->DatasetMapper->getLastUpdate($datasetMetadata['dataset']); |
| 72 | $replace = $this->IDateTimeFormatter->formatDate($timestamp, 'short'); |
| 73 | } elseif ($match === '%lastUpdateTime%') { |
| 74 | $timestamp = $this->DatasetMapper->getLastUpdate($datasetMetadata['dataset']); |
| 75 | $replace = $this->IDateTimeFormatter->formatTime($timestamp, 'short'); |
| 76 | } elseif ($match === '%owner%') { |
| 77 | $owner = $this->DatasetMapper->getOwner($datasetMetadata['dataset']); |
| 78 | $replace = $owner; |
| 79 | } |
| 80 | if ($replace !== null) { |
| 81 | $datasetMetadata[$field] = preg_replace('/' . $match . '/', $replace, $datasetMetadata[$field]); |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | return $datasetMetadata; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * replace variables in single field or dimension |