本文整理汇总了PHP中csv_export_writer::download_file方法的典型用法代码示例。如果您正苦于以下问题:PHP csv_export_writer::download_file方法的具体用法?PHP csv_export_writer::download_file怎么用?PHP csv_export_writer::download_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类csv_export_writer
的用法示例。
在下文中一共展示了csv_export_writer::download_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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->libdir . '/csvlib.class.php';
$table = $report->table;
$matrix = array();
$filename = 'report';
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))));
}
}
}
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
foreach ($matrix as $ri => $col) {
$csvexport->add_data($col);
}
$csvexport->download_file();
exit;
}
示例2: foreach
function report_download_csv($fields, $data, $reportname = 'reportincsv')
{
$filename = clean_filename($reportname);
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
foreach ($data as $eachrow) {
$csvexport->add_data($eachrow);
}
$csvexport->download_file();
}
示例3: user_download_csv
function user_download_csv($fields) {
global $CFG;
require_once($CFG->libdir . '/csvlib.class.php');
$filename = clean_filename('Departments');
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
$userprofiledata = array();
$csvexport->add_data($userprofiledata);
$csvexport->download_file();
die;
}
示例4: user_download_csv
function user_download_csv($fields) {
global $CFG;
require_once($CFG->libdir . '/csvlib.class.php');
$filename = clean_filename(get_string('course', 'local_cobaltcourses'));
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
$userprofiledata = array();
$csvexport->add_data($userprofiledata);
$csvexport->download_file();
die;
}
示例5: user_download_csv
function user_download_csv($fields) {
global $CFG;
require_once($CFG->libdir . '/csvlib.class.php');
$filename = clean_filename('Users sample');
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
$userprofiledata = array('lp_shortname','testuser');
$csvexport->add_data($userprofiledata);
$csvexport->download_file();
die;
}
示例6: print_grades
public function print_grades()
{
global $CFG;
$exporttracking = $this->track_exports();
$course = $this->course;
$strgrades = get_string('grades');
$profilefields = grade_helper::get_user_profile_fields($this->course->id, $this->usercustomfields);
$courseid = $course->id;
$shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$downloadfilename = clean_filename("{$shortname} {$strgrades}");
$csvexport = new csv_export_writer($this->separator);
$csvexport->filename = clean_filename("{$downloadfilename}.csv");
// Print names of all the fields.
$exporttitle = array();
$shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$exporttitle[] = $shortname . "";
$csvexport->add_data($exporttitle);
$exporttitle = array();
$exporttitle[] = "TERM";
$exporttitle[] = "Class Number";
$exporttitle[] = "ID";
$exporttitle[] = "Final Grade";
$exporttitle[] = "" . get_string("firstname");
$exporttitle[] = "" . get_string("lastname");
$exporttitle[] = "" . get_string("idnumber");
$exporttitle[] = "" . get_string("institution");
$exporttitle[] = "" . get_string("department");
$exporttitle[] = "" . get_string("email");
foreach ($this->columns as $gradeitem) {
$exporttitle[] = trim($gradeitem->get_name());
}
$csvexport->add_data($exporttitle);
$sseat = $this->primcomp($courseid);
// Print all the lines of data.
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->allow_user_custom_fields($this->usercustomfields);
$gui->init();
while ($userdata = $gui->next_user()) {
$exportdata = array();
$user = $userdata->user;
if (!isset($sseat[$user->username])) {
continue;
}
foreach ($userdata->grades as $itemid => $grade) {
if ($this->finalitemid == $itemid) {
$finalletter = $this->format_grade($userdata->grades[$itemid]);
if ($this->displaytype == 1) {
$userdata->grades[$itemid]->finalgrade = $finalletter;
}
}
}
$coarr = explode('.', $sseat[$user->username]);
$exportdata[] = $coarr[0];
$exportdata[] = $coarr[1];
$exportdata[] = $user->username;
$exportdata[] = $finalletter;
$exportdata[] = $user->firstname;
$exportdata[] = $user->lastname;
$exportdata[] = $user->idnumber;
$exportdata[] = $user->institution;
$exportdata[] = $user->department;
$exportdata[] = $user->email;
foreach ($userdata->grades as $itemid => $grade) {
$gradestr = $userdata->grades[$itemid]->finalgrade;
$exportdata[] = $gradestr;
}
$csvexport->add_data($exportdata);
}
$gui->close();
$geub->close();
$csvexport->download_file();
exit;
}
示例7: print_log_csv
function print_log_csv($course, $user, $date, $order = 'l.time DESC', $modname, $modid, $modaction, $groupid)
{
global $DB, $CFG;
require_once $CFG->libdir . '/csvlib.class.php';
$csvexporter = new csv_export_writer('tab');
$header = array();
$header[] = get_string('course');
$header[] = get_string('time');
$header[] = get_string('ip_address');
$header[] = get_string('fullnameuser');
$header[] = get_string('action');
$header[] = get_string('info');
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");
$csvexporter->set_filename('logs', '.txt');
$title = array(get_string('savedat') . userdate(time(), $strftimedatetime));
$csvexporter->add_data($title);
$csvexporter->add_data($header);
if (empty($logs['logs'])) {
return true;
}
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 && is_numeric($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
$coursecontext = context_course::instance($course->id);
$firstField = format_string($courses[$log->course], true, array('context' => $coursecontext));
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
$actionurl = $CFG->wwwroot . make_log_url($log->module, $log->url);
$row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module . ' ' . $log->action . ' (' . $actionurl . ')', $log->info);
$csvexporter->add_data($row);
}
$csvexporter->download_file();
return true;
}
示例8: display
//.........这里部分代码省略.........
}
if ($displayoptions['objectivescore']) {
if (isset($objectivescore[$name])) {
$row[] = s($objectivescore[$name]);
} else {
$row[] = $emptycell;
}
}
}
}
// End of interaction data.
} else {
// If we don't have track data, we haven't attempted yet.
$strstatus = get_string('notattempted', 'scorm');
if (!$download) {
$row[] = \html_writer::img($OUTPUT->pix_url('notattempted', 'scorm'), $strstatus, array('title' => $strstatus)) . \html_writer::empty_tag('br') . $strstatus;
} else {
$row[] = $strstatus;
}
// Complete the empty cells.
for ($i = 0; $i < count($columns) - $nbmaincolumns; $i++) {
$row[] = $emptycell;
}
}
}
}
if (!$download) {
$table->add_data($row);
} else {
if ($download == 'Excel' or $download == 'ODS') {
$colnum = 0;
foreach ($row as $item) {
$myxls->write($rownum, $colnum, $item, $format);
$colnum++;
}
$rownum++;
} else {
if ($download == 'CSV') {
$csvexport->add_data($row);
}
}
}
}
if (!$download) {
$table->finish_output();
if ($candelete) {
echo \html_writer::start_tag('table', array('id' => 'commands'));
echo \html_writer::start_tag('tr') . \html_writer::start_tag('td');
echo \html_writer::link('javascript:select_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectall', 'scorm')) . ' / ';
echo \html_writer::link('javascript:deselect_all_in(\'DIV\', null, \'scormtablecontainer\');', get_string('selectnone', 'scorm'));
echo ' ';
echo \html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('deleteselected', 'scorm'), 'class' => 'btn btn-secondary'));
echo \html_writer::end_tag('td') . \html_writer::end_tag('tr') . \html_writer::end_tag('table');
// Close form.
echo \html_writer::end_tag('div');
echo \html_writer::end_tag('form');
}
echo \html_writer::end_div();
if (!empty($attempts)) {
echo \html_writer::start_tag('table', array('class' => 'boxaligncenter')) . \html_writer::start_tag('tr');
echo \html_writer::start_tag('td');
echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'ODS') + $displayoptions), get_string('downloadods'), 'post', ['class' => 'm-t-1']);
echo \html_writer::end_tag('td');
echo \html_writer::start_tag('td');
echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'Excel') + $displayoptions), get_string('downloadexcel'), 'post', ['class' => 'm-t-1']);
echo \html_writer::end_tag('td');
echo \html_writer::start_tag('td');
echo $OUTPUT->single_button(new \moodle_url($PAGE->url, array('download' => 'CSV') + $displayoptions), get_string('downloadtext'), 'post', ['class' => 'm-t-1']);
echo \html_writer::end_tag('td');
echo \html_writer::start_tag('td');
echo \html_writer::end_tag('td');
echo \html_writer::end_tag('tr') . \html_writer::end_tag('table');
}
}
} else {
if ($candelete && !$download) {
echo \html_writer::end_div();
echo \html_writer::end_tag('form');
$table->finish_output();
}
echo \html_writer::end_div();
}
// Show preferences form irrespective of attempts are there to report or not.
if (!$download) {
$mform->set_data(compact('detailedrep', 'pagesize', 'attemptsmode'));
$mform->display();
}
if ($download == 'Excel' or $download == 'ODS') {
$workbook->close();
exit;
} else {
if ($download == 'CSV') {
$csvexport->download_file();
exit;
}
}
} else {
echo $OUTPUT->notification(get_string('noactivity', 'scorm'));
}
}
示例9: __getCourseResourceCommentsExport
public static function __getCourseResourceCommentsExport($userid, $recordrow)
{
global $CFG, $DB;
require_once $CFG->libdir . '/csvlib.class.php';
$fields = array('Course Name' => 'Courses', 'File Name' => 'File Name', 'Comments' => 'Comments');
$filename = time();
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
if ($recordrow != "") {
$fav_comment_sql = 'SELECT urc.id AS commentid, r.name AS resource_name, c.fullname AS course_name, urc.comment
FROM mdl_user_resource_comments urc
JOIN mdl_course_modules cm ON cm.id = urc.coursemoduleid
JOIN mdl_course c ON cm.course = c.id
JOIN mdl_resource r ON cm.instance = r.id
WHERE urc.userid = ' . $userid . " AND TRIM(COALESCE(urc.comment, '')) != '' AND urc.id IN({$recordrow}) ORDER BY urc.id DESC";
} else {
$fav_comment_sql = "SELECT urc.id AS commentid, r.name AS resource_name, c.fullname AS course_name, urc.comment\n\t\t\t\tFROM mdl_user_resource_comments urc\n\t\t\t\t JOIN mdl_course_modules cm ON cm.id = urc.coursemoduleid\n\t\t\t\t JOIN mdl_course c ON cm.course = c.id\n\t\t\t\t JOIN mdl_resource r ON cm.instance = r.id\n\t\t\t\tWHERE urc.userid = '{$userid}' AND TRIM(COALESCE(urc.comment, '')) != '' ORDER BY urc.id DESC";
}
$comments = $DB->get_recordset_sql($fav_comment_sql);
if (!empty($comments)) {
foreach ($comments as $comment) {
$commentsdata['Course Name'] = $comment->course_name;
//$commentsdata['File Name'] = $comment->resource_name;
$resource_name = explode(": ", $comment->resource_name);
if ($resource_name[1] != "") {
$commentsdata['File Name'] = $resource_name[1];
} else {
$commentsdata['File Name'] = $resource_name[0];
}
$commentsdata['Comments'] = $comment->comment;
$csvexport->add_data($commentsdata);
}
}
$csvexport->download_file();
exit;
}
示例10: user_download_csv
function user_download_csv($fields, $extrafields = array())
{
global $CFG, $SESSION, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->libdir . '/csvlib.class.php';
$filename = clean_filename(get_string('users'));
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
$extrafield_sql = '';
foreach ($extrafields as $n => $v) {
$extrafield_sql .= " MAX(IF(muif.shortname = '" . $v->shortname . "', muid.data, NULL)) profile_field_" . $v->shortname . ",";
}
$extrafield_sql = rtrim($extrafield_sql, ",");
$idstoload = $SESSION->bulk_users;
$users = array();
foreach (array_chunk($idstoload, 10000, true) as $user_id) {
$userids = implode(",", $user_id);
$users[] = $DB->get_records_sql("SELECT mu.*,\r\n {$extrafield_sql}\r\n FROM mdl_user AS mu\r\n LEFT JOIN mdl_user_info_data AS muid ON mu.id = muid.userid\r\n LEFT JOIN mdl_user_info_field AS muif ON muif.id = muid.fieldid\r\n WHERE mu.id IN ({$userids}) GROUP BY mu.id");
}
foreach ($users as $userdetails) {
foreach ($userdetails as $user) {
$row = array();
#if (!$user = $DB->get_record('user', array('id'=>$userid))) {
#continue;
#}
#profile_load_data($user);
$userprofiledata = array();
foreach ($fields as $field => $unused) {
// Custom user profile textarea fields come in an array
// The first element is the text and the second is the format.
// We only take the text.
if (is_array($user->{$field})) {
$userprofiledata[] = reset($user->{$field});
} else {
$userprofiledata[] = $user->{$field};
}
}
$csvexport->add_data($userprofiledata);
}
}
$csvexport->download_file();
die;
}
示例11: user_download_csv
function user_download_csv($fields)
{
global $CFG, $SESSION, $DB;
require_once $CFG->dirroot . '/user/profile/lib.php';
require_once $CFG->libdir . '/csvlib.class.php';
$filename = clean_filename(get_string('users'));
$csvexport = new csv_export_writer();
$csvexport->set_filename($filename);
$csvexport->add_data($fields);
foreach ($SESSION->bulk_users as $userid) {
$row = array();
if (!($user = $DB->get_record('user', array('id' => $userid)))) {
continue;
}
profile_load_data($user);
$userprofiledata = array();
foreach ($fields as $field => $unused) {
// Custom user profile textarea fields come in an array
// The first element is the text and the second is the format.
// We only take the text.
if (is_array($user->{$field})) {
$userprofiledata[] = reset($user->{$field});
} else {
$userprofiledata[] = $user->{$field};
}
}
$csvexport->add_data($userprofiledata);
}
$csvexport->download_file();
die;
}
示例12: foreach
$sessions=array();
foreach ($records as $record) {
$fields[$record->sessdates]= $record->sessdates;
$sessions[$record->id]=$record->id;
}
$usersql="SELECT u.id,u.firstname,u.lastname FROM {user} u,{local_user_clclasses} c WHERE u.id=c.userid
AND c.classid={$classid}";
$userlists=$DB->get_records_sql($usersql);
$workbook = new csv_export_writer('');
$filename = clean_filename('userlist');
$workbook->set_filename($filename);
$worksheet = array();
$worksheet[0] = $workbook->add_data($fields);
$sheetrow = 1;
foreach ($userlists as $userlist) {
$post = array();
$post[] = $userlist->firstname.$userlist->lastname;
foreach($sessions as $key=>$v) {
//sessid-userid
$post[]=$key.'-'.$userlist->id;
}
$workbook->add_data($post);
$sheetrow++;
}
$workbook->download_file();
示例13: download_csv
/**
* Trigger a download of a csv export of the search results.
*
* @access public
* @return void
*/
public function download_csv()
{
$csv = new \csv_export_writer();
$csv->set_filename('mediacollection_search');
$csv->add_data(array(get_string('caption', 'mod_mediagallery'), get_string('gallery', 'mod_mediagallery'), get_string('creator', 'mod_mediagallery'), get_string('groups'), get_string('roles')));
foreach ($this->results as $row) {
$csv->add_data(array($row->itemcaption, $row->galleryname, $row->creator, implode(', ', $row->groups), implode(', ', $row->roles)));
}
$csv->download_file();
exit;
}
示例14: download_array
/**
* Creates a file for downloading an array into a deliminated format.
* This function is useful if you are happy with the defaults and all of your
* information is in one array.
*
* @param string $filename The filename of the file being created.
* @param array $records An array of information to be converted.
* @param string $delimiter The name of the delimiter. Supported types(comma, tab, semicolon, colon, cfg)
* @param string $enclosure How speical fields are enclosed.
*/
public static function download_array($filename, array &$records, $delimiter = 'comma', $enclosure = '"')
{
$csvdata = new csv_export_writer($delimiter, $enclosure);
$csvdata->set_filename($filename);
foreach ($records as $row) {
$csvdata->add_data($row);
}
$csvdata->download_file();
}
示例15: print_grades
public function print_grades()
{
global $CFG;
$export_tracking = $this->track_exports();
$strgrades = get_string('grades');
$profilefields = grade_helper::get_user_profile_fields($this->course->id, $this->usercustomfields);
$shortname = format_string($this->course->shortname, true, array('context' => context_course::instance($this->course->id)));
$downloadfilename = clean_filename("{$shortname} {$strgrades}");
$csvexport = new csv_export_writer($this->separator);
$csvexport->set_filename($downloadfilename);
// $profilefields = array('idnumber','firstname');
// Print names of all the fields
// $exporttitle = array();
$exporttitle = array('Client Code', 'Client Name', 'Qualification Code', 'Unit Code', 'Unit Start Date', 'Unit End Date', 'Outcome Code');
// foreach ($profilefields as $field) {
// $exporttitle[] = $field->fullname;
// }
// if (!$this->onlyactive) {
// $exporttitle[] = get_string("suspended");
// }
// Add a feedback column.
// foreach ($this->columns as $grade_item) {
// $exporttitle[] = $this->format_column_name($grade_item);
// if ($this->export_feedback) {
// $exporttitle[] = $this->format_column_name($grade_item, true);
// }
// }
$csvexport->add_data($exporttitle);
// Print all the lines of data.
$geub = new grade_export_update_buffer();
$gui = new graded_users_iterator($this->course, $this->columns, $this->groupid);
$gui->require_active_enrolment($this->onlyactive);
$gui->allow_user_custom_fields($this->usercustomfields);
$gui->init();
while ($userdata = $gui->next_user()) {
$user = $userdata->user;
// foreach ($profilefields as $field) {
// $fieldvalue = grade_helper::get_user_field_value($user, $field);
// $exportdata[] = $fieldvalue;
// }
// if (!$this->onlyactive) {
// $issuspended = ($user->suspendedenrolment) ? get_string('yes') : '';
// $exportdata[] = $issuspended;
// }
// foreach ($userdata->grades as $itemid => $grade) {
// if ($export_tracking) {
// $status = $geub->track($grade);
// }
// $exportdata[] = $this->format_grade($grade);
// if ($this->export_feedback) {
// $exportdata[] = $this->format_feedback($userdata->feedbacks[$itemid]);
// }
// }
foreach ($this->columns as $itemid => $grade_item) {
$exportdata = array();
$gradetxt = $this->format_grade($userdata->grades[$itemid]);
$activity_start_date = $this->get_activity_start_date($this->course, $user, $grade_item);
$grade_modified = $userdata->grades[$itemid]->timemodified;
$client_name = $userdata->user->firstname . ' ' . $userdata->user->lastname;
$client_code = $userdata->user->idnumber;
$unit_code = $grade_item->itemname;
$unit_start = $activity_start_date ? $activity_start_date->format('d/m/Y') : '-';
$unit_end = $grade_modified ? userdate($grade_modified, '%d/%m/%Y') : '-';
$course_code = $this->get_course_short_name($grade_item);
$grade_name = 'grade_name';
if ($grade_item->itemtype == 'category') {
$category_start_date = $this->get_category_start_date($this->course, $user, $grade_item);
$unit_start = $category_start_date ? $category_start_date->format('d/m/Y') : '-';
}
// get the status of this grade, and put it through track to get the status
$g = new grade_export_update_buffer();
$grade_grade = new grade_grade(array('itemid' => $itemid, 'userid' => $user->id));
$status = $g->track($grade_grade);
if ($this->updatedgradesonly && ($status == 'nochange' || $status == 'unknown')) {
// $rowstr .= '<td>'.get_string('unchangedgrade', 'grades').'</td>';
} else {
$exportdata[] = $client_code;
$exportdata[] = $client_name;
$exportdata[] = $course_code;
$exportdata[] = $unit_code;
$exportdata[] = $unit_start;
$exportdata[] = $unit_end;
$exportdata[] = $gradetxt;
$gradeupdated = true;
}
if ($grade_item->itemtype == 'category') {
$csvexport->add_data($exportdata);
}
}
}
$gui->close();
$geub->close();
$csvexport->download_file();
exit;
}