| @@ -14,11 +14,30 @@ | ||
| 14 | 14 | class ReportsModel extends Model |
| 15 | 15 | { |
| 16 | 16 | protected static $table = 'bitforms_reports'; |
| 17 | 17 | |
| 18 | + /** | |
| 19 | + * Whether a report payload carries enough to validate. | |
| 20 | + * | |
| 21 | + * The save path feeds this the request's `currentReport`, and the React `$reportSelector` atom | |
| 22 | + * yields `{}` whenever the report list has not resolved — an empty stdClass, which PHP's | |
| 23 | + * empty() reports as non-empty. Callers must therefore ask before acting on it. | |
| 24 | + * | |
| 25 | + * @param mixed $reportData | |
| 26 | + * | |
| 27 | + * @return bool | |
| 28 | + */ | |
| 29 | + public static function isValidatableReport($reportData) | |
| 30 | + { | |
| 31 | + return \is_object($reportData) && !empty($reportData->type) && isset($reportData->details); | |
| 32 | + } | |
| 33 | + | |
| 18 | 34 | public function validateReportFields($reportData, $fieldNames) |
| 19 | 35 | { |
| 20 | 36 | $reportDetails = []; |
| 37 | + if (!self::isValidatableReport($reportData)) { | |
| 38 | + return $reportDetails; | |
| 39 | + } | |
| 21 | 40 | switch ($reportData->type) { |
| 22 | 41 | case 'table': |
| 23 | 42 | $tableAction = 'table_ac'; |
| 24 | 43 | $reportDetails = !is_string($reportData->details) ? $reportData->details : json_decode($reportData->details); |