本文整理汇总了PHP中MoodleExcelWorkbook::send方法的典型用法代码示例。如果您正苦于以下问题:PHP MoodleExcelWorkbook::send方法的具体用法?PHP MoodleExcelWorkbook::send怎么用?PHP MoodleExcelWorkbook::send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MoodleExcelWorkbook
的用法示例。
在下文中一共展示了MoodleExcelWorkbook::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: export
/**
* Export a report in this format
*
* @param string $query Final form of the main report query
* @param string $storage_path Path on the file system to save the output to,
* or NULL if sending to browser
* @param $filename Filename to use when sending to browser
*/
function export($query, $storage_path, $filename)
{
global $CFG;
require_once $CFG->libdir . '/excellib.class.php';
$filename .= '.xls';
/// Creating a workbook
$workbook = new MoodleExcelWorkbook('-');
/// Sending HTTP headers
$workbook->send($filename);
/// Creating the first worksheet
$sheettitle = get_string('studentprogress', 'reportstudentprogress');
$myxls =& $workbook->add_worksheet($sheettitle);
/// Format types
$format =& $workbook->add_format();
$format->set_bold(0);
$formatbc =& $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb =& $workbook->add_format();
$formatb->set_bold(1);
$formaty =& $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc =& $workbook->add_format();
$formatc->set_align('center');
$formatr =& $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg =& $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
$rownum = 0;
$colnum = 0;
foreach ($this->report->headers as $header) {
$myxls->write($rownum, $colnum++, $header, $formatbc);
}
foreach ($this->report->data as $datum) {
if (!is_object($datum)) {
continue;
}
$rownum++;
$colnum = 0;
foreach ($this->headers as $id => $header) {
if (isset($datum->{$id})) {
$myxls->write($rownum, $colnum++, $datum->{$id}, $format);
} else {
$myxls->write($rownum, $colnum++, '', $format);
}
}
}
$workbook->close();
}
示例2: user_download_xls
function user_download_xls($fields)
{
global $CFG, $SESSION, $DB;
require_once "{$CFG->libdir}/excellib.class.php";
require_once $CFG->dirroot . '/user/profile/lib.php';
$filename = clean_filename(get_string('users') . '.xls');
$workbook = new MoodleExcelWorkbook('-');
$workbook->send($filename);
$worksheet = array();
$worksheet[0] =& $workbook->add_worksheet('');
$col = 0;
foreach ($fields as $fieldname) {
$worksheet[0]->write(0, $col, $fieldname);
$col++;
}
$row = 1;
foreach ($SESSION->bulk_users as $userid) {
if (!($user = $DB->get_record('user', array('id' => $userid)))) {
continue;
}
$col = 0;
profile_load_data($user);
foreach ($fields as $field => $unused) {
$worksheet[0]->write($row, $col, $user->{$field});
$col++;
}
$row++;
}
$workbook->close();
die;
}
示例3: init
/**
* Open workbook and send to browser
*
* @param string $name The preferred file name (no extension)
* @return void
*/
public function init($name)
{
$this->name = $name;
$filename = clean_filename($this->name);
$filename = trim($filename, '_');
$this->workbook = $this->new_workbook();
$this->workbook->send("{$filename}." . $this->get_extension());
// Adding the worksheet
$this->writer = $this->workbook->add_worksheet("{$this->name} {$this->worksheet}");
}
示例4: user_download_xls
function user_download_xls($fields) {
global $CFG, $DB;
require_once("$CFG->libdir/excellib.class.php");
$filename = clean_filename(get_string('course', 'local_cobaltcourses') . '.xls');
$workbook = new MoodleExcelWorkbook('-');
$workbook->send($filename);
$worksheet = array();
$worksheet[0] = $workbook->add_worksheet('');
$col = 0;
foreach ($fields as $fieldname) {
$worksheet[0]->write(0, $col, $fieldname);
$col++;
}
$hierarchy = new hierarchy();
$schoollist = $hierarchy->get_assignedschools();
if (is_siteadmin()) {
$schoollist = $hierarchy->get_school_items();
}
$sheetrow = 1;
foreach ($schoollist as $school) {
$courses = $DB->get_records('local_cobaltcourses', array('schoolid' => $school->id));
foreach ($courses as $course) {
$post = new stdclass();
$post->fullname = $course->fullname;
$post->shortname = $course->shortname;
$departmentname = $DB->get_field('local_department', 'fullname', array('id' => $course->departmentid));
$post->courselibraryname = $departmentname;
$schoolname = $DB->get_field('local_school', 'fullname', array('id' => $course->schoolid));
$post->organizationname = $schoolname;
$post->summary = $course->summary;
$post->coursetype = ($course->coursetype == 0) ? 'General' : 'Elective';
$post->credithours = $course->credithours;
$post->coursecost = $course->coursecost;
$col = 0;
foreach ($fields as $fieldname) {
$worksheet[0]->write($sheetrow, $col, $post->$fieldname);
$col++;
}
$sheetrow++;
}
}
$workbook->close();
die;
}
示例5: user_download_xls
function user_download_xls($fields) {
global $CFG, $DB;
require_once("$CFG->libdir/excellib.class.php");
$filename = clean_filename(get_string('department', 'local_departments') . '.xls');
$workbook = new MoodleExcelWorkbook('-');
$workbook->send($filename);
$worksheet = array();
$worksheet[0] = $workbook->add_worksheet('');
$col = 0;
foreach ($fields as $fieldname) {
$worksheet[0]->write(0, $col, $fieldname);
$col++;
}
$hierarchy = new hierarchy();
/* Bug report #260
* Edited by hemalatha c arun <hemalatha@eabyas.in>
* resolved- If loggedin user is admin, downloading all the department
*/
if (is_siteadmin()) {
$sql = "SELECT distinct(s.id),s.* FROM {local_school} s ORDER BY s.sortorder";
$schoollist = $DB->get_records_sql($sql);
} else
$schoollist = $hierarchy->get_assignedschools();
$sheetrow = 1;
foreach ($schoollist as $school) {
$departments = $DB->get_records('local_department', array('schoolid' => $school->id));
foreach ($departments as $department) {
$post = new stdclass();
$post->shortname = $department->shortname;
$post->fullname = $department->fullname;
$schoolname = $DB->get_field('local_school', 'fullname', array('id' => $department->schoolid));
$post->schoolname = $schoolname;
$post->summary = $department->description;
$col = 0;
foreach ($fields as $fieldname) {
$worksheet[0]->write($sheetrow, $col, $post->$fieldname);
$col++;
}
$sheetrow++;
}
}
$workbook->close();
die;
}
示例6: export_report
/** Configurable Reports
* A Moodle block for creating customizable reports
* @package blocks
* @author: Juan leyva <http://www.twitter.com/jleyvadelgado>
* @date: 2009
*/
function export_report($report) {
global $DB, $CFG;
require_once($CFG->dirroot . '/lib/excellib.class.php');
$table = $report->table;
$matrix = array();
$filename = 'report_' . (time()) . '.xls';
if (!empty($table->head)) {
$countcols = count($table->head);
$keys = array_keys($table->head);
$lastkey = end($keys);
foreach ($table->head as $key => $heading) {
$matrix[0][$key] = str_replace("\n", ' ', htmlspecialchars_decode(strip_tags(nl2br($heading))));
}
}
if (!empty($table->data)) {
foreach ($table->data as $rkey => $row) {
foreach ($row as $key => $item) {
$matrix[$rkey + 1][$key] = str_replace("\n", ' ', htmlspecialchars_decode(strip_tags(nl2br($item))));
}
}
}
$downloadfilename = clean_filename($filename);
/// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
/// Sending HTTP headers
$workbook->send($downloadfilename);
/// Adding the worksheet
$myxls = $workbook->add_worksheet($filename);
foreach ($matrix as $ri => $col) {
foreach ($col as $ci => $cv) {
$myxls->write_string($ri, $ci, $cv);
}
}
$workbook->close();
exit;
}
示例7: MoodleExcelWorkbook
function report_download_xls($fields, $data, $reportname = 'reportinxls')
{
$workbook = new MoodleExcelWorkbook('-');
$workbook->send($reportname);
$worksheet = array();
$worksheet[0] = $workbook->add_worksheet('');
$col = 0;
foreach ($fields as $fieldname) {
$worksheet[0]->write(0, $col, $fieldname);
$col++;
}
$row = 1;
foreach ($data as $eachrow) {
$col = 0;
foreach ($eachrow as $key => $value) {
$worksheet[0]->write($row, $col, $value);
$col++;
}
$row++;
}
$workbook->close();
die;
}
示例8: display
//.........这里部分代码省略.........
}
}
if (!$download) {
// Set up the table.
$params = array('offlinequiz' => $offlinequiz, 'noresults' => $noresults, 'pagesize' => $pagesize);
$table = new offlinequiz_results_table('mod-offlinequiz-report-overview-report', $params);
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($CFG->wwwroot . '/mod/offlinequiz/report.php?mode=overview&id=' . $cm->id . '&noresults=' . $noresults . '&pagesize=' . $pagesize);
$table->sortable(true);
$table->no_sorting('checkbox');
if ($withparticipants) {
$table->no_sorting('checked');
}
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_class('picture', 'picture');
$table->column_class($offlinequizconfig->ID_field, 'userkey');
$table->column_class('timestart', 'timestart');
$table->column_class('offlinegroupid', 'offlinegroupid');
$table->column_class('sumgrades', 'sumgrades');
$table->set_attribute('cellpadding', '2');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
} else {
if ($download == 'ODS') {
require_once "{$CFG->libdir}/odslib.class.php";
$filename .= ".ods";
// Creating a workbook.
$workbook = new MoodleODSWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('reportoverview', 'offlinequiz');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers.
$headers = array(get_string($offlinequizconfig->ID_field), get_string('firstname'), get_string('lastname'), get_string('importedon', 'offlinequiz'), get_string('group'), get_string('grade', 'offlinequiz'));
if (!empty($withparticipants)) {
$headers[] = get_string('present', 'offlinequiz');
}
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
示例9: display
//.........这里部分代码省略.........
// Get rid of zero length questions.
unset($questions[$id]);
unset($questionids[$key]);
}
}
}
if ($hasfeedback) {
$tablecolumns[] = 'feedbacktext';
$tableheaders[] = get_string('feedback', 'game');
}
if (!$download) {
// Set up the table.
$table = new flexible_table('mod-game-report-overview-report');
$table->define_columns($tablecolumns);
$table->define_headers($tableheaders);
$table->define_baseurl($CFG->wwwroot . '/mod/game/report.php?mode=overview&id=' . $cm->id . '&noattempts=' . $noattempts . '&detailedmarks=' . $detailedmarks . '&pagesize=' . $pagesize);
$table->sortable(true);
$table->collapsible(true);
$table->column_suppress('picture');
$table->column_suppress('fullname');
$table->column_class('picture', 'picture');
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
} else {
if ($download == 'ODS') {
require_once "{$CFG->libdir}/odslib.class.php";
$filename .= ".ods";
// Creating a workbook.
$workbook = new MoodleODSWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('reportoverview', 'game');
$myxls =& $workbook->add_worksheet($sheettitle);
// Format types.
$format =& $workbook->add_format();
$format->set_bold(0);
$formatbc =& $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb =& $workbook->add_format();
$formatb->set_bold(1);
$formaty =& $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc =& $workbook->add_format();
$formatc->set_align('center');
$formatr =& $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg =& $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers.
$headers = array(get_string('fullname'), get_string('startedon', 'game'), get_string('timecompleted', 'game'), get_string('attemptduration', 'game'));
if ($game->grade) {
$headers[] = get_string('grade', 'game') . '/' . $game->grade;
}
if ($detailedmarks) {
foreach ($questionids as $id) {
$headers[] = '#' . $questions[$id]->number;
}
示例10: facetoface_download_attendance
/**
* Download the list of users attending at least one of the sessions
* for a given facetoface activity
*/
function facetoface_download_attendance($facetofacename, $facetofaceid, $location, $format)
{
global $CFG;
$timenow = time();
$timeformat = str_replace(' ', '_', get_string('strftimedate', 'langconfig'));
$downloadfilename = clean_filename($facetofacename . '_' . userdate($timenow, $timeformat));
$dateformat = 0;
if ('ods' === $format) {
// OpenDocument format (ISO/IEC 26300).
require_once $CFG->dirroot . '/lib/odslib.class.php';
$downloadfilename .= '.ods';
$workbook = new MoodleODSWorkbook('-');
} else {
// Excel format.
require_once $CFG->dirroot . '/lib/excellib.class.php';
$downloadfilename .= '.xls';
$workbook = new MoodleExcelWorkbook('-');
$dateformat =& $workbook->add_format();
$dateformat->set_num_format('d mmm yy');
// TODO: use format specified in language pack.
}
$workbook->send($downloadfilename);
$worksheet =& $workbook->add_worksheet('attendance');
facetoface_write_worksheet_header($worksheet);
facetoface_write_activity_attendance($worksheet, 1, $facetofaceid, $location, '', '', $dateformat);
$workbook->close();
exit;
}
示例11: display
//.........这里部分代码省略.........
$table->column_suppress('picture');
$table->column_suppress('fullname');
foreach ($extrafields as $field) {
$table->column_suppress($field);
}
foreach ($nosort as $field) {
$table->no_sorting($field);
}
$table->no_sorting('start');
$table->no_sorting('finish');
$table->no_sorting('score');
$table->no_sorting('checkbox');
$table->no_sorting('picture');
foreach ($scoes as $sco) {
if ($sco->launch != '') {
$table->no_sorting('scograde' . $sco->id);
}
}
$table->column_class('picture', 'picture');
$table->column_class('fullname', 'bold');
$table->column_class('score', 'bold');
$table->set_attribute('cellspacing', '0');
$table->set_attribute('id', 'attempts');
$table->set_attribute('class', 'generaltable generalbox');
// Start working -- this is necessary as soon as the niceties are over.
$table->setup();
} else {
if ($download == 'ODS') {
require_once "{$CFG->libdir}/odslib.class.php";
$filename .= ".ods";
// Creating a workbook.
$workbook = new \MoodleODSWorkbook("-");
// Sending HTTP headers.
$workbook->send($filename);
// Creating the first worksheet.
$sheettitle = get_string('report', 'scorm');
$myxls = $workbook->add_worksheet($sheettitle);
// Format types.
$format = $workbook->add_format();
$format->set_bold(0);
$formatbc = $workbook->add_format();
$formatbc->set_bold(1);
$formatbc->set_align('center');
$formatb = $workbook->add_format();
$formatb->set_bold(1);
$formaty = $workbook->add_format();
$formaty->set_bg_color('yellow');
$formatc = $workbook->add_format();
$formatc->set_align('center');
$formatr = $workbook->add_format();
$formatr->set_bold(1);
$formatr->set_color('red');
$formatr->set_align('center');
$formatg = $workbook->add_format();
$formatg->set_bold(1);
$formatg->set_color('green');
$formatg->set_align('center');
// Here starts workshhet headers.
$colnum = 0;
foreach ($headers as $item) {
$myxls->write(0, $colnum, $item, $formatbc);
$colnum++;
}
$rownum = 1;
} else {
if ($download == 'Excel') {
示例12: data_export_xls
/**
* @global object
* @param array $export
* @param string $dataname
* @param int $count
* @return string
*/
function data_export_xls($export, $dataname, $count) {
global $CFG;
require_once("$CFG->libdir/excellib.class.php");
$filename = clean_filename("{$dataname}-{$count}_record");
if ($count > 1) {
$filename .= 's';
}
$filename .= clean_filename('-' . gmdate("Ymd_Hi"));
$filename .= '.xls';
$filearg = '-';
$workbook = new MoodleExcelWorkbook($filearg);
$workbook->send($filename);
$worksheet = array();
$worksheet[0] =& $workbook->add_worksheet('');
$rowno = 0;
foreach ($export as $row) {
$colno = 0;
foreach($row as $col) {
$worksheet[0]->write($rowno, $colno, $col);
$colno++;
}
$rowno++;
}
$workbook->close();
return $filename;
}
示例13: print_log_xls
function print_log_xls($course, $user, $date, $order = 'l.time DESC', $modname, $modid, $modaction, $groupid)
{
global $CFG, $DB;
require_once "{$CFG->libdir}/excellib.class.php";
if (!($logs = build_logs_array($course, $user, $date, $order, '', '', $modname, $modid, $modaction, $groupid))) {
return false;
}
$courses = array();
if ($course->id == SITEID) {
$courses[0] = '';
if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
foreach ($ccc as $cc) {
$courses[$cc->id] = $cc->shortname;
}
}
} else {
$courses[$course->id] = $course->shortname;
}
$count = 0;
$ldcache = array();
$tt = getdate(time());
$today = mktime(0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
$strftimedatetime = get_string("strftimedatetime");
$nroPages = ceil(count($logs) / (EXCELROWS - FIRSTUSEDEXCELROW + 1));
$filename = 'logs_' . userdate(time(), get_string('backupnameformat', 'langconfig'), 99, false);
$filename .= '.xls';
$workbook = new MoodleExcelWorkbook('-');
$workbook->send($filename);
$worksheet = array();
$headers = array(get_string('course'), get_string('time'), get_string('ip_address'), get_string('fullnameuser'), get_string('action'), get_string('info'));
// Creating worksheets
for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
$sheettitle = get_string('logs') . ' ' . $wsnumber . '-' . $nroPages;
$worksheet[$wsnumber] =& $workbook->add_worksheet($sheettitle);
$worksheet[$wsnumber]->set_column(1, 1, 30);
$worksheet[$wsnumber]->write_string(0, 0, get_string('savedat') . userdate(time(), $strftimedatetime));
$col = 0;
foreach ($headers as $item) {
$worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW - 1, $col, $item, '');
$col++;
}
}
if (empty($logs['logs'])) {
$workbook->close();
return true;
}
$formatDate =& $workbook->add_format();
$formatDate->set_num_format(get_string('log_excel_date_format'));
$row = FIRSTUSEDEXCELROW;
$wsnumber = 1;
$myxls =& $worksheet[$wsnumber];
foreach ($logs['logs'] as $log) {
if (isset($ldcache[$log->module][$log->action])) {
$ld = $ldcache[$log->module][$log->action];
} else {
$ld = $DB->get_record('log_display', array('module' => $log->module, 'action' => $log->action));
$ldcache[$log->module][$log->action] = $ld;
}
if ($ld && !empty($log->info)) {
// ugly hack to make sure fullname is shown correctly
if ($ld->mtable == 'user' and $ld->field == $DB->sql_concat('firstname', "' '", 'lastname')) {
$log->info = fullname($DB->get_record($ld->mtable, array('id' => $log->info)), true);
} else {
$log->info = $DB->get_field($ld->mtable, $ld->field, array('id' => $log->info));
}
}
// Filter log->info
$log->info = format_string($log->info);
$log->info = strip_tags(urldecode($log->info));
// Some XSS protection
if ($nroPages > 1) {
if ($row > EXCELROWS) {
$wsnumber++;
$myxls =& $worksheet[$wsnumber];
$row = FIRSTUSEDEXCELROW;
}
}
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$myxls->write($row, 0, format_string($courses[$log->course], true, array('context' => $coursecontext)), '');
$myxls->write_date($row, 1, $log->time, $formatDate);
// write_date() does conversion/timezone support. MDL-14934
$myxls->write($row, 2, $log->ip, '');
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$myxls->write($row, 3, $fullname, '');
$myxls->write($row, 4, $log->module . ' ' . $log->action, '');
$myxls->write($row, 5, $log->info, '');
$row++;
}
$workbook->close();
return true;
}
示例14: view_issued_certificates
public function view_issued_certificates(moodle_url $url)
{
global $OUTPUT, $DB, $CFG;
// Declare some variables
$strcertificates = get_string('modulenameplural', 'simplecertificate');
$strcertificate = get_string('modulename', 'simplecertificate');
$strto = html_writer::link($url->out(false, array('orderby' => 'username')), get_string('awardedto', 'simplecertificate'));
$strdate = html_writer::link($url->out(false, array('orderby' => 'issuedate')), get_string('receiveddate', 'simplecertificate'));
$strgrade = get_string('grade', 'simplecertificate');
$strcode = get_string('code', 'simplecertificate');
$strreport = get_string('report', 'simplecertificate');
$groupmode = groups_get_activity_groupmode($this->get_course_module());
$page = $url->get_param('page');
$perpage = $url->get_param('perpage');
$orderby = $url->get_param('orderby');
$usercount = 0;
$users = $this->get_issued_certificate_users($orderby, $groupmode);
if ($users) {
$usercount = count($users);
$users = array_slice($users, intval($page * $perpage), $perpage);
}
if (!$url->get_param('action')) {
echo $OUTPUT->header();
$this->show_tabs($url);
if ($groupmode) {
groups_get_activity_group($this->coursemodule, true);
}
groups_print_activity_menu($this->coursemodule, $url);
if (!$users) {
notify(get_string('nocertificatesissued', 'simplecertificate'));
echo $OUTPUT->footer();
exit;
}
// Create the table for the users
$table = new html_table();
$table->width = "95%";
$table->tablealign = "center";
$table->head = array($strto, $strdate, $strgrade, $strcode);
$table->align = array("left", "left", "center", "center");
foreach ($users as $user) {
$name = $OUTPUT->user_picture($user) . fullname($user);
$date = userdate($user->timecreated) . simplecertificate_print_issue_certificate_file($this->get_issue($user));
$code = $user->code;
$table->data[] = array($name, $date, $this->get_grade($user->id), $code);
}
// Create table to store buttons
$tablebutton = new html_table();
$tablebutton->attributes['class'] = 'downloadreport';
$btndownloadods = $OUTPUT->single_button($url->out_as_local_url(false, array('action' => 'download', 'type' => 'ods')), get_string("downloadods"));
$btndownloadxls = $OUTPUT->single_button($url->out_as_local_url(false, array('action' => 'download', 'type' => 'xls')), get_string("downloadexcel"));
$btndownloadtxt = $OUTPUT->single_button($url->out_as_local_url(false, array('action' => 'download', 'type' => 'txt')), get_string("downloadtext"));
$tablebutton->data[] = array($btndownloadods, $btndownloadxls, $btndownloadtxt);
echo $OUTPUT->paging_bar($usercount, $page, $perpage, $url);
echo '<br />';
echo html_writer::table($table);
echo html_writer::tag('div', html_writer::table($tablebutton), array('style' => 'margin:auto; width:50%'));
} else {
if ($url->get_param('action') == 'download') {
$page = $perpage = 0;
$type = $url->get_param('type');
// Calculate file name
$filename = clean_filename($this->get_instance()->coursename . '-' . strip_tags(format_string($this->get_instance()->name, true)) . '.' . strip_tags(format_string($type, true)));
switch ($type) {
case 'ods':
require_once "{$CFG->libdir}/odslib.class.php";
// Creating a workbook
$workbook = new MoodleODSWorkbook("-");
// Send HTTP headers
$workbook->send(format_text($filename, true));
// Creating the first worksheet
$myxls = $workbook->add_worksheet($strreport);
// Print names of all the fields
$myxls->write_string(0, 0, get_string("fullname"));
$myxls->write_string(0, 1, get_string("idnumber"));
$myxls->write_string(0, 2, get_string("group"));
$myxls->write_string(0, 3, $strdate);
$myxls->write_string(0, 4, $strgrade);
$myxls->write_string(0, 5, $strcode);
// Generate the data for the body of the spreadsheet
$i = 0;
$row = 1;
if ($users) {
foreach ($users as $user) {
$myxls->write_string($row, 0, fullname($user));
$studentid = !empty($user->idnumber) ? $user->idnumber : " ";
$myxls->write_string($row, 1, $studentid);
$ug2 = '';
if ($usergrps = groups_get_all_groups($this->get_course()->id, $user->id)) {
foreach ($usergrps as $ug) {
$ug2 = $ug2 . $ug->name;
}
}
$myxls->write_string($row, 2, $ug2);
$myxls->write_string($row, 3, userdate($user->timecreated));
$myxls->write_string($row, 4, $this->get_grade($user->id));
$myxls->write_string($row, 5, $user->code);
$row++;
}
$pos = 5;
}
//.........这里部分代码省略.........
示例15: MoodleExcelWorkbook
$workbook->close();
exit;
}
// Output the file as a valid Excel spreadsheet if required
if ($type == "xls") {
require_once("$CFG->libdir/excellib.class.php");
/// Calculate file name
$downloadfilename = clean_filename(strip_tags($courseshortname.' '.format_string($survey->name,true))).'.xls';
/// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
/// Sending HTTP headers
$workbook->send($downloadfilename);
/// Creating the first worksheet
$myxls = $workbook->add_worksheet(textlib::substr(strip_tags(format_string($survey->name,true)), 0, 31));
$header = array("surveyid","surveyname","userid","firstname","lastname","email","idnumber","time", "notes");
$col=0;
foreach ($header as $item) {
$myxls->write_string(0,$col++,$item);
}
foreach ($nestedorder as $key => $nestedquestions) {
foreach ($nestedquestions as $key2 => $qid) {
$question = $questions[$qid];
if ($question->type == "0" || $question->type == "1" || $question->type == "3" || $question->type == "-1") {
$myxls->write_string(0,$col++,"$question->text");