/**
 * Prints a table of previously issued certificates--used for reissue.
 *
 * @param int $certificate id
 * @param int $userid
 * @param null
 */
function certificate_print_attempts($certificateid, $userid)
{
    global $OUTPUT, $DB;
    if (!($certificate = $DB->get_record('certificate', array('id' => $certificateid)))) {
        return false;
    }
    $attempts = certificate_get_attempts($certificateid, $userid);
    echo $OUTPUT->heading(get_string('summaryofattempts', 'certificate'));
    // Prepare table header
    $table = new html_table();
    $table->class = 'generaltable';
    $table->head = array(get_string('issued', 'certificate'));
    $table->align = array('left');
    $table->attributes = array("style" => "width:20%; margin:auto");
    $gradecolumn = $certificate->printgrade;
    if ($gradecolumn) {
        $table->head[] = get_string('grade');
        $table->align[] = 'center';
        $table->size[] = '';
    }
    // One row for each attempt
    foreach ($attempts as $attempt) {
        $row = array();
        // prepare strings for time taken and date completed
        $datecompleted = '';
        if ($attempt->certdate > 0) {
            // attempt has finished
            $datecompleted = userdate($attempt->certdate);
        }
        $row[] = $datecompleted;
        if ($gradecolumn) {
            $attemptgrade = $attempt->reportgrade;
            $row[] = $attemptgrade;
        }
        $table->data[$attempt->id] = $row;
    }
    echo html_writer::table($table);
}
 public function test_certificate_get_attempts()
 {
     global $DB;
     $certificate = $this->generator->create_instance(array('course' => $this->course->id));
     $coursemodule = get_coursemodule_from_instance('certificate', $certificate->id);
     $studentroleid = $DB->get_record('role', array('shortname' => 'student'), 'id')->id;
     $teacherroleid = $DB->get_record('role', array('shortname' => 'editingteacher'), 'id')->id;
     // Have a single teacher.
     $teacheruser = $this->getDataGenerator()->create_user(array('email' => "*****@*****.**", 'username' => "dr_money_face"));
     $this->getDataGenerator()->enrol_user($teacheruser->id, $this->course->id, $teacherroleid);
     $studentuser = $this->getDataGenerator()->create_user(array('email' => "*****@*****.**", 'username' => "joke_depletion"));
     $this->getDataGenerator()->enrol_user($studentuser->id, $this->course->id, $studentroleid);
     // Prior to any issue, the certificate_get_attempts should return false.
     $this->setUser($studentuser);
     $this->assertFalse(certificate_get_attempts($certificate->id));
     // Issue a certificate multiple times.
     $certificateissue01 = certificate_get_issue($this->course, $studentuser, $certificate, $coursemodule);
     $certificateissue02 = certificate_get_issue($this->course, $studentuser, $certificate, $coursemodule);
     // Set the current user to student since certificate_get_attempts relies on the
     // global variable $USER.
     $this->setUser($studentuser);
     // This is inconsistent with certificate_get_issue which is the function
     // used to acquire issue for a user. The same function that ensure there is
     // only one certificate issued per user.
     $attempts = certificate_get_attempts($certificate->id);
     $this->assertEquals(1, count($attempts));
     foreach ($attempts as $attempt) {
         $this->assertContains($attempt->id, array($certificateissue01->id, $certificateissue02->id));
     }
 }
Beispiel #3
0
if (empty($action)) {
    // Not displaying PDF
    echo $OUTPUT->header();
    $viewurl = new moodle_url('/mod/certificate/view.php', array('id' => $cm->id));
    groups_print_activity_menu($cm, $viewurl);
    $currentgroup = groups_get_activity_group($cm);
    $groupmode = groups_get_activity_groupmode($cm);
    if (has_capability('mod/certificate:manage', $context)) {
        $numusers = count(certificate_get_issues($certificate->id, 'ci.timecreated ASC', $groupmode, $cm));
        $url = html_writer::tag('a', get_string('viewcertificateviews', 'certificate', $numusers), array('href' => $CFG->wwwroot . '/mod/certificate/report.php?id=' . $cm->id));
        echo html_writer::tag('div', $url, array('class' => 'reportlink'));
    }
    if (!empty($certificate->intro)) {
        echo $OUTPUT->box(format_module_intro('certificate', $certificate, $cm->id), 'generalbox', 'intro');
    }
    if ($attempts = certificate_get_attempts($certificate->id)) {
        echo certificate_print_attempts($course, $certificate, $attempts);
    }
    if ($certificate->delivery == 0) {
        $str = get_string('openwindow', 'certificate');
    } elseif ($certificate->delivery == 1) {
        $str = get_string('opendownload', 'certificate');
    } elseif ($certificate->delivery == 2) {
        $str = get_string('openemail', 'certificate');
    }
    echo html_writer::tag('p', $str, array('style' => 'text-align:center'));
    $linkname = get_string('getcertificate', 'certificate');
    $link = new moodle_url('/mod/certificate/view.php?id=' . $cm->id . '&action=get');
    $button = new single_button($link, $linkname);
    if ($certificate->delivery != 1) {
        $button->add_action(new popup_action('click', $link, 'view' . $cm->id, array('height' => 600, 'width' => 800)));