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


PHP csv_export_writer类代码示例

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


在下文中一共展示了csv_export_writer类的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: execute

 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->libdir . '/csvlib.class.php';
     require_once $CFG->libdir . '/moodlelib.php';
     $filename = $this->expandedOptions['path'];
     if ($filename[0] != '/') {
         $filename = $this->cwd . DIRECTORY_SEPARATOR . $filename;
     }
     $categories = $DB->get_records('user_info_category', null, 'sortorder ASC');
     $data = array();
     foreach ($categories as $category) {
         if ($fields = $DB->get_records('user_info_field', array('categoryid' => $category->id), 'sortorder ASC')) {
             foreach ($fields as $field) {
                 $field->categoryname = $category->name;
                 $field->categorysortorder = $category->sortorder;
                 $data[] = $field;
             }
         }
     }
     // End of $categories foreach.
     $header = array('id', 'shortname', 'name', 'datatype', 'description', 'descriptionformat', 'categoryid', 'sortorder', 'required', 'locked', 'visible', 'forceunique', 'signup', 'defaultdata', 'defaultdataformat', 'param1', 'param2', 'param3', 'param4', 'param5', 'categoryname', 'categorysortorder');
     $csvexport = new \csv_export_writer();
     $csvexport->add_data($header);
     foreach ($data as $row) {
         $arrayrow = (array) $row;
         $csvexport->add_data($arrayrow);
     }
     try {
         file_put_contents($filename, $csvexport->print_csv_data(true));
         echo "Userfields exported to: " . $filename . "\n";
     } catch (Exception $e) {
         cli_error("Unable to save file. Check if file {$filename} is writable");
     }
 }
开发者ID:dariogs,项目名称:moosh,代码行数:35,代码来源:UserProfileFieldsExport.php

示例3: 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

示例4: report_download_csv

 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

