stop-update-with-on_update

QuestionsCategory: Questionsstop-update-with-on_update
Samuel Gil asked 2 months ago

Hello, I have this code that’s supposed to stop the update of fields in the grid,
but when I try to update,
I get an error saying the field doesn’t exist,
and I get the feeling that the update isn’t stopping. Is there something wrong with my code?

function actualizarPorTabla($data, $cols, $g)
{
//Here would be my connection to the database with PDO
// Configuración de conexión PDO manual
$pdo = new PDO("");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Para manejar errores con excepciones
//print_r($cols);
//print_r($data);
foreach ($cols as $col)
{
$campo = $col["name"];
$tabla = $col["table"];

// Imprimir todo $data y $cols para ver qué datos están disponibles
/*
echo "Datos recibidos en \\$data: ";
print_r($data["params"]["QUALITY_1"]);
echo "

";
*/

// Verifica si el campo está en los datos a actualizar y no es un campo de identidad

if (isset($data["params"][$campo]) && !in_array($campo, ["ID_SEGUIMIENTO", "ID_APROBACION"]))
{
//echo $tabla;
if ($tabla == "PLM_SEGUIMIENTO")
{
// Actualizar en PLM_SEGUIMIENTO
echo "Actualiza seguimiento";
$querySeguimiento = "UPDATE PLM_SEGUIMIENTO SET $campo = :valor WHERE ID_SEGUIMIENTO = :ID_SEGUIMIENTO";
$paramsSeguimiento = [
":valor" => $data[$campo],
":ID_SEGUIMIENTO" => $data["ID_SEGUIMIENTO"] ];
$stmt = $pdo->prepare($querySeguimiento);
$stmt->execute($paramsSeguimiento);
}
elseif ($tabla == "PLM_APROBACIONES")
{
echo "Actualiza aprobaciones";
//echo $data["params"][$campo];
// Actualizar en PLM_APROBACIONES
$queryAprobaciones = "UPDATE PLM_APROBACIONES SET $campo = :valor WHERE ID_APROBACION = :ID_APROBACION";
$paramsAprobaciones = [
":valor" => $data["params"][$campo],
":ID_APROBACION" => $data["ID_APROBACION"]
];
$stmt = $pdo->prepare($queryAprobaciones);
$stmt->execute($paramsAprobaciones);
}
}
}
}

$e["on_update"] = array(function($data) use ($cols, $g)
{
// Llamamos a la función para realizar las actualizaciones según la tabla
actualizarPorTabla($data, $cols, $g);
},
null,
true);
$g->set_events($e);

1 Answers
Abu Ghufran Staff answered 2 months ago

Hello,

I don’t understand much about your custom logic, however you can debug the callback function by placing following at various places inside your function and check if the data is passed correctly and the conditions are written correct.

phpgrid_error($data);

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

14 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?