Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong data for column in exported csv in Reports->Lessons #4975

Conversation

Imran92
Copy link
Contributor

@Imran92 Imran92 commented Apr 1, 2022

Fixes the issue mentioned here #4964 (review)

Changes proposed in this Pull Request

The column data was not sorted according to the column headers. So when 'module' column was added in the headers, the data was not being sorted, so the module column appeared after the title column, but the data for the module column was in the last column in each row. So it resulted in all columns except the title showing wrong data (1 right circular shift except the title). Here we're sorting the data as per column headers to make them appear in the same order.

Testing instructions

  1. Create a few lessons
  2. Export CSV
  3. See if all data appears according to their column name

Screenshot / Video

Before - (Notice that the students column is showing a date, also the rest of the columns)
image

After-
image

@Imran92 Imran92 added this to the 4.3.0 - Reports v2 milestone Apr 1, 2022
@Imran92 Imran92 requested a review from a team April 1, 2022 10:26
@Imran92 Imran92 self-assigned this Apr 1, 2022
Copy link
Member

@merkushin merkushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 All columns and data in their places :) Thanks!

@@ -351,7 +351,7 @@ public function generate_report( $report ) {

// Process each row.
foreach ( $this->items as $item ) {
$data[] = $this->get_row_data( $item );
$data[] = array_replace( $columns, $this->get_row_data( $item ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it doesn't cause any performance issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about this too, but hopefully in this particular case it won't come to that, the loop will be running for number of rows * number of properties time in total, we don't have that many properties (columns) usually, and for the number of rows to become an issue, I think we'll be facing out of memory or something like that before that happens :p So I think compared to the time it takes to fetch the data and prepare a row, the time taken here hopefully won't become too significant

@Imran92 Imran92 merged commit 40a6f42 into feature/reports-refactor Apr 1, 2022
@Imran92 Imran92 deleted the fix/lesson-export-data-does-not-match-column-header branch April 1, 2022 17:33
@m1r0
Copy link
Member

m1r0 commented Apr 1, 2022

I'm not sure how I missed this one. 😄 GJ finding the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants