Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
csv_import_reader Class Reference

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

Public Member Functions

 __construct ($iid, $type)
 Contructor.
 
 __destruct ()
 Make sure the file is closed when this object is discarded.
 
object cleanup ($full=false)
 Cleanup temporary data.
 
 close ()
 Release iteration related resources.
 
 get_columns ()
 Returns list of columns.
 
 get_error ()
 Get last error.
 
object init ()
 Init iterator.
 
 load_csv_content ($content, $encoding, $delimiter_name, $column_validation=null, $enclosure='"')
 Parse this content.
 
 next ()
 Get next line.
 

Static Public Member Functions

static get_delimiter ($delimiter_name)
 Get delimiter character.
 
static get_delimiter_list ()
 Get list of cvs delimiters.
 
static object get_encoded_delimiter ($delimiter_name)
 Get encoded delimiter character.
 
static object get_new_iid ($type)
 Create new import id.
 

Detailed Description

Utitily class for importing of CSV files.

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

Constructor & Destructor Documentation

◆ __construct()

csv_import_reader::__construct ( $iid,
$type )

Contructor.

Parameters
int$iidimport identifier
string$typewhich script imports?

Member Function Documentation

◆ cleanup()

object csv_import_reader::cleanup ( $full = false)

Cleanup temporary data.

@global object

Parameters
boolean$fulltrue means do a full cleanup - all sessions for current user, false only the active iid

◆ close()

csv_import_reader::close ( )

Release iteration related resources.

Return values
void

◆ get_columns()

csv_import_reader::get_columns ( )

Returns list of columns.

Return values
array|false

◆ get_delimiter()

static csv_import_reader::get_delimiter ( $delimiter_name)
static

Get delimiter character.

Parameters
stringseparator name
Return values
stringdelimiter char

◆ get_delimiter_list()

static csv_import_reader::get_delimiter_list ( )
static

Get list of cvs delimiters.

Return values
arraysuitable for selection box

◆ get_encoded_delimiter()

static object csv_import_reader::get_encoded_delimiter ( $delimiter_name)
static

Get encoded delimiter character.

Parameters
stringseparator name
Return values
stringencoded delimiter char

◆ get_error()

csv_import_reader::get_error ( )

Get last error.

Return values
stringerror text of null if none

◆ get_new_iid()

static object csv_import_reader::get_new_iid ( $type)
static

Create new import id.

Parameters
stringwho imports?
Return values
intiid

◆ init()

object csv_import_reader::init ( )

Init iterator.

@global object

Return values
boolSuccess

◆ load_csv_content()

csv_import_reader::load_csv_content ( $content,
$encoding,
$delimiter_name,
$column_validation = null,
$enclosure = '"' )

Parse this content.

Parameters
string$contentthe content to parse.
string$encodingcontent encoding
string$delimiter_nameseparator (comma, semicolon, colon, cfg)
string$column_validationname of function for columns validation, must have one param $columns
string$enclosurefield wrapper. One character only.
Return values
boolfalse if error, count of data lines if ok; use get_error() to get error string

◆ next()

csv_import_reader::next ( )

Get next line.

Return values
mixedfalse, or an array of values

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