added feature to update inserted information, fixed bug that was inserting new rows after each refresh of the page and optimized get_customfield_values , it was sending many requests and optimized to 1.

This commit is contained in:
2025-08-21 20:39:31 +04:00
parent 2c514a8ab6
commit 24cda34681
5 changed files with 363 additions and 112 deletions
+21 -11
View File
@@ -1,5 +1,5 @@
<?php
require_once dirname(__DIR__, 2) . '/vendor/autoload.php'; // Torna al livello di public
require_once dirname(__DIR__, 2) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/class/VisualLimsApiClient.class.php';
header('Content-Type: application/json');
@@ -9,20 +9,30 @@ error_reporting(E_ALL);
try {
$api = VisualLimsApiClient::getInstance();
// ID del campo custom passato da GET oppure default
$customFieldId = isset($_GET['field_id']) && is_numeric($_GET['field_id']) ? intval($_GET['field_id']) : 156;
// მივიღოთ მრავლობითი field_ids
$fieldIds = [];
if (isset($_GET['field_ids'])) {
$fieldIds = array_filter(array_map('intval', explode(',', $_GET['field_ids'])));
}
// Endpoint con $expand per ottenere i valori
$endpoint = "CustomField($customFieldId)?\$expand=CustomFieldsValues";
// თუ არ გადმოგვცეს -> ერთი default
if (empty($fieldIds)) {
$fieldIds = [156];
}
// Recupera i dati dal server
$data = $api->get($endpoint);
$results = [];
// Salva la risposta in un file per debug
file_put_contents(__DIR__ . '/customfield_values_response.json', json_encode($data));
foreach ($fieldIds as $customFieldId) {
$endpoint = "CustomField($customFieldId)?\$expand=CustomFieldsValues";
$data = $api->get($endpoint);
// Output JSON al client
echo json_encode($data);
$results[$customFieldId] = $data['CustomFieldsValues'] ?? [];
}
// Debug ფაილი
file_put_contents(__DIR__ . '/customfield_values_response.json', json_encode($results));
echo json_encode($results);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([