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

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

Public Member Functions

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

Static Public Member Functions

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

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

◆ 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: