private function saveClass($id, $type, $isValueStat, $request) { $db = ezcDbInstance::get(); $statData = R3EcoGisStatHelper::getStatTypeData($this->do_id, R3EcoGisStatHelper::getStatTypeCodeById($id)); // Salvo con contesto di partenza più piccolo (comune o provincia) $sc_id = R3EcoGisStatHelper::getContextIdByCode(R3EcoGisStatHelper::getBetterContext($statData['st_code'])); // Salvo con contesto di arrivo più piccolo (edifici, comune o aggregazione) $sc_id_child = R3EcoGisStatHelper::getContextIdByCode(R3EcoGisStatHelper::getBetterChildContext($statData['st_code'])); $sql = "DELETE FROM ecogis.stat_type_class WHERE st_id={$id} AND stc_automatic IS FALSE AND stc_type_absolute IS " . ($type == 'absolute' ? 'TRUE' : 'FALSE'); // Evita di non vedere le statistiche prima del ricalcolo $db->exec($sql); $sql = "INSERT INTO ecogis.stat_type_class (st_id, stc_order, stc_text_1, stc_text_2, stc_color, stc_outline_color, stc_expression, stc_type_absolute, stc_value, sc_id, sc_id_child)\n VALUES (:st_id, :stc_order, :stc_text_1, :stc_text_2, :stc_color, :stc_outline_color, :stc_expression, :stc_type_absolute, :stc_value, :sc_id, :sc_id_child)"; $stmt = $db->prepare($sql); $idList = array(); for ($ii = 0; $ii < count($request['stc_type']); $ii++) { if ((string) $request['stc_order'][$ii] != '' && $request['stc_type'][$ii] == $type) { $idList[] = $ii; } } $seq = 0; foreach ($idList as $key) { if ($request['stc_type'][$key] == 'absolute') { $field = 'sdt_absolute_value'; $prec = 'st_value_1_prec'; } else { if ($request['stc_type'][$key] == 'relative') { $field = 'sdt_relative_value'; $prec = 'st_value_2_prec'; } else { throw new Exception("Invalid kind \"{$request['stc_type'][$key]}\""); } } if ($isValueStat) { if ($seq == 0) { $expr = "[{$field}]<{$request['stc_value'][$key]}"; $text1 = sprintf(R3_STAT_FROM_TEXT_1, R3NumberFormat($request['stc_value'][$key], $statData[$prec], true)); $text2 = sprintf(R3_STAT_FROM_TEXT_2, R3NumberFormat($request['stc_value'][$key], $statData[$prec], true)); } else { if ($seq == count($idList) - 1) { $expr = "[{$field}]>={$request['stc_value'][$key]}"; $text1 = sprintf(R3_STAT_TO_TEXT_1, R3NumberFormat($oldValue, $statData[$prec], true)); $text2 = sprintf(R3_STAT_TO_TEXT_2, R3NumberFormat($oldValue, $statData[$prec], true)); } else { $expr = "[{$field}]>={$oldValue} AND [{$field}]<{$request['stc_value'][$key]}"; $text1 = sprintf(R3_STAT_BETWEEN_TEXT_1, R3NumberFormat($oldValue, $statData[$prec], true), R3NumberFormat($request['stc_value'][$key], $statData[$prec], true)); $text2 = sprintf(R3_STAT_BETWEEN_TEXT_2, R3NumberFormat($oldValue, $statData[$prec], true), R3NumberFormat($request['stc_value'][$key], $statData[$prec], true)); } } $oldValue = $request['stc_value'][$key]; $data = array('st_id' => $id, 'stc_order' => $request['stc_order'][$key], 'stc_text_1' => $text1, 'stc_text_2' => $text2, 'stc_color' => $request['stc_color'][$key], 'stc_outline_color' => $request['stc_outline_color'][$key], 'stc_expression' => empty($request['stc_value'][$key]) ? null : $expr, 'stc_type_absolute' => $request['stc_type'][$key] == 'absolute' ? 't' : 'f', 'stc_value' => empty($request['stc_value'][$key]) ? null : $request['stc_value'][$key], 'sc_id' => $sc_id, 'sc_id_child' => $sc_id_child); } else { $data = array('st_id' => $id, 'stc_order' => $request['stc_order'][$key], 'stc_text_1' => $request['stc_text_1'][$key], 'stc_text_2' => $request['stc_text_2'][$key], 'stc_color' => $request['stc_color'][$key], 'stc_outline_color' => $request['stc_outline_color'][$key], 'stc_expression' => empty($request['stc_expression'][$key]) ? null : $request['stc_expression'][$key], 'stc_type_absolute' => $request['stc_type'][$key] == 'absolute' ? 't' : 'f', 'stc_value' => empty($request['stc_value'][$key]) ? null : $request['stc_value'][$key], 'sc_id' => $sc_id, 'sc_id_child' => $sc_id_child); } $stmt->execute($data); $seq++; } }