Export: an empty row in a number grid shifts all following cells left

Abierto Apto para principiantes
#3,980 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
php
Área
data

Línea de trabajo

La lógica de exportación está en lib/Service/SubmissionService.php, en el bucle foreach sobre $gridRowsPerQuestionId[$questionId]; la rama de fila vacía actualmente añade una única columna ''. Comprueba cómo se construye $gridColumnsPerQuestionId para ANSWER_GRID_TYPE_NUMBER y haz que una fila vacía añada una celda en blanco por columna. Cambia también la comprobación inner empty() para que una respuesta de 0 se conserve. Está hecho cuando un grid de tipo number con una fila vacía mantiene alineadas las columnas posteriores y una respuesta de 0 se exporta como 0.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Describe the bug

In the CSV/XLSX export of results, a number grid question whose row is left completely empty shifts every following cell on that line to the left: the next rows' values, and the answers to all later questions, end up under the wrong headers.

Steps to reproduce
  1. Create a form with one grid question, cell type Number, rows A1, A2, A3 and columns N0, N1, N2. Add a second question of any type after it.
  2. Submit one response that fills A1 (N0 = 2, N2 = 1) and A3 (N1 = 4), and leaves all of row A2 empty.
  3. Go to Results and export to CSV or XLSX.
Expected behaviour

The 4 appears under "(A3 - N1)", and the second question's answer appears in its own column.

Actual behaviour

The 4 appears under "(A2 - N2)", and every later cell on that line, including the second question's answer, is shifted left by (number of columns − 1) = 2.

Cause

In lib/Service/SubmissionService.php (the export), a grid row with no answer adds one empty cell:

foreach ($gridRowsPerQuestionId[$questionId] as $row) {
    if (empty($answerText[$row])) {
        $columns[] = '';
        continue;
    }

A number grid has one export column per row × column, so for ANSWER_GRID_TYPE_NUMBER an empty row has to add one empty cell per column (count($gridColumnsPerQuestionId[$questionId])). Radio and checkbox grids use one column per row, so they are not affected.

Versions

Seen on Forms 5.4.2; the same code is on main today (checked against v5.4.3 and main).

Related, same block: an answer of 0 exports as an empty cell

For number grids, the inner check if (empty($answerText[$row][$column])) treats an answer of 0 (or "0") as missing, because empty() is true for 0 in PHP, so a cell answered with 0 is exported blank. A check such as !isset($answerText[$row][$column]) || $answerText[$row][$column] === '' keeps the 0. (Found by reading the code, not by running it.)

Lenguaje dominante
JavaScript
Estrellas
385
Forks
133
Merge medio
7 h 54 min
PR fusionados (30 d)
157

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de nextcloud/forms

Todos los issues de nextcloud/forms

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.