Пример #1
0
    }
    echo html_writer::tag('div', $OUTPUT->render($button), array('style' => 'text-align:center'));
    echo $OUTPUT->footer($course);
    exit;
} else {
    // Output to pdf
    // No debugging here, sorry.
    $CFG->debugdisplay = 0;
    @ini_set('display_errors', '0');
    @ini_set('log_errors', '1');
    $filename = certificate_get_certificate_filename($certificate, $cm, $course) . '.pdf';
    require "{$CFG->dirroot}/mod/certificate/certificate_pdf_renderer.php";
    $cpr = new certificate_pdf_renderer($certificate, $course, $cm);
    $pdf = $cpr->get_pdf();
    // PDF contents are now in $file_contents as a string.
    $filecontents = $pdf->Output('', 'S');
    if ($certificate->savecert == 1) {
        certificate_save_pdf($filecontents, $certrecord->id, $filename, $context->id);
    }
    if ($certificate->delivery == 0) {
        // Open in browser.
        send_file($filecontents, $filename, 0, 0, true, false, 'application/pdf');
    } elseif ($certificate->delivery == 1) {
        // Force download.
        send_file($filecontents, $filename, 0, 0, true, true, 'application/pdf');
    } elseif ($certificate->delivery == 2) {
        certificate_email_student($course, $certificate, $certrecord, $context, $filecontents, $filename);
        // Open in browser after sending email.
        send_file($filecontents, $filename, 0, 0, true, false, 'application/pdf');
    }
}
 public function test_certificate_email_student()
 {
     global $CFG, $USER;
     $certificate = $this->generator->create_instance(array('course' => $this->course->id));
     $coursemodule = get_coursemodule_from_instance('certificate', $certificate->id);
     $certificateissues = certificate_get_issue($this->course, $USER, $certificate, $coursemodule);
     $this->setAdminUser();
     require_once "{$CFG->dirroot}/mod/certificate/certificate_pdf_renderer.php";
     $cpr = new certificate_pdf_renderer($certificate, $this->course, $coursemodule);
     $pdf = $cpr->get_pdf();
     // PDF contents are now in $file_contents as a string.
     $filecontents = $pdf->Output('', 'S');
     $filename = certificate_get_certificate_filename($certificate, $coursemodule, $this->course) . '.pdf';
     $context = context_module::instance($coursemodule->id);
     unset_config('noemailever');
     $sink = $this->redirectEmails();
     certificate_email_student($this->course, $certificate, $certificateissues, $context, $filecontents, $filename);
     $messages = $sink->get_messages();
     $this->assertEquals(1, count($messages));
     $this->assertEquals($USER->email, $messages[0]->to);
 }
Пример #3
0
    $linkname = get_string('getcertificate', 'certificate');
    $link = new moodle_url('/mod/certificate/view.php?id=' . $cm->id . '&action=get');
    $button = new single_button($link, $linkname);
    $button->add_action(new popup_action('click', $link, 'view' . $cm->id, array('height' => 600, 'width' => 800)));
    echo html_writer::tag('div', $OUTPUT->render($button), array('style' => 'text-align:center'));
    echo $OUTPUT->footer($course);
    exit;
} else {
    // Output to pdf
    // Remove full-stop at the end if it exists, to avoid "..pdf" being created and being filtered by clean_filename
    $certname = rtrim($certificate->name, '.');
    $filename = clean_filename("{$certname}.pdf");
    if ($certificate->savecert == 1) {
        // PDF contents are now in $file_contents as a string
        $file_contents = $pdf->Output('', 'S');
        certificate_save_pdf($file_contents, $certrecord->id, $filename, $context->id);
    }
    if ($certificate->delivery == 0) {
        $pdf->Output($filename, 'I');
        // open in browser
    } elseif ($certificate->delivery == 1) {
        $pdf->Output($filename, 'D');
        // force download when create
    } elseif ($certificate->delivery == 2) {
        certificate_email_student($course, $certificate, $certrecord, $context);
        $pdf->Output($filename, 'I');
        // open in browser
        $pdf->Output('', 'S');
        // send
    }
}