Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mod_data\local\exporter\entries_exporter Class Reference
Inheritance diagram for mod_data\local\exporter\entries_exporter:
mod_data\local\exporter\csv_entries_exporter mod_data\local\exporter\ods_entries_exporter

Public Member Functions

 __construct ()
 Creates an entries_exporter object.
 
 add_file_from_string (string $filename, string $filecontent, string $zipsubdir='files/')
 Use this method to add a file which should be exported to the entries_exporter.
 
 add_row (array $row)
 Adds a row (array of strings) to the export data.
 
 add_to_current_row (string $cellcontent)
 Adds a data string (so the content for a "cell") to the current row.
 
 create_unique_filename (string $filename)
 Creates a unique filename based on the given filename.
 
 file_exists (string $filename, string $zipsubdir='files/')
 Checks if a file with the given name has already been added to the file export bundle.
 
 get_records_count ()
 Returns the count of currently stored records (rows excluding header row).
 
 next_row ()
 Signal the entries_exporter to finish the current row and jump to the next row.
 
 send_file (bool $sendtouser=true)
 Sends the generated export file.
 
 set_export_file_name (string $exportfilename)
 Sets the name of the export file.
 

Protected Member Functions

 get_data_file_content ()
 The entries_exporter will prepare a data file from the rows and columns being added.
 
 get_export_data_file_extension ()
 Overwrite the method to return the file extension your data file will have, for example return 'csv'; for a csv file entries_exporter.
 

Protected Attributes

array array $exportdata
 The data structure containing the data for exporting.
 
string string $exportfilename
 Name of the export file name without extension.
 

Constructor & Destructor Documentation

◆ __construct()

mod_data\local\exporter\entries_exporter::__construct ( )

Creates an entries_exporter object.

This object can be used to export data to different formats including files. If files are added, everything will be bundled up in a zip archive.

Member Function Documentation

◆ add_file_from_string()

mod_data\local\exporter\entries_exporter::add_file_from_string ( string $filename,
string $filecontent,
string $zipsubdir = 'files/' )

Use this method to add a file which should be exported to the entries_exporter.

Parameters
string$filenamethe name of the file which should be added
string$filecontentthe content of the file as a string
string$zipsubdirthe subdirectory in the zip archive. Defaults to 'files/'.
Return values
void
Exceptions
moodle_exceptionif there is an error adding the file to the zip archive

◆ add_row()

mod_data\local\exporter\entries_exporter::add_row ( array $row)

Adds a row (array of strings) to the export data.

Parameters
array$rowthe row to add, $row has to be a plain array of strings
Return values
void

◆ add_to_current_row()

mod_data\local\exporter\entries_exporter::add_to_current_row ( string $cellcontent)

Adds a data string (so the content for a "cell") to the current row.

Parameters
string$cellcontentthe content to add to the current row
Return values
void

◆ create_unique_filename()

mod_data\local\exporter\entries_exporter::create_unique_filename ( string $filename)

Creates a unique filename based on the given filename.

This method adds "_1", "_2", ... to the given file name until the newly generated filename is not equal to any of the already saved ones in the export file bundle.

Parameters
string$filenamethe filename based on which a unique filename should be generated
Return values
stringthe unique filename

◆ file_exists()

mod_data\local\exporter\entries_exporter::file_exists ( string $filename,
string $zipsubdir = 'files/' )

Checks if a file with the given name has already been added to the file export bundle.

Care: Filenames are compared to all files in the specified zip subdirectory which defaults to 'files/'.

Parameters
string$filenamethe filename containing the zip path of the file to check
string$zipsubdirThe subdirectory in which the filename should be looked for, defaults to 'files/'
Return values
booltrue if file with the given name already exists, false otherwise

◆ get_data_file_content()

mod_data\local\exporter\entries_exporter::get_data_file_content ( )
abstractprotected

The entries_exporter will prepare a data file from the rows and columns being added.

Overwrite this method to generate the data file as string.

Return values
stringthe data file as a string

Reimplemented in mod_data\local\exporter\csv_entries_exporter, and mod_data\local\exporter\ods_entries_exporter.

◆ get_export_data_file_extension()

mod_data\local\exporter\entries_exporter::get_export_data_file_extension ( )
abstractprotected

Overwrite the method to return the file extension your data file will have, for example return 'csv'; for a csv file entries_exporter.

Return values
stringthe file extension of the data file your entries_exporter is using

Reimplemented in mod_data\local\exporter\csv_entries_exporter, and mod_data\local\exporter\ods_entries_exporter.

◆ get_records_count()

mod_data\local\exporter\entries_exporter::get_records_count ( )

Returns the count of currently stored records (rows excluding header row).

Return values
intthe count of records/rows

◆ next_row()

mod_data\local\exporter\entries_exporter::next_row ( )

Signal the entries_exporter to finish the current row and jump to the next row.

Return values
void

◆ send_file()

mod_data\local\exporter\entries_exporter::send_file ( bool $sendtouser = true)

Sends the generated export file.

Care: By default this function finishes the current PHP request and directly serves the file to the user as download.

Parameters
bool$sendtousertrue if the file should be sent directly to the user, if false the file content will be returned as string
Return values
string|nullfile content as string if $sendtouser is true
Exceptions
moodle_exceptionif there is an issue adding the data file
file_serving_exceptionif the file could not be served properly

◆ set_export_file_name()

mod_data\local\exporter\entries_exporter::set_export_file_name ( string $exportfilename)

Sets the name of the export file.

Only use the basename without path and without extension here.

Parameters
string$exportfilenamename of the file without path and extension
Return values
void

Member Data Documentation

◆ $exportdata

array array mod_data\local\exporter\entries_exporter::$exportdata
protected

The data structure containing the data for exporting.

It's a 2-dimensional array of rows and columns.


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