I'm working with someone else's code, it's a mix of structured programming, POO, MVC.
Inside a file task_model.php I have two methods, the first getTareasPendientes
applies filters and makes the query with the database to throw the array of the The employee's pending tasks as shown in the following image:
The second method cancelTareasP
(in which I am working), will cancel the pending tasks of a specific project and record the changes in a history.
What I want is to get only the id
of the pending tasks in the getTareasPendientes
method and use it in the cancelTareasP
method, since to register the changes in the history I must make the query and Update
of each task separately.
I hope I have managed to explain and even though I can not put the whole code to be understood.
task_model.php
<?php
/**
* Devuelve arreglo de tareas PENDIENTES asociadas al Empleado.
* @param SafeMySQL $db Conex. a BD
* @param integer $idEmp ID del Empleado (opcional)
* @param array $aFiltro Arreglo para aplicar filtros personalizados a la consulta:
* ftroLimit: valore entero como limite para reg a devolver
* proyecto_id: ID de proyecto
* @return array [description]
*/
public static function getTareasPendientes(SafeMySQL $db, $idEmp = 0, $aFiltro=array()){
$ftroLimit = $proyecto_id = '';
if(!empty($aFiltro) && is_array($aFiltro)){//condiciones esperadas
if(isset($aFiltro['ftroLimit']) && $aFiltro['ftroLimit'] > 0){//se envia un valor entero como limite
$ftroLimit = ' LIMIT '.$aFiltro['ftroLimit'];
}
if(isset($aFiltro['proyecto_id'])) $proyecto_id = $aFiltro['proyecto_id'];//se espera ID de proyecto
}
$sql = "SELECT t1.id, t1.solicitud, t2.responsable FROM Tareas t1
INNER JOIN tareas_emp t2 ON t1.id = t2.tareas_id
LEFT JOIN Proyectos t3 ON t1.proyecto_id = t3.id
WHERE t1.estatus = 'Pendiente' ";
if($idEmp > 0){
$sql.= "AND t2.empleado_id = $idEmp ";
}
if($proyecto_id > 0){
$sql.= "AND t3.id = $proyecto_id ";
}
$sql.= $ftroLimit;
$data = $db->getAll($sql);
return $data;
}
public static function cancelTareasP(Usuario $_Usuario, $proyecto_id) {
$conex = $_Usuario->getConexBD();
if ($_Usuario instanceof Usuario) {
$tipoUsuario = $_Usuario->getTipo();
$nivelAcceso = $_Usuario->getPerfil()->get_nivelacc();
}
$tareasPend = extract(Tarea::getTareasPendientes($conex));
$i = 0;
while ($i <= $tareasPend) {
return $conex->query("UPDATE Tareas SET estatus = 'Cancelada' WHERE proyecto_id = '$proyecto_id' AND id = '$tareasPend'");
$i++;
}
return regHistorico($conex, 4, 'Tareas', $tareasPend, $proyecto_id);
}
?>