• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP csv_export_writer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了csv_export_writer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: print_array

 /**
  * This will convert an array of values into a deliminated string.
  * Like the above function, this is for convenience.
  *
  * @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.
  * @param bool $return       If true will return a string with the csv data.
  * @return string            csv data.
  */
 public static function print_array(array &$records, $delimiter = 'comma', $enclosure = '"', $return = false)
 {
     $csvdata = new csv_export_writer($delimiter, $enclosure);
     foreach ($records as $row) {
         $csvdata->add_data($row);
     }
     $data = $csvdata->print_csv_data($return);
     if ($return) {
         return $data;
     }
 }
开发者ID:Burick,项目名称:moodle,代码行数:21,代码来源:csvlib.class.php


示例17: send

 public function send($filename)
 {
     $writer = new csv_export_writer($this->delimiter);
     $writer->set_filename($filename);
     foreach ($this->pages as $page) {
         if ($page->title) {
             $writer->add_data(array('*** ' . $page->title . ' ***'));
         }
         // Find extent of the table.
         $rows = $this->get_row_count($page);
         $cols = $this->get_col_count($page);
         for ($row = 0; $row < $rows; $row++) {
             $data = array();
             $col = 0;
             while ($col < $cols) {
                 if (isset($page->cells[$row][$col])) {
                     $data[] = $page->cells[$row][$col];
                 } else {
                     $data[] = '';
                 }
                 $span = 1;
                 if (isset($page->mergers[$row][$col])) {
                     $mergewidth = (int) $page->mergers[$row][$col];
                     if ($mergewidth >= 1) {
                         $span = $mergewidth;
                     }
                 }
                 $col += $span;
             }
             $writer->add_data($data);
         }
     }
     $writer->download_file();
 }
开发者ID:ninelanterns,项目名称:moodle-mod_scheduler,代码行数:34,代码来源:exportlib.php


示例18: 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;
 }
开发者ID:abhiahirwar,项目名称:moodle_csv_report,代码行数:95,代码来源:grade_export_csv.php


示例19: __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;
    }
开发者ID:vinoth4891,项目名称:clinique,代码行数:37,代码来源:clinique_course_resource.php


示例20: 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;
}
开发者ID:vinoth4891,项目名

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP csv_import_reader类代码示例发布时间:2022-05-23
下一篇:
PHP csstidy类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap