ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
SimpleExcel\Parser\BaseParser Class Reference
+ Inheritance diagram for SimpleExcel\Parser\BaseParser:
+ Collaboration diagram for SimpleExcel\Parser\BaseParser:

Public Member Functions

 __construct ($file_url=NULL)
 
 getCell ($row_num, $col_num, $val_only=true)
 Get value of the specified cell. More...
 
 getColumn ($col_num, $val_only=TRUE)
 Get data of the specified column as an array. More...
 
 getField ($val_only=TRUE)
 Get data of all cells as an array. More...
 
 getRow ($row_num, $val_only=TRUE)
 Get data of the specified row as an array. More...
 
 isCellExists ($row_num, $col_num)
 Check whether cell with specified row & column exists. More...
 
 isColumnExists ($col_num)
 Check whether a specified column exists. More...
 
 isRowExists ($row_num)
 Check whether a specified row exists. More...
 
 isFieldExists ()
 Check whether table exists. More...
 
 isFileReady ($file_path)
 Check whether file exists, valid, and readable. More...
 
- Public Member Functions inherited from SimpleExcel\Parser\IParser
 loadFile ($file_path)
 
 loadString ($str)
 

Protected Attributes

 $table_arr
 
 $file_extension = ''
 

Detailed Description

Definition at line 13 of file BaseParser.php.

Constructor & Destructor Documentation

◆ __construct()

SimpleExcel\Parser\BaseParser::__construct (   $file_url = NULL)
Parameters
string$file_urlPath to file (optional)

Definition at line 34 of file BaseParser.php.

References SimpleExcel\Parser\IParser\loadFile().

34  {
35  if(isset($file_url)) {
36  $this->loadFile($file_url);
37  }
38  }
+ Here is the call graph for this function:

Member Function Documentation

◆ getCell()

SimpleExcel\Parser\BaseParser::getCell (   $row_num,
  $col_num,
  $val_only = true 
)

Get value of the specified cell.

Parameters
int$row_numRow number
int$col_numColumn number
int$val_only
Returns
array
Exceptions
ExceptionIf the cell identified doesn't exist.

Implements SimpleExcel\Parser\IParser.

Definition at line 49 of file BaseParser.php.

References SimpleExcel\Exception\SimpleExcelException\CELL_NOT_FOUND, and SimpleExcel\Parser\BaseParser\isCellExists().

49  {
50  // check whether the cell exists
51  if (!$this->isCellExists($row_num, $col_num)) {
52  throw new \Exception('Cell '.$row_num.','.$col_num.' doesn\'t exist', SimpleExcelException::CELL_NOT_FOUND);
53  }
54  return $this->table_arr[$row_num-1][$col_num-1];
55  }
isCellExists($row_num, $col_num)
Check whether cell with specified row & column exists.
Definition: BaseParser.php:121
+ Here is the call graph for this function:

◆ getColumn()

SimpleExcel\Parser\BaseParser::getColumn (   $col_num,
  $val_only = TRUE 
)

Get data of the specified column as an array.

Parameters
int$col_numColumn number
bool$val_only
Returns
array
Exceptions
ExceptionIf the column requested doesn't exist.

Implements SimpleExcel\Parser\IParser.

Definition at line 65 of file BaseParser.php.

References $row, SimpleExcel\Exception\SimpleExcelException\COLUMN_NOT_FOUND, and SimpleExcel\Parser\BaseParser\isColumnExists().

65  {
66  $col_arr = array();
67 
68  if(!$this->isColumnExists($col_num)){
69  throw new \Exception('Column '.$col_num.' doesn\'t exist', SimpleExcelException::COLUMN_NOT_FOUND);
70  }
71 
72  // get the specified column within every row
73  foreach($this->table_arr as $row){
74  array_push($col_arr, $row[$col_num-1]);
75  }
76 
77  // return the array
78  return $col_arr;
79  }
isColumnExists($col_num)
Check whether a specified column exists.
Definition: BaseParser.php:131
+ Here is the call graph for this function:

◆ getField()

SimpleExcel\Parser\BaseParser::getField (   $val_only = TRUE)

Get data of all cells as an array.

Parameters
bool$val_only
Returns
array
Exceptions
ExceptionIf the field is not set.

Implements SimpleExcel\Parser\IParser.

Definition at line 88 of file BaseParser.php.

References SimpleExcel\Parser\BaseParser\$table_arr, SimpleExcel\Exception\SimpleExcelException\FIELD_NOT_FOUND, and SimpleExcel\Parser\BaseParser\isFieldExists().

88  {
89  if(!$this->isFieldExists()){
90  throw new \Exception('Field is not set', SimpleExcelException::FIELD_NOT_FOUND);
91  }
92 
93  // return the array
94  return $this->table_arr;
95  }
isFieldExists()
Check whether table exists.
Definition: BaseParser.php:156
+ Here is the call graph for this function:

◆ getRow()

SimpleExcel\Parser\BaseParser::getRow (   $row_num,
  $val_only = TRUE 
)

Get data of the specified row as an array.

Parameters
int$row_numRow number
bool$val_only
Returns
array
Exceptions
ExceptionWhen a row is requested that doesn't exist.

Implements SimpleExcel\Parser\IParser.

Definition at line 105 of file BaseParser.php.

References SimpleExcel\Parser\BaseParser\isRowExists(), and SimpleExcel\Exception\SimpleExcelException\ROW_NOT_FOUND.

