当前位置: 首页>>代码示例>>PHP>>正文


PHP csv_export_writer::set_filename方法代码示例

本文整理汇总了PHP中csv_export_writer::set_filename方法的典型用法代码示例。如果您正苦于以下问题:PHP csv_export_writer::set_filename方法的具体用法?PHP csv_export_writer::set_filename怎么用?PHP csv_export_writer::set_filename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在csv_export_writer的用法示例。


在下文中一共展示了csv_export_writer::set_filename方法的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;
}
开发者ID:adonm,项目名称:learning,代码行数:36,代码来源:export.php

示例2: 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);
     // Print names of all the fields
     $exporttitle = array();
     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()) {
         $exportdata = array();
         $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]);
             }
         }
         $csvexport->add_data($exportdata);
     }
     $gui->close();
     $geub->close();
     $csvexport->download_file();
     exit;
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:59,代码来源:grade_export_txt.php

示例3: 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();
 }
开发者ID:kmahesh541,项目名称:mitclone,代码行数:11,代码来源:export_reports.php

示例4: test_csv_functions

    public function test_csv_functions() {
        $csvexport = new csv_export_writer();
        $csvexport->set_filename('unittest');
        foreach ($this->testdata as $data) {
            $csvexport->add_data($data);
        }
        $csvoutput = $csvexport->print_csv_data(true);
        $this->assertEquals($csvoutput, $this->teststring);

        $test_data = csv_export_writer::print_array($this->testdata, 'comma', '"', true);
        $this->assertEquals($test_data, $this->teststring);
    }
开发者ID:nigeli,项目名称:moodle,代码行数:12,代码来源:csvclass_test.php

示例5: 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;
}
开发者ID:anilch,项目名称:Personel,代码行数:12,代码来源:sample.php

示例6: 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;
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:12,代码来源:sample.php

示例7: 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;
}
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:12,代码来源:sample.php

示例8: test_csv_functions

    public function test_csv_functions() {
        $csvexport = new csv_export_writer();
        $csvexport->set_filename('unittest');
        foreach ($this->testdata as $data) {
            $csvexport->add_data($data);
        }
        $csvoutput = $csvexport->print_csv_data(true);
        $this->assertEquals($csvoutput, $this->teststring);

        $test_data = csv_export_writer::print_array($this->testdata, 'comma', '"', true);
        $this->assertEquals($test_data, $this->teststring);

        // Testing that the content is imported correctly.
        $iid = csv_import_reader::get_new_iid('lib');
        $csvimport = new csv_import_reader($iid, 'lib');
        $contentcount = $csvimport->load_csv_content($this->teststring, 'utf-8', 'comma');
        $csvimport->init();
        $dataset = array();
        $dataset[] = $csvimport->get_columns();
        while ($record = $csvimport->next()) {
            $dataset[] = $record;
        }
        $csvimport->cleanup();
        $csvimport->close();
        $this->assertEquals($dataset, $this->testdata);

        // Testing for the wrong count of columns.
        $errortext = get_string('csvweirdcolumns', 'error');
        $iid = csv_import_reader::get_new_iid('lib');
        $csvimport = new csv_import_reader($iid, 'lib');
        $contentcount = $csvimport->load_csv_content($this->teststring2, 'utf-8', 'comma');
        $importerror = $csvimport->get_error();
        $csvimport->cleanup();
        $csvimport->close();
        $this->assertEquals($importerror, $errortext);

        // Testing for empty content
        $errortext = get_string('csvemptyfile', 'error');

        $iid = csv_import_reader::get_new_iid('lib');
        $csvimport = new csv_import_reader($iid, 'lib');
        $contentcount = $csvimport->load_csv_content($this->teststring3, 'utf-8', 'comma');
        $importerror = $csvimport->get_error();
        $csvimport->cleanup();
        $csvimport->close();
        $this->assertEquals($importerror, $errortext);
    }
开发者ID:JP-Git,项目名称:moodle,代码行数:47,代码来源:csvclass_test.php

示例9: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/profile/lib.php';
     require_once $CFG->libdir . '/csvlib.class.php';
     $username = $this->arguments[0];
     $filename = $this->expandedOptions['name'];
     $user = get_user_by_name($username);
     if (!$user) {
         cli_error("User not found.");
     } else {
         $userid = $user->id;
     }
     $fields = array('id' => 'id', 'username' => 'username', 'email' => 'email', 'firstname' => 'firstname', 'lastname' => 'lastname', 'idnumber' => 'idnumber', 'institution' => 'institution', 'department' => 'department', 'phone1' => 'phone1', 'phone2' => 'phone2', 'city' => 'city', 'url' => 'url', 'icq' => 'icq', 'skype' => 'skype', 'aim' => 'aim', 'yahoo' => 'yahoo', 'msn' => 'msn', 'country' => 'country');
     if ($extrafields = $DB->get_records('user_info_field')) {
         foreach ($extrafields as $n => $v) {
             $fields['profile_field_' . $v->shortname] = 'profile_field_' . $v->shortname;
         }
     }
     $csvexport = new \csv_export_writer();
     $csvexport->set_filename($filename);
     $csvexport->add_data($fields);
     $row = array();
     profile_load_data($user);
     $userprofiledata = array();
     foreach ($fields as $field => $unused) {
         if (is_array($user->{$field})) {
             $userprofiledata[] = reset($user->{$field});
         } else {
             $userprofiledata[] = $user->{$field};
         }
     }
     $csvexport->add_data($userprofiledata);
     file_put_contents($filename, $csvexport->print_csv_data(true));
     echo "User " . $user->username . " successfully downloaded\n";
 }
