* validate notification thresholds per report * * @param int $reportId * @param $dimension1 * @param $dimension2 * @param $value * @param int $insert * @return string * @throws \Exception */
(int $reportId, $dimension1, $dimension2, $value, int $insert = 0)
| 229 | * @throws \Exception |
| 230 | */ |
| 231 | public function validate(int $reportId, $dimension1, $dimension2, $value, int $insert = 0) { |
| 232 | $result = null; |
| 233 | $thresholds = $this->ThresholdMapper->getSevOneThresholdsByReport($reportId); |
| 234 | $thresholds = $this->VariableService->replaceThresholdsVariables($thresholds); |
| 235 | $datasetMetadata = $this->ReportMapper->read($reportId); |
| 236 | |
| 237 | foreach ($thresholds as $threshold) { |
| 238 | if (isset($datasetMetadata['user_id']) && $threshold['user_id'] !== $datasetMetadata['user_id']) { |
| 239 | continue; |
| 240 | } |
| 241 | $dimIndex = intval($threshold['dimension']); |
| 242 | // Calculated columns are evaluated only in the browser-rendered table. |
| 243 | if ($dimIndex >= self::CALCULATED_COLUMN_DIMENSION_OFFSET) { |
| 244 | continue; |
| 245 | } |
| 246 | switch ($dimIndex) { |
| 247 | case 0: |
| 248 | $compare = $dimension1; |
| 249 | $subject = $datasetMetadata['dimension1']; |
| 250 | break; |
| 251 | case 1: |
| 252 | $compare = $dimension2; |
| 253 | $subject = $datasetMetadata['dimension2']; |
| 254 | break; |
| 255 | default: |
| 256 | $compare = $value; |
| 257 | $subject = $datasetMetadata['value']; |
| 258 | } |
| 259 | |
| 260 | if ($threshold['option'] === 'new' && $insert != 0) { |
| 261 | $this->NotificationManager->triggerNotification(NotificationManager::SUBJECT_THRESHOLD, $reportId, $threshold['id'], [ |
| 262 | 'report' => $datasetMetadata['name'], |
| 263 | 'subject' => $subject, |
| 264 | // TRANSLATORS: Noun: a newly added data row; also used as a notification subject. |
| 265 | 'rule' => $this->l10n->t('new record'), |
| 266 | 'value' => '' |
| 267 | ], $threshold['user_id']); |
| 268 | $result = 'Threshold value met'; |
| 269 | } else { |
| 270 | $option = strtoupper($threshold['option']); |
| 271 | |
| 272 | // map legacy symbolic options to the new textual ones |
| 273 | $legacyMap = [ |
| 274 | '=' => 'EQ', |
| 275 | '>' => 'GT', |
| 276 | '<' => 'LT', |
| 277 | '>=' => 'GE', |
| 278 | '<=' => 'LE', |
| 279 | '!=' => 'NE', |
| 280 | ]; |
| 281 | if (isset($legacyMap[$option])) { |
| 282 | $option = $legacyMap[$option]; |
| 283 | } |
| 284 | |
| 285 | switch ($option) { |
| 286 | case 'EQ': |
| 287 | $comparison = $this->compareValues($compare, $threshold['target']) === 0; |
| 288 | break; |