83 {
86
87 $this->warnings = array();
88 try {
90 $excel->loadFromFile(
$file);
91 } catch (Exception $e) {
92 $this->warnings[] = $this->lng->txt("dcl_file_not_readable");
93 }
94
95 $sheet_count = $excel->getSheetCount();
96 $excel->setActiveSheet(0);
97
98 if($sheet_count != count($this->tables)) {
99 $this->warnings[] = $this->lng->txt('dcl_file_not_readable');
100 }
101
102 if (count($this->warnings)) {
103 return array('line'=>0, 'warnings'=>$this->warnings);
104 }
105
106 for($sheet = 0; $sheet < $sheet_count; $sheet++) {
107 $excel->setActiveSheet($sheet);
108 $table = $this->tables[$sheet];
109
110
111 $sheet_title = substr($table->getTitle(), 0, 31);
112 if($excel->getSheetTitle() != $sheet_title) {
113 $this->warnings[] = $this->lng->txt('dcl_table_title_not_matching');
114 continue;
115 }
116
117 $field_names = array();
118 $sheet_data = $excel->getSheetAsArray();
119
120 foreach ($sheet_data[0] as
$column) {
122 }
124
125 $records_failed = 0;
126 for ($i = 2; $i <= count($sheet_data); $i ++) {
128 $record->setOwner(
$ilUser->getId());
131 $record->setTableId($table->getId());
132 if (!$simulate) {
133 $record->doCreate();
134 }
135 $fields_failed = 0;
136 foreach ($fields as $col => $field) {
137 try {
138 $value = $record->getRecordFieldValueFromExcel($excel, $i, $col, $field);
139
140 if (is_array($value) && isset($value['warning'])) {
141 $this->warnings[] = $value['warning'];
142 $value = '';
143 }
144
145 $field->checkValidity($value, $record->getId());
146 if (!$simulate) {
147 $record->setRecordFieldValue($field->getId(), $value);
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
177 return array('line'=>($i-2 < 0 ? 0 : $i-2), 'warnings'=>$this->warnings);
178 }
@classDescription Date and time handling
Class ilDclBaseRecordModel.
getImportFieldsFromTitles($table, $titles)
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file