Exemplo n.º 1
0
/**
 * Generates the bulk report pdf's and zip.
 *
 * @return void
 * @uses $CFG, $DB
 */
function report_ncccscensus_process_batch($batch)
{
    global $CFG, $DB;
    require_once $CFG->libdir . '/moodlelib.php';
    // Retrieve first 50 reports to generate at a time and prevent cron job from lasting longer than 5 minutes.
    $proccess = $DB->get_records('report_ncccscensus', array('batchid' => $batch, 'status' => 0), '', '*', 0, 50);
    $files = array();
    $tempdirused = false;
    $dir = make_temp_directory("ncccscensus{$batch}", false);
    foreach ($proccess as $report) {
        // Create form data.
        $formdata = new stdClass();
        $formdata->id = $report->course;
        $formdata->group = 0;
        $formdata->startdate = $report->reportstartdate;
        $formdata->enddate = $report->reportenddate;
        // Save report pdf.
        $date = usergetdate(time(), get_user_timezone());
        $filename = date('MdY_Hi', mktime($date['hours'], $date['minutes'], 0, $date['mon'], $date['mday'], $date['year']));
        $filename = $filename . '-' . $report->course . '.pdf';
        // Get temporary file location.
        $fullfilename = $dir . '/' . $filename;
        if (true === report_ncccscensus_generate_report($formdata, REPORT_NCCCSCENSUS_ACTION_PDF, $fullfilename)) {
            $files[$filename] = $fullfilename;
            $report->filename = $filename;
            $report->fullfilename = $fullfilename;
            // Indicate that there was a pdf generated, if not remove as remove in zip will not be called.
            $tempdirused = true;
            $report->status = 1;
        } else {
            $report->status = 2;
        }
        // Mark report generation as complete.
        $DB->update_record('report_ncccscensus', $report);
    }
    if (!$tempdirused) {
        rmdir($dir);
    }
    report_ncccscensus_generate_bulk_zip($batch);
}
Exemplo n.º 2
0
$PAGE->set_title(get_string('setupquery', 'report_ncccscensus'));
$PAGE->set_heading($SITE->fullname);
$PAGE->set_pagelayout('report');
$PAGE->navbar->add(get_string('reportlink', 'report_ncccscensus'));
$mform = new report_ncccscensus_setup_query_form($PAGE->url, $cid);
if ($mform->is_cancelled()) {
    redirect($CFG->wwwroot . '/course/view.php?id=' . $cid);
    die;
}
$action = optional_param('action', REPORT_NCCCSCENSUS_ACTION_VIEW, PARAM_INT);
if ($action == REPORT_NCCCSCENSUS_ACTION_VIEW) {
    echo $OUTPUT->header();
    echo $OUTPUT->box_start();
}
if ($formdata = $mform->get_data()) {
    if (report_ncccscensus_generate_report($formdata, $action) === false) {
        if ($action !== REPORT_NCCCSCENSUS_ACTION_VIEW) {
            echo $OUTPUT->header();
            echo $OUTPUT->box_start();
            $mform->display();
        }
        echo $OUTPUT->notification(get_string('nodatafound', 'report_ncccscensus'), 'notifysuccess');
        if ($action !== REPORT_NCCCSCENSUS_ACTION_VIEW) {
            echo $OUTPUT->box_end();
            echo $OUTPUT->footer();
        }
    }
} else {
    $mform->display();
}
if ($action == REPORT_NCCCSCENSUS_ACTION_VIEW) {