Plugin attendance download button

Plugin attendance download button

by Weslley Bezerra -
Number of replies: 0

Hello, I've been having difficulty adjusting an improvement in plugin attendance, in the data export part (/mod/attendance/export.php), there is an 'ok' button that when pressed once, it is no longer possible to do another download unless the user refreshes the page manually.

When calling the attendance_exporttotableed($data, $filename, $formdata->format) function, there is a $workbook->close() method of moodle's MoodleExcelWorkbook() API that doesn't seem to let us add any method after the attendance_exporttotableed() function that does not perform any page update, I bring this issue in a way to try to adjust this issue of this button that after an action will only be available again with a user manual update, below contains the code of the function that is called after the download request from the Excel file:


function attendance_exporttotableed($data, $filename, $format) {

    global $CFG;

    if ($format === 'excel') {

        require_once("$CFG->libdir/excellib.class.php");

        $filename .= ".xls";

        $workbook = new MoodleExcelWorkbook("-");

    } else {

        require_once("$CFG->libdir/odslib.class.php");

        $filename .= ".ods";

        $workbook = new MoodleODSWorkbook("-");

    }

    // Sending HTTP headers.

    $workbook->send($filename);

    // Creating the first worksheet.

    $myxls = $workbook->add_worksheet(get_string('modulenameplural', 'attendance'));

    // Format types.

    $formatbc = $workbook->add_format();

    $formatbc->set_bold(1);


    $myxls->write(0, 0, get_string('course'), $formatbc);

    $myxls->write(0, 1, $data->course);

    $myxls->write(1, 0, get_string('group'), $formatbc);

    $myxls->write(1, 1, $data->group);


    $i = 3;

    $j = 0;

    foreach ($data->tabhead as $cell) {

        // Merge cells if the heading would be empty (remarks column).

        if (empty($cell)) {

            $myxls->merge_cells($i, $j - 1, $i, $j);

        } else {

            $myxls->write($i, $j, $cell, $formatbc);

        }

        $j++;

    }

    $i++;

    $j = 0;

    foreach ($data->table as $row) {

        foreach ($row as $cell) {

            $myxls->write($i, $j++, $cell);

        }

        $i++;

        $j = 0;

    }

   

    $workbook->close();

   exit;

}

Average of ratings: -