MCPcopy Create free account
hub / github.com/Rello/analytics / validateFlexibleRecords

Method validateFlexibleRecords

lib/Service/ThresholdService.php:338–374  ·  view source on GitHub ↗

@param list ,insert:bool}> $records */

(int $datasetId, array $records)

Source from the content-addressed store, hash-verified

336
337 /** @param list<array{values:array<string,mixed>,insert:bool}> $records */
338 public function validateFlexibleRecords(int $datasetId, array $records): void {
339 $columns = array_column($this->FlexibleStorageMapper->getColumns($datasetId), null, 'ref');
340 foreach ($this->ReportMapper->reportsForDataset($datasetId) as $report) {
341 $reportId = (int)$report['id'];
342 $thresholds = $this->VariableService->replaceThresholdsVariables(
343 $this->ThresholdMapper->getSevOneThresholdsByReport($reportId)
344 );
345 foreach ($records as $record) {
346 foreach ($thresholds as $threshold) {
347 $reference = $threshold['source_column_ref'] ?? null;
348 if (
349 !is_string($reference)
350 || !array_key_exists($reference, $record['values'])
351 || !isset($columns[$reference])
352 || (($threshold['user_id'] ?? null) !== ($report['user_id'] ?? null))
353 ) {
354 continue;
355 }
356 $compare = $record['values'][$reference];
357 $matched = $threshold['option'] === 'new' && $record['insert'];
358 if (!$matched && $threshold['option'] !== 'new') {
359 $matched = $this->matchesThreshold($compare, $threshold['target'], (string)$threshold['option']);
360 }
361 if (!$matched) {
362 continue;
363 }
364 $this->NotificationManager->triggerNotification(NotificationManager::SUBJECT_THRESHOLD, $reportId, $threshold['id'], [
365 'report' => $report['name'],
366 'subject' => $columns[$reference]['name'],
367 // TRANSLATORS: Noun: a newly added data row; also used as a notification subject.
368 'rule' => $threshold['option'] === 'new' ? $this->l10n->t('new record') : $threshold['option'],
369 'value' => $threshold['option'] === 'new' ? '' : $threshold['target'],
370 ], $threshold['user_id']);
371 }
372 }
373 }
374 }
375
376 private function matchesThreshold(mixed $value, mixed $target, string $option): bool {
377 $option = strtoupper($option);

Callers 2

validateFlexibleMethod · 0.95

Calls 7

matchesThresholdMethod · 0.95
getColumnsMethod · 0.80
triggerNotificationMethod · 0.80
reportsForDatasetMethod · 0.45
tMethod · 0.45

Tested by

no test coverage detected