Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
csv_export_writer Class Reference

Utitily class for exporting of CSV files. More...

Public Member Functions

 __construct ($delimiter='comma', $enclosure='"', $mimetype = 'application/download', $bom = false)
 Constructor for the csv export reader.
 
 __destruct ()
 Make sure that everything is closed when we are finished.
 
 add_data ($row)
 Add data to the temporary file in csv format.
 
 download_file ()
 Download the csv file.
 
 print_csv_data ($return=false)
 Echos or returns a csv data line by line for displaying.
 
 set_filename ($dataname, $extension='.csv')
 Set the filename for the uploaded csv file.
 

Static Public Member Functions

static download_array ($filename, array &$records, $delimiter='comma', $enclosure='"')
 Creates a file for downloading an array into a deliminated format.
 
static print_array (array &$records, $delimiter='comma', $enclosure='"', $return = false)
 This will convert an array of values into a deliminated string.
 

Public Attributes

string $csvenclosure
 $csvenclosure How fields with spaces and commas are enclosed.
 
string $delimiter
 $delimiter The name of the delimiter.
 
string $filename
 $filename The filename for the csv file to be downloaded.
 
string $mimetype
 $mimetype Mimetype of the file we are exporting.
 
string $path
 $path The directory path for storing the temporary csv file.
 

Protected Member Functions

 send_header ()
 Output file headers to initialise the download of the file.
 
 set_temp_file_path ()
 Set the file path to the temporary file.
 

Protected Attributes

resource $fp
 $fp File pointer for the csv file.
 

Detailed Description

Utitily class for exporting of CSV files.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

csv_export_writer::__construct ( $delimiter = 'comma',
$enclosure = '"',
$mimetype = 'application/download',
$bom = false )

Constructor for the csv export reader.

Parameters
string$delimiterThe name of the character used to seperate fields. Supported types(comma, tab, semicolon, colon, cfg)
string$enclosureThe character used for determining the enclosures.
string$mimetypeMime type of the file that we are exporting.
boolean$bomIf true, prefix file with byte order mark.

Member Function Documentation

◆ add_data()

csv_export_writer::add_data ( $row)

Add data to the temporary file in csv format.

Parameters
array$rowAn array of values.

◆ download_array()

static csv_export_writer::download_array ( $filename,
array & $records,
$delimiter = 'comma',
$enclosure = '"' )
static

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.

Parameters
string$filenameThe filename of the file being created.
array$recordsAn array of information to be converted.
string$delimiterThe name of the delimiter. Supported types(comma, tab, semicolon, colon, cfg)
string$enclosureHow speical fields are enclosed.

◆ print_array()

static csv_export_writer::print_array ( array & $records,
$delimiter = 'comma',
$enclosure = '"',
$return = false )
static

This will convert an array of values into a deliminated string.

Like the above function, this is for convenience.

Parameters
array$recordsAn array of information to be converted.
string$delimiterThe name of the delimiter. Supported types(comma, tab, semicolon, colon, cfg)
string$enclosureHow speical fields are enclosed.
bool$returnIf true will return a string with the csv data.
Return values
stringcsv data.

◆ print_csv_data()

csv_export_writer::print_csv_data ( $return = false)

Echos or returns a csv data line by line for displaying.

Parameters
bool$returnSet to true to return a string with the csv data.
Return values
stringcsv data.

◆ set_filename()

csv_export_writer::set_filename ( $dataname,
$extension = '.csv' )

Set the filename for the uploaded csv file.

Parameters
string$datanameThe name of the module.
string$extenstionFile extension for the file.

Member Data Documentation

◆ $delimiter

string csv_export_writer::$delimiter

$delimiter The name of the delimiter.

Supported types(comma, tab, semicolon, colon, cfg)


The documentation for this class was generated from the following file: