75 {
78
79 $this->warnings = array();
80 try {
82 $excel->loadFromFile($file);
83 } catch (Exception $e) {
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)) {
95 return array('line' => 0, 'warnings' => $this->warnings);
96 }
97
98 for ($sheet = 0; $sheet < $sheet_count; $sheet++) {
99 $excel->setActiveSheet($sheet);
100 $table = $this->tables[$sheet];
101
102
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');
106 continue;
107 }
108
109 $field_names = array();
110 $sheet_data = $excel->getSheetAsArray();
111
112 foreach ($sheet_data[0] as $column) {
113 $field_names[] = $column;
114 }
116
117 $records_failed = 0;
118 for (
$i = 2;
$i <= count($sheet_data);
$i++) {
120 $record->setOwner(
$ilUser->getId());
123 $record->setTableId(
$table->getId());
124 if (!$simulate) {
125 $record->doCreate();
126 }
127 $fields_failed = 0;
128 foreach ($fields as $col => $field) {
129 try {
130 if ($field->isStandardField()) {
131 $record->setStandardFieldValueFromExcel($excel,
$i, $col, $field);
132 } else {
133 $value = $record->getRecordFieldValueFromExcel($excel,
$i, $col, $field);
134
135 if (is_array($value) && isset($value['warning'])) {
136 $this->warnings[] = $value['warning'];
137 $value = '';
138 }
139
140 $field->checkValidity($value, $record->getId());
141 if (!$simulate) {
142 $record->setRecordFieldValue($field->getId(), $value);
143 }
144 }
146 $fields_failed++;
148 }
149 }
150
151 if ($fields_failed < count($fields)) {
152 $record_imported = true;
153 } else {
154 $records_failed++;
155 $record_imported = false;
156 }
157
158 if (!$simulate) {
159 if (!$record_imported) {
160 $record->doDelete(true);
161 } else {
162 $record->doUpdate();
163 }
164 }
165 if ((
$i - 1) - $records_failed > $this->max_imports) {
166 $this->warnings[] = $this->lng->txt("dcl_max_import") . (count($sheet_data) - 1) . " > " . $this->max_imports;
167 break;
168 }
169 }
170 }
171
172 return array(
'line' => (
$i - 2 < 0 ? 0 :
$i - 2),
'warnings' => $this->warnings);
173 }
@classDescription Date and time handling
Class ilDclBaseRecordModel.
getImportFieldsFromTitles($table, $titles)