MOODLE - 便携式文档格式

MOODLE - Portable Document Format

正在寻找从 moodle custompage 下载(PDF、CSV)数据。有没有API功能,需要调用custompage下载数据。自定义页面有一个 table 数据:

自定义页面

$table = new html_table();
$table->head = array('course', 'users');
$table->attributes['class'] = 'table';

$sql = "SELECT c.fullname, count(cc.userid) AS 'completed'
        FROM {course_completions} cc JOIN {course} ON c.id = cc.course WHERE cc.timestarted > 0
        GROUP BY c.fullname ";

$mds = $DB->get_records_sql($sql);    
foreach ($mds as $m) {
    $table->data[] = new html_table_row(array(implode(array($m->fullname. $m->lastname)), 
                           $m->completed ));
}                              
echo html_writer::table($table); 

对于基本 PDF

require_once($CFG->libdir . '/pdflib.php');

$doc = new pdf();

$doc->AddPage();

$output = html_writer::table($table);

$doc->writeHTML($output);

$doc->Output('filename.pdf');

此处的 Moodle 源代码中有一个更好的示例 - /lib/tests/other/pdflibtestpage.php

对于 CSV

require_once($CFG->libdir . '/csvlib.class.php');

csv_export_writer::download_array('filename.csv, $mds);

以上两个都应该在将任何内容打印到屏幕之前进行下载。

另外,在您的 SQL 中,您应该使用 GROUP BY c.id,因为课程全名不是唯一的。