Esempio n. 1
0
/**
 * Prints the header in view.  Used to help prevent FPDF header errors.
 *
 * @param stdClass $course
 * @param stdClass $certificate
 * @param stdClass $cm
 * @return null
 */
function view_header($course, $certificate, $cm)
{
    global $CFG, $DB, $PAGE, $OUTPUT;
    $PAGE->set_title(format_string($certificate->name));
    $PAGE->set_heading(format_string($course->fullname));
    echo $OUTPUT->header();
    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
    if (has_capability('mod/certificate:manage', $context)) {
        $numusers = count(certificate_get_issues($certificate->id, 'ci.certdate ASC', '', $cm));
        echo '<div class="reportlink"><a href="report.php?id=' . $cm->id . '">' . get_string('viewcertificateviews', 'certificate', $numusers) . '</a></div>';
    }
    if (!empty($certificate->intro)) {
        echo $OUTPUT->box(format_module_intro('certificate', $certificate, $cm->id), 'generalbox', 'intro');
    }
}
 public function test_certificate_get_issues()
 {
     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);
     $this->setUser($teacheruser);
     $studentuserarray = array();
     for ($i = 0; $i < 10; $i++) {
         $studentuserarray[] = $this->getDataGenerator()->create_user(array('email' => "joeshmoethe{$i}@illuminati.shmoe", 'username' => "joeshmoethe{$i}"));
         // Enrol the user as a student.
         $this->getDataGenerator()->enrol_user(end($studentuserarray)->id, $this->course->id, $studentroleid);
         // Issue a certificate.
         certificate_get_issue($this->course, end($studentuserarray), $certificate, $coursemodule);
     }
     $users = certificate_get_issues($certificate->id, "ci.timecreated ASC", false, $coursemodule);
     foreach ($users as $user) {
         $userfound = false;
         foreach ($studentuserarray as $student) {
             if ($userfound = $student->id == $user->id) {
                 break;
             }
         }
         $this->assertTrue($userfound);
     }
 }
Esempio n. 3
0
    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;
    }
}
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');
Esempio n. 4
0
            $ug2 = '';
            if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
                foreach ($usergrps as $ug) {
                    $ug2 = $ug2 . $ug->name;
                }
            }
            echo $ug2 . "\t";
            echo userdate($user->timecreated) . "\t";
            echo certificate_get_grade($certificate, $course, $user->id) . "\t";
            echo $user->code . "\n";
            $row++;
        }
    }
    exit;
}
$usercount = count(certificate_get_issues($certificate->id, $DB->sql_fullname(), $groupmode, $cm));
// Create the table for the users
$table = new html_table();
$table->width = "95%";
$table->tablealign = "center";
$table->head = array($strto);
$table->align = array('left');
foreach ($extrafields as $field) {
    $table->head[] = get_user_field_name($field);
    $table->align[] = 'left';
}
$table->head = array_merge($table->head, array($strdate, $strgrade, $strcode));
$table->align = array_merge($table->align, array('left', 'center', 'center'));
foreach ($users as $user) {
    $name = $OUTPUT->user_picture($user) . fullname($user);
    $date = userdate($user->timecreated) . certificate_print_user_files($certificate, $user->id, $context->id);
        if ($groupmode = groupmode($course, $cm)) {   // Groups are being used
            $currentgroup = setup_and_print_groups($course, $groupmode, 'report.php?id='.$cm->id);
        } else {
            $currentgroup = 0;
        }

    /// Get all teachers and students
        if ($currentgroup) {
            $users = get_group_users($currentgroup);
        } else {
            $users = get_course_users($course->id);
        }
*/
$sqlsort = "s.studentname ASC";
//or sort by date:
// $sqlsort = "s.certdate ASC";
if (!($users = certificate_get_issues($certificate->id, $USER, $sqlsort))) {
    notice("There are no issued certificates", "../../course/view.php?id={$course->id}");
    die;
}
$table->head = array($strto, $strdate, $strcode);
$table->align = array("LEFT", "LEFT", "LEFT");
foreach ($users as $user) {
    $name = print_user_picture($user->id, $course->id, $user->picture, false, true) . $user->studentname;
    $date = certificate_date_report($user) . certificate_print_user_files($user->id);
    $code = $user->code;
    $table->data[] = array($name, $date, $code);
}
echo "<BR>";
print_table($table);
print_footer($course);
$strreport = get_string('report', 'certificate');
if (!$download) {
    $PAGE->navbar->add($strreport);
    $PAGE->set_title(format_string($certificate->name) . ": {$strreport}");
    $PAGE->set_heading($course->fullname);
    // Check to see if groups are being used in this choice
    if ($groupmode = groups_get_activity_groupmode($cm)) {
        groups_get_activity_group($cm, true);
        groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/certificate/report.php?id=' . $id);
    }
} else {
    $groupmode = groups_get_activity_groupmode($cm);
}
add_to_log($course->id, 'certificate', 'view', "report.php?id={$cm->id}", '$certificate->id', $cm->id);
// Ensure there are issues to display, if not display notice
if (!($users = certificate_get_issues($certificate->id, $DB->sql_fullname(), $groupmode, $cm))) {
    echo $OUTPUT->header();
    notify(get_string('nocertificatesissued', 'certificate'));
    echo $OUTPUT->footer($course);
    exit;
}
if ($download == "ods") {
    require_once "{$CFG->libdir}/odslib.class.php";
    // Calculate file name
    $filename = clean_filename("{$course->shortname} " . strip_tags(format_string($certificate->name, true))) . '.ods';
    // Creating a workbook
    $workbook = new MoodleODSWorkbook("-");
    // Send HTTP headers
    $workbook->send($filename);
    // Creating the first worksheet
    $myxls =& $workbook->add_worksheet($strreport);
Esempio n. 7
0
$strcertificate = get_string('modulename', 'certificate');
$strto = get_string('awardedto', 'certificate');
$strdate = get_string('receiveddate', 'certificate');
$strgrade = get_string('grade', 'certificate');
$strcode = get_string('code', 'certificate');
$strreport = get_string('report', 'certificate');
add_to_log($course->id, 'certificate', 'view', "report.php?id={$cm->id}", '$certificate->id', $cm->id);
/// Check to see if groups are being used
$groupmode = groups_get_activity_groupmode($cm, $course);
if ($groupmode) {
    groups_get_activity_group($cm, true);
}
$sqlsort = 's.studentname ASC';
//or to sort by date:
// $sqlsort = 's.certdate ASC';
if (!($users = certificate_get_issues($certificate->id, $USER, $sqlsort, $groupmode, $cm))) {
    $navigation = build_navigation($strreport, $cm);
    print_header_simple(format_string($certificate->name) . ": {$strreport}", "", $navigation, "", '', true);
    if ($groupmode) {
        groups_print_activity_menu($cm, 'report.php?id=' . $id);
    }
    notify('There are no issued certificates');
    print_footer();
    die;
}
if (!$download) {
    $navigation = build_navigation($strreport, $cm);
    print_header_simple(format_string($certificate->name) . ": {$strreport}", "", $navigation, "", '', true);
    if ($groupmode) {
        groups_print_activity_menu($cm, 'report.php?id=' . $id);
    }