Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
csv_export_writer Class Reference

Public Member Functions

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

Static Public Member Functions

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

Public Attributes

string $csvenclosure
 $csvenclosure How fields with spaces and commas are enclosed.
 
string $delimiter
 $delimiter The name of the delimiter. More...
 
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.
 

Constructor & Destructor Documentation

◆ __construct()

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

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.

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: