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