edit templtae lingue e colori
This commit is contained in:
@@ -2,25 +2,140 @@
|
||||
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
ini_set('display_errors', '0');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
try {
|
||||
$api = VisualLimsApiClient::getInstance();
|
||||
$rapporto_id = 533329;
|
||||
|
||||
// Costruzione manuale dell'endpoint con espansione annidata
|
||||
$endpoint = "Rapporto($rapporto_id)?\$expand=CampioniDatiRapporto(\$expand=AnalisiDatiRapporto,CustomFieldsDatiRapporto)";
|
||||
// Esempi:
|
||||
// rapporto_by_codice_expand_step.php?codice=2541111&step=base
|
||||
// rapporto_by_codice_expand_step.php?codice=2541111&step=files
|
||||
// rapporto_by_codice_expand_step.php?codice=2541111&step=campioni
|
||||
// rapporto_by_codice_expand_step.php?codice=2541111&step=files_campioni
|
||||
|
||||
// Non passiamo options, già incluso nell'endpoint
|
||||
$data = $api->get($endpoint);
|
||||
$codiceRapporto = trim($_GET['codice'] ?? '');
|
||||
$step = trim($_GET['step'] ?? 'base');
|
||||
|
||||
file_put_contents(__DIR__ . '/rapporto_expanded.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
echo json_encode($data);
|
||||
if ($codiceRapporto === '') {
|
||||
throw new Exception("Parametro codice mancante. Usa ?codice=2541111");
|
||||
}
|
||||
|
||||
$allowedSteps = [
|
||||
'base' => '',
|
||||
'files' => 'RapportiFiles',
|
||||
'allegati' => 'RapportiAllegati',
|
||||
'campioni' => 'CampioniDatiRapporto',
|
||||
'files_campioni' => 'RapportiFiles,CampioniDatiRapporto'
|
||||
];
|
||||
|
||||
if (!array_key_exists($step, $allowedSteps)) {
|
||||
throw new Exception("Step non valido. Usa: " . implode(', ', array_keys($allowedSteps)));
|
||||
}
|
||||
|
||||
// Escape OData per eventuali apostrofi
|
||||
$codiceRapportoSafe = str_replace("'", "''", $codiceRapporto);
|
||||
|
||||
/*
|
||||
* STEP 1 - Trova IdRapporto partendo da CodiceRapporto.
|
||||
* Query leggera, con $select e $top=1.
|
||||
*/
|
||||
$searchParams = [
|
||||
'$filter' => "CodiceRapporto eq '{$codiceRapportoSafe}'",
|
||||
'$select' => 'IdRapporto,CodiceRapporto,Data,Versione,Firmato,DataStampa',
|
||||
'$top' => 1
|
||||
];
|
||||
|
||||
$searchEndpoint = "Rapporto?" . http_build_query($searchParams);
|
||||
|
||||
$searchData = $api->get($searchEndpoint);
|
||||
|
||||
$items = $searchData['value'] ?? [];
|
||||
|
||||
if (!is_array($items) || count($items) === 0) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Nessun rapporto trovato per questo CodiceRapporto.',
|
||||
'codice_rapporto' => $codiceRapporto,
|
||||
'search_endpoint' => $searchEndpoint,
|
||||
'search_data' => $searchData
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$rapportoBase = $items[0];
|
||||
$rapportoId = intval($rapportoBase['IdRapporto'] ?? 0);
|
||||
|
||||
if (!$rapportoId) {
|
||||
throw new Exception("IdRapporto non trovato nella risposta.");
|
||||
}
|
||||
|
||||
/*
|
||||
* STEP 2 - Se step=base, restituisco solo la ricerca base.
|
||||
*/
|
||||
if ($step === 'base') {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'codice_rapporto' => $codiceRapporto,
|
||||
'id_rapporto' => $rapportoId,
|
||||
'step' => $step,
|
||||
'search_endpoint' => $searchEndpoint,
|
||||
'rapporto_base' => $rapportoBase
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* STEP 3 - Espande SOLO il rapporto trovato.
|
||||
*/
|
||||
$expandValue = $allowedSteps[$step];
|
||||
|
||||
$detailParams = [
|
||||
'$expand' => $expandValue
|
||||
];
|
||||
|
||||
$detailEndpoint = "Rapporto({$rapportoId})?" . http_build_query($detailParams);
|
||||
|
||||
file_put_contents(
|
||||
__DIR__ . '/last_rapporto_by_codice_expand_endpoint.txt',
|
||||
'[' . date('Y-m-d H:i:s') . '] SEARCH: ' . $searchEndpoint . PHP_EOL .
|
||||
'[' . date('Y-m-d H:i:s') . '] DETAIL: ' . $detailEndpoint . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
|
||||
$detailData = $api->get($detailEndpoint);
|
||||
|
||||
file_put_contents(
|
||||
__DIR__ . "/rapporto_codice_{$codiceRapportoSafe}_{$step}.json",
|
||||
json_encode([
|
||||
'search' => $searchData,
|
||||
'detail' => $detailData
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
|
||||
);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'codice_rapporto' => $codiceRapporto,
|
||||
'id_rapporto' => $rapportoId,
|
||||
'step' => $step,
|
||||
'search_endpoint' => $searchEndpoint,
|
||||
'detail_endpoint' => $detailEndpoint,
|
||||
'rapporto_base' => $rapportoBase,
|
||||
'data' => $detailData
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
} catch (Exception $e) {
|
||||
file_put_contents(__DIR__ . '/error_log.txt', date('Y-m-d H:i:s') . ' - ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
||||
file_put_contents(
|
||||
__DIR__ . '/error_log.txt',
|
||||
date('Y-m-d H:i:s') . ' - ' . $e->getMessage() . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user