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

Aberta Para iniciantes
#3,980 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
php
Domínio
data

Direção de pesquisa

A lógica de exportação está em lib/Service/SubmissionService.php, no laço foreach sobre $gridRowsPerQuestionId[$questionId]; o ramo de linha vazia atualmente acrescenta uma única coluna ''. Verifique como $gridColumnsPerQuestionId é construído para ANSWER_GRID_TYPE_NUMBER e faça com que uma linha vazia acrescente uma célula em branco por coluna. Altere também a verificação inner empty() para que uma resposta 0 seja mantida. Concluído quando uma grid do tipo number com uma linha vazia mantiver as colunas seguintes alinhadas e uma resposta 0 for exportada como 0.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.)

Linguagem predominante
JavaScript
Estrelas
385
Forks
133
Merge médio
7h 54min
PRs com merge (30d)
157

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de nextcloud/forms

Todas as issues de nextcloud/forms

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.