77 : array
78 {
79 $this->warnings = [];
81 try {
82 $excel->loadFromFile($file);
83 } catch (Exception) {
84 $this->warnings[] = $this->
lng->txt(
"dcl_file_not_readable");
85 }
86
87 $sheet_count = $excel->getSheetCount();
88 $excel->setActiveSheet(0);
89
90 if ($sheet_count != count($this->tables)) {
91 $this->warnings[] = $this->
lng->txt(
'dcl_file_not_readable');
92 }
93
94 if (count($this->warnings)) {
96 }
97
98 $i = 0;
99
100 for ($sheet = 0; $sheet < $sheet_count; $sheet++) {
101 $excel->setActiveSheet($sheet);
102 $table = $this->tables[$sheet];
103
104
105 $sheet_title = substr($table->getTitle(), 0, 31);
106 if ($excel->getSheetTitle() != $sheet_title) {
107 $this->warnings[] = $this->
lng->txt(
'dcl_table_title_not_matching');
108 continue;
109 }
110
111 $field_names = [];
112 $sheet_data = $excel->getSheetAsArray();
113
114 foreach ($sheet_data[0] as $column) {
115 $field_names[] = $column;
116 }
118
119 $records_failed = 0;
120 for ($i = 2; $i <= count($sheet_data); $i++) {
122 $record->setOwner($this->
user->getId());
124 $record->setCreateDate($date_obj);
125 $record->setLastUpdate($date_obj);
126 $record->setLastEditBy($this->
user->getId());
127 $record->setTableId($table->getId());
128 if (!$simulate) {
129 $record->doCreate();
130 }
131 $fields_failed = 0;
132 foreach ($fields as $col => $field) {
133 try {
134 if ($field->isStandardField()) {
135 $record->setStandardFieldValueFromExcel($excel, $i, $col, $field);
136 } else {
137 $value = $record->getRecordFieldValueFromExcel($excel, $i, $col, $field);
138
139 if (is_array($value) && isset($value['warning'])) {
140 $this->warnings[] = $value['warning'];
141 $value = '';
142 }
143
144 $field->checkValidity($value, $record->getId());
145 if (!$simulate) {
146 $record->setRecordFieldValue($field->getId(), $value);
147 }
148 }
150 $fields_failed++;
152 }
153 }
154
155 if ($fields_failed < count($fields)) {
156 $record_imported = true;
157 } else {
158 $records_failed++;
159 $record_imported = false;
160 }
161
162 if (!$simulate) {
163 if (!$record_imported) {
164 $record->doDelete(true);
165 } else {
166 $record->doUpdate();
167 }
168 }
169 if (($i - 1) - $records_failed > $this->max_imports) {
170 $this->warnings[] = $this->
lng->txt(
"dcl_max_import") . (count($sheet_data) - 1) .
" > " . $this->max_imports;
171 break;
172 }
173 }
174 }
175
176 return ['line' => (max($i - 2, 0)), 'warnings' => $this->warnings];
177 }
@classDescription Date and time handling
getImportFieldsFromTitles(ilDclTable $table, array $titles)