ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ILIAS\Survey\CSVReader Class Reference
+ Collaboration diagram for ILIAS\Survey\CSVReader:

Public Member Functions

 setSeparator (string $a_sep)
 
 setDelimiter (string $a_del)
 
 setLength (int $a_length)
 
 open (string $path_to_file)
 
 close ()
 
 getCsvAsArray ()
 

Private Member Functions

 parse ()
 
 unquote (string $a_str)
 

Private Attributes

 $file_resource
 
string $line_ends
 
array $data = []
 
string $separator = ';'
 
string $delimiter = '""'
 
string $escape = '\\'
 
int $length = 1024
 

Detailed Description

Deprecated:
11 This component will be removed with ILIAS 11

Definition at line 27 of file CSVReader.php.

Member Function Documentation

◆ close()

ILIAS\Survey\CSVReader::close ( )

Definition at line 79 of file CSVReader.php.

79  : bool
80  {
81  return fclose($this->file_resource);
82  }

◆ getCsvAsArray()

ILIAS\Survey\CSVReader::getCsvAsArray ( )

Definition at line 84 of file CSVReader.php.

References ILIAS\Survey\CSVReader\$data, and ILIAS\Survey\CSVReader\parse().

84  : array
85  {
86  $this->parse();
87 
88  return $this->data;
89  }
+ Here is the call graph for this function:

◆ open()

ILIAS\Survey\CSVReader::open ( string  $path_to_file)

Definition at line 69 of file CSVReader.php.

References ilUtil\stripSlashes().

69  : bool
70  {
71  $this->file_resource = fopen(ilUtil::stripSlashes($path_to_file), "r");
72 
73  if (!is_resource($this->file_resource)) {
74  throw new RuntimeException('sould not open stream to ' . $path_to_file);
75  }
76  return true;
77  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ Here is the call graph for this function:

◆ parse()

ILIAS\Survey\CSVReader::parse ( )
private

Definition at line 40 of file CSVReader.php.

References ILIAS\Survey\CSVReader\unquote().

Referenced by ILIAS\Survey\CSVReader\getCsvAsArray().

40  : void
41  {
42  $row = 0;
43 
44  while (($line = fgetcsv($this->file_resource, $this->length, $this->separator, $this->escape)) !== false) {
45  $line_count = count($line);
46  for ($col = 0; $col < $line_count; $col++) {
47  $this->data[$row][$col] = $this->unquote($line[$col]);
48  }
49 
50  ++$row;
51  }
52  }
unquote(string $a_str)
Definition: CSVReader.php:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDelimiter()

ILIAS\Survey\CSVReader::setDelimiter ( string  $a_del)

Definition at line 59 of file CSVReader.php.

59  : void
60  {
61  $this->delimiter = $a_del;
62  }

◆ setLength()

ILIAS\Survey\CSVReader::setLength ( int  $a_length)

Definition at line 64 of file CSVReader.php.

64  : void
65  {
66  $this->length = $a_length;
67  }

◆ setSeparator()

ILIAS\Survey\CSVReader::setSeparator ( string  $a_sep)

Definition at line 54 of file CSVReader.php.

54  : void
55  {
56  $this->separator = $a_sep;
57  }

◆ unquote()

ILIAS\Survey\CSVReader::unquote ( string  $a_str)
private

Definition at line 91 of file CSVReader.php.

Referenced by ILIAS\Survey\CSVReader\parse().

91  : string
92  {
93  return str_replace($this->delimiter . $this->delimiter, $this->delimiter, $a_str);
94  }
+ Here is the caller graph for this function:

Field Documentation

◆ $data

array ILIAS\Survey\CSVReader::$data = []
private

Definition at line 34 of file CSVReader.php.

Referenced by ILIAS\Survey\CSVReader\getCsvAsArray().

◆ $delimiter

string ILIAS\Survey\CSVReader::$delimiter = '""'
private

Definition at line 36 of file CSVReader.php.

◆ $escape

string ILIAS\Survey\CSVReader::$escape = '\\'
private

Definition at line 37 of file CSVReader.php.

◆ $file_resource

ILIAS\Survey\CSVReader::$file_resource
private

Definition at line 32 of file CSVReader.php.

◆ $length

int ILIAS\Survey\CSVReader::$length = 1024
private

Definition at line 38 of file CSVReader.php.

◆ $line_ends

string ILIAS\Survey\CSVReader::$line_ends
private

Definition at line 33 of file CSVReader.php.

◆ $separator

string ILIAS\Survey\CSVReader::$separator = ';'
private

Definition at line 35 of file CSVReader.php.


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