示例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('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

示例7: 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

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

示例9: 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

示例10: 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

示例11: require_once

 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

示例12: __analyseExport

 public function __analyseExport($type, $retailer, $store, $region, $country, $course, $team, $sortBy, $fieldsval, $keyword, $isshowreport, $recordrow)
 {
     global $CFG, $DB, $SESSION;
     require_once $CFG->libdir . '/csvlib.class.php';
     $useragent = new uagent_info();
     if ($useragent->DetectIpad() || $useragent->DetectIphoneOrIpod() || $useragent->DetectAndroid() || $useragent->DetectIosNative()) {
         $csvexport = new csv_export_writer();
         $download_method = 'download_file';
     } else {
         $csvexport = new csv_export_writer('tab');
         $download_method = 'download_file_for_excel';
     }
     if ($recordrow != '') {
         $fields = array('Region' => 'Region', 'Country' => 'Country', 'Retailer' => 'Retailer', 'Store' => 'Store', 'Course' => 'Course', 'First Name' => 'First Name', 'Last Name' => 'Last Name', 'Job Title' => 'Job Title', 'Course Points' => 'Course Points', 'Total Points' => 'Total Points');
         $filename = time();
         $csvexport->set_filename($filename);
         $csvexport->add_data($fields);
         if (empty($sortBy)) {
             $sortBy = 'firstname';
             $sortMode = 'ASC';
         } else {
             list($sortBy, $sortMode) = explode(' ', $sortBy);
         }
         $recordrow = explode(',', $recordrow);
         $reportsDetails = $SESSION->reports_current_page;
         foreach ($reportsDetails as $id => &$reportsDetail) {
             if (!in_array($id, $recordrow)) {
                 unset($reportsDetails[$id]);
             }
         }
         unset($reportsDetail);
         foreach ($reportsDetails as $kReportsDetails => $vReportDetails) {
             $userprofiledata['Region'] = $vReportDetails->region;
             $userprofiledata['Country'] = $vReportDetails->country;
             $userprofiledata['Retailer'] = $vReportDetails->retailer;
             $userprofiledata['Store'] = $vReportDetails->store;
             $userprofiledata['Course'] = $vReportDetails->fullname;
             $userprofiledata['First Name'] = $vReportDetails->firstname;
             $userprofiledata['Last Name'] = $vReportDetails->lastname;
             $userprofiledata['Job Title'] = $vReportDetails->jobtitle;
             $userprofiledata['Course Points'] = $vReportDetails->points;
             $userprofiledata['Total Points'] = $vReportDetails->totalpoints;
             $csvexport->add_data($userprofiledata);
             $i++;
         }
         $csvexport->{$download_method}();
         exit;
     }
     if ($isshowreport == 'true') {
         if ($type == 'user' || $type == 'course') {
             $fields = array('Region' => 'Region', 'Country' => 'Country', 'Retailer' => 'Retailer', 'Store' => 'Store', 'Course' => 'Course', 'First Name' => 'First Name', 'Last Name' => 'Last Name', 'Job Title' => 'Job Title', 'Course Points' => 'Course Points', 'Total Points' => 'Total Points');
             //$filename = clean_filename(get_string('users'));
             $filename = time();
             $csvexport->set_filename($filename);
             $csvexport->add_data($fields);
             $region = explode(",", $region);
             $country = explode(",", $country);
             $retailer = explode(",", $retailer);
             $store = explode(",", $store);
             $course = explode(",", $course);
             if ($type == 'user' || $type == 'course') {
                 if (in_array("sel_all", $region) || in_array("null", $country)) {
                     $regionstr = '';
                 } else {
                     $regionstr = implode('~', $region);
                 }
                 if (in_array("sel_all", $country) || in_array("null", $country)) {
                     $countrystr = '';
                 } else {
                     $countrystr = implode('~', $country);
                 }
                 if (in_array("sel_all", $retailer) || in_array("null", $retailer)) {
                     $retailerstr = '';
                 } else {
                     $retailerstr = implode('~', $retailer);
                 }
                 if (in_array("sel_all", $store) || in_array("null", $store)) {
                     $storestr = '';
                 } else {
                     $storestr = implode('~', $store);
                 }
                 if (in_array("sel_all", $course) || in_array("null", $course)) {
                     $coursestr = '';
                 } else {
                     $coursestr = implode('~', $course);
                 }
                 if (empty($sortBy)) {
                     $sortBy = 'firstname';
                     $sortMode = 'ASC';
                 } else {
                     list($sortBy, $sortMode) = explode(' ', $sortBy);
                 }
                 /*
                 	CALL get_mdl_reports_dtl
                 	(
                 	@v_region := '',
                 	@v_country := '',
                 	@v_retailer	:= '',
                 	@v_store := '',
                 	@v_course := '',
//.........这里部分代码省略.........
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:clinique_export.php

示例13: 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;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:67,代码来源:lib.php

示例14: display


//.........这里部分代码省略.........
                // 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');

                $colnum = 0;
                foreach ($headers as $item) {
                    $myxls->write(0, $colnum, $item, $formatbc);
                    $colnum++;
                }
                $rownum = 1;
            } else if ($download == 'CSV') {
                $csvexport = new csv_export_writer("tab");
                $csvexport->set_filename($filename, ".txt");
                $csvexport->add_data($headers);
            }

            if (!$download) {
                $sort = $table->get_sql_sort();
            } else {
                $sort = '';
            }
            // Fix some wired sorting
            if (empty($sort)) {
                $sort = ' ORDER BY uniqueid';
            } else {
                $sort = ' ORDER BY '.$sort;
            }

            if (!$download) {
                // Add extra limits due to initials bar
                list($twhere, $tparams) = $table->get_sql_where();
                if ($twhere) {
                    $where .= ' AND '.$twhere; //initial bar
                    $params = array_merge($params, $tparams);
                }

                if (!empty($countsql)) {
                    $count = $DB->get_record_sql($countsql,$params);
                    $totalinitials = $count->nbresults;
                    if ($twhere) {
                        $countsql .= ' AND '.$twhere;
                    }
                    $count = $DB->get_record_sql($countsql, $params);
                    $total  = $count->nbresults;
开发者ID:number33,项目名称:moodle,代码行数:67,代码来源:report.php

示例15: format_string

            // If logged in user has this role, allow marking complete
            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();
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:31,代码来源:index.php


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