Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lang/en/certificate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

// This file is part of the Certificate module for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down
106 changes: 106 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1519,3 +1519,109 @@ function certificate_scan_image_dir($path) {

return $options;
}



/**
* Creates a spreadsheet in a given format
* @param object $course
* @param object $certificate
* @param object $users
* @param object $context
* @param object $extrauserfields
* @param string $filename
* @param object $workbook
* @param string $strreport
* @param object $ustr
* @param object $cstr
*/
function certificate_report_make_spreadsheet(
$course, $certificate, $users, $context, $extrauserfields, $filename, $workbook, $strreport, $ustr, $cstr) {
// Send HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$myxls = $workbook->add_worksheet($strreport);

$username = array(get_string("lastname"), get_string("firstname"));
$ustr = array_merge($username, array_splice($ustr, 1));
// Print names of all the fields.
$col = 0;
foreach ($ustr as $us) {
$myxls->write_string(0, $col++, $us);
}
$myxls->write_string(0, $col++, get_string("group"));

foreach ($cstr as $cs) {
$myxls->write_string(0, $col++, $cs);
}

// Generate the data for the body of the spreadsheet.
$i = 0;
$row = 1;
if ($users) {
foreach ($users as $user) {
list($udata, $cdata) = certificate_report_get_user_data($course, $certificate, $context, $user, $extrauserfields, true);
$col = 0;
foreach ($udata as $ud) {
$myxls->write_string($row, $col++, $ud);
}
$ug2 = '';
if ($usergrps = groups_get_all_groups($course->id, $user->id)) {
foreach ($usergrps as $ug) {
$ug2 = $ug2 . $ug->name;
}
}
$myxls->write_string($row, $col++, $ug2);
foreach ($cdata as $cd) {
$myxls->write_string($row, $col++, $cd);
}
$row++;
}
$pos = 6;
}
// Close the workbook.
$workbook->close();
}

/**
* Return user data in two different arrays, userinfo and certificate info
* @param object $course
* @param object $certificate
* @param object $context
* @param object $user
* @param object $extrauserfields
* @param boolean $downloading
* @return an array object which contains two arrays
*/
function certificate_report_get_user_data($course, $certificate, $context, $user, $extrauserfields, $downloading = false) {
global $OUTPUT;
if ($downloading) {
$name = array($user->lastname, $user->firstname);
} else {
$name = array($OUTPUT->user_picture($user) . fullname($user));
}
$udata = $name;
$udata[] = (!empty($user->idnumber)) ? $user->idnumber : " ";

// Get extra user settings and add it to the userinfo.
foreach ($extrauserfields as $euf) {
if (!$user->$euf) {
$udata[] = '';
} else {
$udata[] = $user->$euf;
}
}

$cdata = array();
if ($downloading) {
$cdata[] = userdate($user->timecreated);
} else {
$cdata[] = userdate($user->timecreated) . certificate_print_user_files($certificate, $user->id, $context->id);
}
if ($certificate->printgrade) {
$cdata[] = certificate_get_grade($certificate, $course, $user->id);
}
$cdata[] = $user->code;

return array($udata, $cdata);
}
Loading