Questionnaire: missing date exporting to CSV

Questionnaire: missing date exporting to CSV

by Alfonso Marrodán -
Number of replies: 4
Moodle 1.8.2+ and Questionnaire v2007010801.

When exporting the questionnaire, into the CSV file, not appear the answers of "Date" questions. The rest of the data are present in CSV file.

Also, this date fields are displayed correctly in "View by Response" and "View all Responses".

No errors in httpd's log.

Exporting the questionnaire with responses to other Moodle (1.6.4+) with the same Questionnaire's version (v2007010801), dates are exported correctly to CSV.

Any idea?
Average of ratings: -
In reply to Alfonso Marrodán

Re: Questionnaire: missing date exporting to CSV

by Carlos Chiarella -
Hello,

I had the same problem and this is what I did.
Go to your locallib.php file. Find the line that says:
// --------------------- response_date ---------------------

A few lines below there is a foreach loop:
foreach ($row as $key => $val) {
if (!is_numeric($key)) {
// convert date from yyyy-mm-dd database format to actual QUESTIONNAIREDATEFORMAT
if (preg_match('/\d\d\d\d-\d\d-\d\d/', $val)) {
$dateparts = split('-', $val);
$val = mktime(0, 0, 0, $dateparts[1], $dateparts[2], $dateparts[0]); // Unix timestamp
$val = userdate ( $val, QUESTIONNAIREDATEFORMAT);
$newrow[] = $val; // JR JR 1945-03-14
}
}
}

Change this code for:
foreach ($row as $key => $val) {
if (!is_numeric($key)) {
// convert date from yyyy-mm-dd database format to actual QUESTIONNAIREDATEFORMAT
if (preg_match('/\d\d\d\d-\d\d-\d\d/', $val)) {
$dateparts = split('-', $val);
$val = mktime(0, 0, 0, $dateparts[1], $dateparts[2], $dateparts[0]); // Unix timestamp
$val = userdate ( $val, QUESTIONNAIREDATEFORMAT);
$newrow[] = $val; // JR JR 1945-03-14
} else {
$newrow[] = $val;
}
}
}

I only added an else, as you can see. I hope this helps.

Carlos

In reply to Carlos Chiarella

Re: Questionnaire: missing date exporting to CSV

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Carlos,
Please note that this bug has been corrected in latest version of Questionnaire module. I still need a little time to merge all recent fixes and improvements into 1.7 and 1.8 versions, but note that latest version will work with moodle 1.7 and 1.8.
Joseph
In reply to Carlos Chiarella

Re: Questionnaire: missing date exporting to CSV

by Alfonso Marrodán -
Hello,

Resolved fixed. Great !!

Thank you very much to both.

Alfonso