@@ -77,20 +77,18 @@ private function _fetchSeries( &$handle ) {
77
77
$ types = fgetcsv ( $ handle , 0 , VISUALIZER_CSV_DELIMITER , VISUALIZER_CSV_ENCLOSURE );
78
78
}
79
79
80
+ $ labels = array_filter ( $ labels );
81
+ $ types = array_filter ( $ types );
82
+
80
83
if ( ! $ labels || ! $ types ) {
84
+ $ this ->_error = esc_html__ ( 'File should have a heading row (1st row) and a data type row (2nd row). Please try again. ' , 'visualizer ' );
81
85
return false ;
82
86
}
83
87
84
- // if no types were setup, re read labels and empty types array
85
88
$ types = array_map ( 'trim ' , $ types );
86
89
if ( ! self ::_validateTypes ( $ types ) ) {
87
- // re open the file
88
- fclose ( $ handle );
89
- $ handle = $ this ->_get_file_handle ();
90
-
91
- // re read the labels and empty types array
92
- $ labels = fgetcsv ( $ handle , 0 , VISUALIZER_CSV_DELIMITER , VISUALIZER_CSV_ENCLOSURE );
93
- $ types = array ();
90
+ $ this ->_error = esc_html__ ( 'Invalid data types detected in the data type row (2nd row). Please try again. ' , 'visualizer ' );
91
+ return false ;
94
92
}
95
93
96
94
for ( $ i = 0 , $ len = count ( $ labels ); $ i < $ len ; $ i ++ ) {
@@ -134,6 +132,7 @@ protected function _get_file_handle( $filename = false ) {
134
132
public function fetch () {
135
133
// if filename is empty return false
136
134
if ( empty ( $ this ->_filename ) ) {
135
+ $ this ->_error = esc_html__ ( 'No file provided. Please try again. ' , 'visualizer ' );
137
136
return false ;
138
137
}
139
138
0 commit comments