开发者ID:dariogs,项目名称:moosh,代码行数:36,代码来源:UserExport.php

示例10: array

            if ($users && in_array($USER->id, array_keys($users))) {
                $allow_marking = true;
                $allow_marking_criteria = $rcriterion->id;
                break;
            }
        }
    }
}
/*
 * Setup page header
 */
if ($csv) {
    $shortname = format_string($course->shortname, true, array('context' => $context));
    $shortname = preg_replace('/[^a-z0-9-]/', '_', core_text::strtolower(strip_tags($shortname)));
    $export = new csv_export_writer();
    $export->set_filename('completion-' . $shortname);
} else {
    // Navigation and header
    $strcompletion = get_string('coursecompletion');
    $PAGE->set_title($strcompletion);
    $PAGE->set_heading($course->fullname);
    echo $OUTPUT->header();
    $PAGE->requires->js('/report/completion/textrotate.js');
    $PAGE->requires->js_function_call('textrotate_init', null, true);
    // Handle groups (if enabled)
    groups_print_course_menu($course, $CFG->wwwroot . '/report/completion/?course=' . $course->id);
}
// Generate where clause
$where = array();
$where_params = array();
if ($sifirst !== 'all') {
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:index.php

示例11: array

// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Internal library of functions for module ratingallocate, subpart csv_export.
 *
 *
 * @package    mod_ratingallocate
 * @copyright  2014 Max Schulze, C Usener
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../../config.php';
// to include $CFG, for example
require_once $CFG->libdir . '/csvlib.class.php';
require_once './locallib.php';
$id = required_param('id', PARAM_INT);
// course_module ID, or
$cm = get_coursemodule_from_id('ratingallocate', $id, 0, false, MUST_EXIST);
$course = get_course($cm->course);
$ratingallocate = $DB->get_record('ratingallocate', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm);
$context = context_module::instance($cm->id);
require_capability('mod/ratingallocate:export_ratings', $context);
$ratingallocateobj = new ratingallocate($ratingallocate, $course, $cm, $context);
global $DB;
// print all the exported data here
$downloadfilename = clean_filename('export_ratings_' . $ratingallocateobj->ratingallocate->name);
$csvexport = new csv_export_writer('semicolon');
$csvexport->set_filename($downloadfilename);
$renderer = $PAGE->get_renderer('mod_ratingallocate');
$renderer->ratings_csv_for_ratingallocate($ratingallocateobj, $csvexport);
$csvexport->download_file();
开发者ID:Kathrin84,项目名称:moodle-mod_ratingallocate,代码行数:31,代码来源:export_ratings_csv.php

示例12: 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();
 }
开发者ID:Burick,项目名称:moodle,代码行数:19,代码来源:csvlib.class.php

示例13: save_users_to_csv

 /**
  * Save requested users to a comma separated values (CSV) file.
  *
  * @return csv_export_writer The csv file object.
  */
 protected function save_users_to_csv()
 {
     global $DB;
     $csv = new csv_export_writer($this->delimiter);
     $csv->set_filename('users');
     $maxrolesnumber = 0;
     // Getting the maximum number of roles a user can have.
     foreach ($this->contents as $key => $user) {
         $rolesnumber = count($user->roles);
         if ($rolesnumber > $maxrolesnumber) {
             $maxrolesnumber = $rolesnumber;
         }
     }
     // Saving field names.
     $userfields = $this->fields;
     if ($this->useoverrides) {
         foreach ($this->overrides as $field => $value) {
             if (!array_search($field, $userfields)) {
                 $userfields[] = $field;
             }
         }
     }
     $row = $userfields;
     if ($maxrolesnumber > 0) {
         for ($i = 1; $i <= $maxrolesnumber; $i++) {
             $coursename = 'course' . $i;
             $rolename = 'role' . $i;
             $row[] = $coursename;
             $row[] = $rolename;
         }
     }
     $csv->add_data($row);
     $columnsnumber = count($row);
     foreach ($this->contents as $key => $user) {
         if (!empty($user->roles)) {
             $row = array();
             foreach ($userfields as $key => $field) {
                 $row[] = $user->{$field};
             }
             foreach ($user->roles as $key => $rolesarray) {
                 foreach ($rolesarray as $role => $course) {
                     $row[] = $course;
                     $row[] = $role;
                 }
             }
             // Adding blank columns until we have the same number of columns.
             $no = count($row);
             while ($no < $columnsnumber) {
                 $row[] = '';
                 $no++;
             }
             $csv->add_data($row);
         }
     }
     return $csv;
 }
开发者ID:alexandru-elisei,项目名称:moodle-tool_downloaddata,代码行数:61,代码来源:processor.php

示例14: 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;
 }
开发者ID:eSrem,项目名称:moodle-mod_mediagallery,代码行数:17,代码来源:search.php

示例15: array

 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;
开发者ID:narasimhaeabyas,项目名称:tataaiapro,代码行数:31,代码来源:download.php


注:本文中的csv_export_writer::set_filename方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。