* replace variables in filters and apply format * * @param $reportMetadata * @return array */
($reportMetadata)
| 157 | * @return array |
| 158 | */ |
| 159 | public function replaceFilterVariables($reportMetadata) { |
| 160 | if ($reportMetadata['filteroptions'] !== null) { |
| 161 | $filteroptions = json_decode($reportMetadata['filteroptions'], true); |
| 162 | if (isset($filteroptions['filter'])) { |
| 163 | foreach ($filteroptions['filter'] as $key => $value) { |
| 164 | |
| 165 | // get the parsed filter |
| 166 | $parsed = $this->parseFilter($value['value']); |
| 167 | if (!$parsed) continue; |
| 168 | |
| 169 | // $parsed['option'] is coming from the parser and returns always GT - or BETWEEN for quarters |
| 170 | // GT is best fit for most filters as most text variables return ranges |
| 171 | // if a user specifically chooses LT, it should be kept on purpose e.g. for deletion filters |
| 172 | if ($parsed['option'] === 'BETWEEN' || $filteroptions['filter'][$key]['option'] !== 'LT') { |
| 173 | $filteroptions['filter'][$key]['option'] = $parsed['option']; |
| 174 | } |
| 175 | |
| 176 | // if a parser is selected in the chart options, it should also be valid here automatically |
| 177 | if (isset($reportMetadata['chartoptions'])) { |
| 178 | $chartOptions = json_decode($reportMetadata['chartoptions'], true); |
| 179 | if (isset($chartOptions['scales']['xAxes']['time']['parser'])) { |
| 180 | $format = $chartOptions['scales']['xAxes']['time']['parser']; |
| 181 | } |
| 182 | } |
| 183 | $format = $this->parseFormat($value['value']); |
| 184 | |
| 185 | // translate commonly known X timestamp format to U for php |
| 186 | if ($format === 'X') $format = 'U'; |
| 187 | |
| 188 | if (is_array($parsed['value'])) { |
| 189 | // Format both start and end values for BETWEEN |
| 190 | $filteroptions['filter'][$key]['value'] = [ |
| 191 | date($format, $parsed['value'][0]), |
| 192 | date($format, $parsed['value'][1]) |
| 193 | ]; |
| 194 | } else { |
| 195 | $filteroptions['filter'][$key]['value'] = date($format, $parsed['value']); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | $reportMetadata['filteroptions'] = json_encode($filteroptions); |
| 200 | } |
| 201 | return $reportMetadata; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * parsing of %*% variables |