| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 2 | 3 | /** |
| 3 | 4 | * Provides Report Model Class |
| 4 | 5 | */ |
| 5 | 6 | |
| @@ -9,13 +10,34 @@ | ||
| 9 | 10 | |
| 10 | 11 | /** |
| 11 | 12 | * |
| 12 | 13 | */ |
| 13 | -class ReportsModel extends Model { | |
| 14 | +class ReportsModel extends Model | |
| 15 | +{ | |
| 14 | 16 | protected static $table = 'bitforms_reports'; |
| 15 | 17 | |
| 16 | - public function validateReportFields($reportData, $fieldNames) { | |
| 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 | + | |
| 34 | + public function validateReportFields($reportData, $fieldNames) | |
| 35 | + { | |
| 17 | 36 | $reportDetails = []; |
| 37 | + if (!self::isValidatableReport($reportData)) { | |
| 38 | + return $reportDetails; | |
| 39 | + } | |
| 18 | 40 | switch ($reportData->type) { |
| 19 | 41 | case 'table': |
| 20 | 42 | $tableAction = 'table_ac'; |
| 21 | 43 | $reportDetails = !is_string($reportData->details) ? $reportData->details : json_decode($reportData->details); |
| @@ -55,9 +77,10 @@ | ||
| 55 | 77 | } |
| 56 | 78 | return $reportDetails; |
| 57 | 79 | } |
| 58 | 80 | |
| 59 | - public function bulkDelete(array $condition = null, $check_operator = null) { | |
| 81 | + public function bulkDelete(array $condition = null, $check_operator = null) | |
| 82 | + { | |
| 60 | 83 | if ( |
| 61 | 84 | !\is_null($condition) |
| 62 | 85 | && \is_array($condition) |
| 63 | 86 | && array_keys($condition) !== range(0, count($condition) - 1) |
| @@ -81,9 +104,9 @@ | ||
| 81 | 104 | ); |
| 82 | 105 | } |
| 83 | 106 | $result = $this->app_db->query( |
| 84 | 107 | $this->app_db->prepare( |
| 85 | - "DELETE FROM $this->table_name $condition_to_check", | |
| 108 | + "DELETE FROM `{$this->table_name}` $condition_to_check", | |
| 86 | 109 | $all_values |
| 87 | 110 | ) |
| 88 | 111 | ); |
| 89 | 112 | return $this->getResult($result); |