5 require_once(
'./Modules/DataCollection/classes/class.ilObjDataCollectionAccess.php');
6 require_once(
'./Modules/DataCollection/classes/class.ilObjDataCollectionGUI.php');
7 require_once(
'./Modules/DataCollection/classes/Content/class.ilDclRecordListGUI.php');
8 require_once(
'./Modules/DataCollection/classes/Table/class.ilDclTable.php');
9 require_once (
'./Services/Export/classes/class.ilExport.php');
10 require_once (
'./Services/Excel/classes/class.ilExcel.php');
83 public function import(
$file, $simulate =
false) {
87 $this->warnings =
array();
90 $excel->loadFromFile(
$file);
92 $this->warnings[] = $this->lng->txt(
"dcl_file_not_readable");
95 $sheet_count = $excel->getSheetCount();
96 $excel->setActiveSheet(0);
98 if($sheet_count != count($this->tables)) {
99 $this->warnings[] = $this->lng->txt(
'dcl_file_not_readable');
102 if (count($this->warnings)) {
103 return array(
'line'=>0,
'warnings'=>$this->warnings);
106 for($sheet = 0; $sheet < $sheet_count; $sheet++) {
107 $excel->setActiveSheet($sheet);
108 $table = $this->tables[$sheet];
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');
117 $field_names =
array();
118 $sheet_data = $excel->getSheetAsArray();
120 foreach ($sheet_data[0] as
$column) {
126 for ($i = 2; $i <= count($sheet_data); $i ++) {
128 $record->setOwner(
$ilUser->getId());
131 $record->setTableId($table->getId());
136 foreach ($fields as $col => $field) {
138 $value = $record->getRecordFieldValueFromExcel($excel, $i, $col, $field);
140 if (is_array($value) && isset($value[
'warning'])) {
141 $this->warnings[] = $value[
'warning'];
145 $field->checkValidity($value, $record->getId());
147 $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;
177 return array(
'line'=>($i-2 < 0 ? 0 : $i-2),
'warnings'=>$this->warnings);
189 $this->warnings[] = $field->getTitle() .
": " . $this->lng->txt(
"dcl_not_supported_in_import");
203 $fields = $table->getRecordFields();
204 $import_fields =
array();
205 foreach ($fields as $field) {
208 $field->checkTitlesForImport($titles, $import_fields);
212 foreach ($titles as $key => $value) {
214 if (in_array($value, $std_field_titles)) {
216 }
else if (!isset($import_fields[$key])) {
221 return $import_fields;
__construct($ref_id, $table_id=null)
const INPUTFORMAT_BOOLEAN
Hook-Class for exporting data-collections (used in SOAP-Class) This Class avoids duplicated code by r...
static _getAllStandardFieldTitles()
$supported_import_datatypes
const INPUTFORMAT_DATETIME
Create styles array
The data for the language used.
const INPUTFORMAT_REFERENCE
Class ilDclBaseRecordModel.
static getExcelCharForInteger($int)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
Class ilObjDataCollection.
getImportFieldsFromTitles($table, $titles)