public function test_certificate_print_teacher_names()
 {
     global $DB;
     $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' => "sendmemoneyforgrades@bobineuniversity.ca", 'username' => "dr_money_face"));
     $this->getDataGenerator()->enrol_user($teacheruser->id, $this->course->id, $teacherroleid);
     // Have a single student.
     $studentuser = $this->getDataGenerator()->create_user(array('email' => "coolbeans@Iranoutofjokereference.ca", 'username' => "joke_depletion"));
     $this->getDataGenerator()->enrol_user($studentuser->id, $this->course->id, $studentroleid);
     $certificate = $this->generator->create_instance(array('course' => $this->course->id, 'printteacher' => 1));
     $this->setUser($studentuser);
     // For certificateissues specific test @see locallib_test.php, we will only test for existence.
     $coursemodule = get_coursemodule_from_instance('certificate', $certificate->id);
     $certificateissues = certificate_get_issue($this->course, $studentuser, $certificate, $coursemodule);
     $this->assertNotEmpty($coursemodule);
     $this->assertNotEmpty($certificateissues);
     $certificaterenderer = new certificate_pdf_renderer($certificate, $this->course, $coursemodule, $certificateissues);
     $this->assertNotEmpty($certificaterenderer);
 }
 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' => "sendmemoneyforgrades@bobineuniversity.ca", 'username' => "dr_money_face"));
     $this->getDataGenerator()->enrol_user($teacheruser->id, $this->course->id, $teacherroleid);
     $studentuser = $this->getDataGenerator()->create_user(array('email' => "coolbeans@Iranoutofjokereference.ca", '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));
     }
 }
Esempio n. 3
0
    $editvalue = $PAGE->user_is_editing() ? 'off' : 'on';
    $strsubmit = $PAGE->user_is_editing() ? get_string('blockseditoff') : get_string('blocksediton');
    $url = new moodle_url($CFG->wwwroot . '/mod/certificate/view.php', array('id' => $cm->id, 'edit' => $editvalue));
    $PAGE->set_button($OUTPUT->single_button($url, $strsubmit));
}
// Check if the user can view the certificate
if ($certificate->requiredtime && !has_capability('mod/certificate:manage', $context)) {
    if (certificate_get_course_time($course->id) < $certificate->requiredtime * 60) {
        $a = new stdClass();
        $a->requiredtime = $certificate->requiredtime;
        notice(get_string('requiredtimenotmet', 'certificate', $a), "{$CFG->wwwroot}/course/view.php?id={$course->id}");
        die;
    }
}
// Create new certificate record, or return existing record
$certrecord = certificate_get_issue($course, $USER, $certificate, $cm);
make_cache_directory('tcpdf');
// Load the specific certificate type.
require "{$CFG->dirroot}/mod/certificate/type/{$certificate->certificatetype}/certificate.php";
if (empty($action)) {
    // Not displaying PDF
    echo $OUTPUT->header();
    /// find out current groups mode
    groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/certificate/view.php?id=' . $cm->id);
    $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'));
    }
function certificate_email_students($USER)
{
    global $course, $certificate, $CFG;
    $certrecord = certificate_get_issue($course, $USER);
    if ($certrecord->sent > 0) {
        return;
    }
    $teacher = get_teacher($course->id);
    $strawarded = get_string('awarded', 'certificate');
    $stremailstudenttext = get_string('emailstudenttext', 'certificate');
    $info->username = fullname($user);
    $info->certificate = format_string($certificate->name, true);
    $info->course = format_string($course->fullname, true);
    $from = fullname($teacher);
    $subject = $info->course . ': ' . $info->certificate;
    $message = get_string('emailstudenttext', 'certificate', $info) . "\n";
    // Make the HTML version more XHTML happy  (&amp;)
    $messagehtml = text_to_html(get_string('emailstudenttext', 'certificate', $info));
    $user->mailformat = 0;
    // Always send HTML version as well
    $attachment = $course->id . '/moddata/certificate/' . $certificate->id . '/' . $USER->id . '/certificate.pdf';
    $attachname = "certificate.pdf";
    set_field("certificate_issues", "sent", "1", "certificateid", $certificate->id, "userid", $USER->id);
    return email_to_user($USER, $from, $subject, $message, $messagehtml, $attachment, $attachname);
}
 /**
  * @param object $certificate
  * @param $course
  * @param $coursemodule
  * @param object $certificateissues
  */
 public function __construct($certificate, $course, $coursemodule, $certificateissues = null)
 {
     // See if certificate issues exist.
     if (empty($certificateissues)) {
         global $USER;
         $certificateissues = certificate_get_issue($course, $USER, $certificate, $coursemodule);
     }
     parent::__construct($certificate, $course, $certificateissues, $coursemodule);
 }
Esempio n. 6
0
 public function test_certificate_get_participants()
 {
     // This should create certificate db entry as well as course module entry.
     $certificate = $this->generator->create_instance(array('course' => $this->course->id));
     $coursemodule = get_coursemodule_from_instance('certificate', $certificate->id);
     $userarray = array();
     for ($i = 0; $i < 10; $i++) {
         $userarray[] = $this->getDataGenerator()->create_user();
         $this->assertNotEmpty(certificate_get_issue($this->course, end($userarray), $certificate, $coursemodule));
     }
     $expecteduserids = array();
     foreach ($userarray as $user) {
         $expecteduserids[] = $user->id;
     }
     $participantobject = certificate_get_participants($certificate->id);
     $realuserids = array();
     foreach ($participantobject as $key => $user) {
         $realuserids[] = $user->id;
     }
     foreach ($expecteduserids as $uid) {
         $this->assertContains($uid, $realuserids);
     }
     foreach ($realuserids as $uid) {
         $this->assertContains($uid, $expecteduserids);
     }
 }