Save an UPDATE in a variable

0

I have a question, I would like to save a UPDATE within a variable, for example, this is my code:

    public static function cancelTareasP(Usuario $_Usuario, $proyecto_id) {    

        $conex = $_Usuario->getConexBD();    

        $tareasPend = Tarea::getTareasPendientes($conex);
        $ids = array_column($tareasPend, 'id');    

        foreach ($ids as $id) {
            $conex->query("UPDATE Tareas SET estatus = 'Cancelada' WHERE proyecto_id = '$proyecto_id' AND id = '$id'");
        }

        return regHistorico($conex, 4, 'Tareas', $idTareasModificadas, $proyecto_id);
    }

At the moment of doing the UPDATE the estatus of the tasks is modified, those changes must be registered in a history, my doubt is if you can save that UPDATE as a variable ( $idTareasModificadas ) that is the array of id of the tasks that were modified, in order to make the record.

I hope you have given me to understand.

    
asked by Paloma Alvarado 02.08.2017 в 19:59
source

2 answers

0

If you wish to save the id of the tasks in a history, you should only place the registory function inside the foreach:

public static function cancelTareasP(Usuario $_Usuario, $proyecto_id) {    

    $conex = $_Usuario->getConexBD();    
    $tareasPend = Tarea::getTareasPendientes($conex);
    $ids = array_column($tareasPend, 'id');    

    foreach ($ids as $id) {
        $conex->query("UPDATE Tareas SET estatus = 'Cancelada' WHERE proyecto_id = '$proyecto_id' AND id = '$id'");
        regHistorico($conex, 4, 'Tareas', $id, $proyecto_id);

    }
}
    
answered by 02.08.2017 в 20:26
0

You could improve the getTareasPendientes function to get the pending tasks with the $ proyecto_id; this way you ensure that this function returns the pending tasks of that project or you execute the query there in substitution of the function, since the problem is that you get all the pending tasks, executing the query there you would bring those with status = 'Pending 'and belong to the project_id.

$tareasPend = Tarea::getTareasPendientes($conex, $proyecto_id);
    o
$tareasPend = $conex->query("SELECT id FROM Tareas WHERE estatus = 'Pendiente' AND proyecto_id = '$proyecto_id'");   

foreach ($tareasPend as $id) {
    $conex->query("UPDATE Tareas SET estatus = 'Cancelada' WHERE id = '$id'");
    regHistorico($conex, 4, 'Tareas', $id, $proyecto_id);
}
    
answered by 02.08.2017 в 21:23