105  {
106  if(!$this->isRowExists($row_num)){
107  throw new \Exception('Row '.$row_num.' doesn\'t exist', SimpleExcelException::ROW_NOT_FOUND);
108  }
109 
110  // return the array
111  return $this->table_arr[$row_num-1];
112  }
isRowExists($row_num)
Check whether a specified row exists.
Definition: BaseParser.php:147
+ Here is the call graph for this function:

◆ isCellExists()

SimpleExcel\Parser\BaseParser::isCellExists (   $row_num,
  $col_num 
)

Check whether cell with specified row & column exists.

Parameters
int$row_numRow number
int$col_numColumn number
Returns
bool

Implements SimpleExcel\Parser\IParser.

Definition at line 121 of file BaseParser.php.

References SimpleExcel\Parser\BaseParser\isColumnExists(), and SimpleExcel\Parser\BaseParser\isRowExists().

Referenced by SimpleExcel\Parser\BaseParser\getCell(), and SimpleExcel\Parser\XMLParser\getCell().

121  {
122  return $this->isRowExists($row_num) && $this->isColumnExists($col_num);
123  }
isColumnExists($col_num)
Check whether a specified column exists.
Definition: BaseParser.php:131
isRowExists($row_num)
Check whether a specified row exists.
Definition: BaseParser.php:147
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isColumnExists()

SimpleExcel\Parser\BaseParser::isColumnExists (   $col_num)

Check whether a specified column exists.

Parameters
int$col_numColumn number
Returns
bool

Implements SimpleExcel\Parser\IParser.

Definition at line 131 of file BaseParser.php.

References $row.

Referenced by SimpleExcel\Parser\BaseParser\getColumn(), and SimpleExcel\Parser\BaseParser\isCellExists().

131  {
132  $exist = false;
133  foreach($this->table_arr as $row){
134  if(array_key_exists($col_num-1, $row)){
135  $exist = true;
136  }
137  }
138  return $exist;
139  }
+ Here is the caller graph for this function:

◆ isFieldExists()

SimpleExcel\Parser\BaseParser::isFieldExists ( )

Check whether table exists.

Returns
bool

Implements SimpleExcel\Parser\IParser.

Definition at line 156 of file BaseParser.php.

Referenced by SimpleExcel\Parser\BaseParser\getField(), and SimpleExcel\Parser\XMLParser\getField().

156  {
157  return isset($this->table_arr);
158  }
+ Here is the caller graph for this function:

◆ isFileReady()

SimpleExcel\Parser\BaseParser::isFileReady (   $file_path)

Check whether file exists, valid, and readable.

Parameters
string$file_pathPath to file
Returns
bool
Exceptions
ExceptionIf file being loaded doesn't exist
ExceptionIf file extension doesn't match
ExceptionIf error reading the file

Implements SimpleExcel\Parser\IParser.

Definition at line 169 of file BaseParser.php.

References SimpleExcel\Parser\BaseParser\$file_extension, SimpleExcel\Exception\SimpleExcelException\ERROR_READING_FILE, SimpleExcel\Exception\SimpleExcelException\FILE_EXTENSION_MISMATCH, and SimpleExcel\Exception\SimpleExcelException\FILE_NOT_FOUND.

Referenced by SimpleExcel\Parser\JSONParser\loadFile(), SimpleExcel\Parser\CSVParser\loadFile(), SimpleExcel\Parser\HTMLParser\loadFile(), and SimpleExcel\Parser\XMLParser\loadFile().

169  {
170 
171  // file exists?
172  if (!file_exists($file_path)) {
173 
174  throw new \Exception('File '.$file_path.' doesn\'t exist', SimpleExcelException::FILE_NOT_FOUND);
175 
176  // extension valid?
177  } else if (strtoupper(pathinfo($file_path, PATHINFO_EXTENSION))!= strtoupper($this->file_extension)){
178 
179  throw new \Exception('File extension '.$file_extension.' doesn\'t match with '.$this->file_extension, SimpleExcelException::FILE_EXTENSION_MISMATCH);
180 
181  // file readable?
182  } else if (($handle = fopen($file_path, 'r')) === FALSE) {
183 
184  throw new \Exception('Error reading the file in'.$file_path, SimpleExcelException::ERROR_READING_FILE);
185  fclose($handle);
186 
187  // okay then
188  } else {
189 
190  return TRUE;
191  }
192  }
+ Here is the caller graph for this function:

◆ isRowExists()

SimpleExcel\Parser\BaseParser::isRowExists (   $row_num)

Check whether a specified row exists.

Parameters
int$row_numRow number
Returns
bool

Implements SimpleExcel\Parser\IParser.

Definition at line 147 of file BaseParser.php.

Referenced by SimpleExcel\Parser\BaseParser\getRow(), and SimpleExcel\Parser\BaseParser\isCellExists().

147  {
148  return array_key_exists($row_num-1, $this->table_arr);
149  }
+ Here is the caller graph for this function:

Field Documentation

◆ $file_extension

SimpleExcel\Parser\BaseParser::$file_extension = ''
protected

Definition at line 29 of file BaseParser.php.

Referenced by SimpleExcel\Parser\BaseParser\isFileReady().

◆ $table_arr

SimpleExcel\Parser\BaseParser::$table_arr
protected

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