80 $excel->loadFromFile($file);
82 $this->warnings[] = $this->
lng->txt(
"dcl_file_not_readable");
85 $sheet_count = $excel->getSheetCount();
86 $excel->setActiveSheet(0);
88 if ($sheet_count != count($this->tables)) {
89 $this->warnings[] = $this->
lng->txt(
'dcl_file_not_readable');
92 if (count($this->warnings)) {
98 for ($sheet = 0; $sheet < $sheet_count; $sheet++) {
99 $excel->setActiveSheet($sheet);
100 $table = $this->tables[$sheet];
103 $sheet_title = substr($table->getTitle(), 0, 31);
104 if ($excel->getSheetTitle() != $sheet_title) {
105 $this->warnings[] = $this->
lng->txt(
'dcl_table_title_not_matching');
110 $sheet_data = $excel->getSheetAsArray();
112 foreach ($sheet_data[0] as $column) {
113 $field_names[] = $column;
118 for ($i = 2; $i <= count($sheet_data); $i++) {
120 $record->setOwner($this->
user->getId());
122 $record->setCreateDate($date_obj);
123 $record->setLastUpdate($date_obj);
124 $record->setLastEditBy($this->
user->getId());
125 $record->setTableId($table->getId());
130 foreach ($fields as $col => $field) {
132 if ($field->isStandardField()) {
133 $record->setStandardFieldValueFromExcel($excel, $i, $col, $field);
135 $value = $record->getRecordFieldValueFromExcel($excel, $i, $col, $field);
137 if (is_array($value) && isset($value[
'warning'])) {
138 $this->warnings[] = $value[
'warning'];
142 $field->checkValidity($value, $record->getId());
144 $record->setRecordFieldValue($field->getId(), $value);
153 if ($fields_failed < count($fields)) {
154 $record_imported =
true;
157 $record_imported =
false;
161 if (!$record_imported) {
162 $record->doDelete(
true);
167 if (($i - 1) - $records_failed > $this->max_imports) {
168 $this->warnings[] = $this->
lng->txt(
"dcl_max_import") . (count($sheet_data) - 1) .
" > " . $this->max_imports;
174 return [
'line' => (max($i - 2, 0)),
'warnings' => $this->warnings];
getImportFieldsFromTitles(ilDclTable $table, array $titles)
static getExcelCharForInteger(int $int)