82 $excel->loadFromFile($file);
84 $this->warnings[] = $this->
lng->txt(
"dcl_file_not_readable");
87 $sheet_count = $excel->getSheetCount();
88 $excel->setActiveSheet(0);
90 if ($sheet_count != count($this->tables)) {
91 $this->warnings[] = $this->
lng->txt(
'dcl_file_not_readable');
94 if (count($this->warnings)) {
100 for ($sheet = 0; $sheet < $sheet_count; $sheet++) {
101 $excel->setActiveSheet($sheet);
102 $table = $this->tables[$sheet];
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');
112 $sheet_data = $excel->getSheetAsArray();
114 foreach ($sheet_data[0] as $column) {
115 $field_names[] = $column;
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());
132 foreach ($fields as $col => $field) {
134 if ($field->isStandardField()) {
135 $record->setStandardFieldValueFromExcel($excel, $i, $col, $field);
137 $value = $record->getRecordFieldValueFromExcel($excel, $i, $col, $field);
139 if (is_array($value) && isset($value[
'warning'])) {
140 $this->warnings[] = $value[
'warning'];
144 $field->checkValidity($value, $record->getId());
146 $record->setRecordFieldValue($field->getId(), $value);
155 if ($fields_failed < count($fields)) {
156 $record_imported =
true;
159 $record_imported =
false;
163 if (!$record_imported) {
164 $record->doDelete(
true);
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;
176 return [
'line' => (max($i - 2, 0)),
'warnings' => $this->warnings];
getImportFieldsFromTitles(ilDclTable $table, array $titles)
static getExcelCharForInteger(int $int)