55 public function __construct(
int $ref_id, ?
int $table_id = null)
62 $this->
lng = $DIC->language();
63 $this->
user = $DIC->user();
66 $this->tables = (
$table_id) ? [$this->dcl->getTableById($table_id)] : $this->dcl->getTables();
74 public function import(
string $file,
bool $simulate =
false): array
79 $excel->loadFromFile($file);
81 $this->warnings[] = $this->
lng->txt(
"dcl_file_not_readable");
84 $sheet_count = $excel->getSheetCount();
85 $excel->setActiveSheet(0);
87 if ($sheet_count != count($this->tables)) {
88 $this->warnings[] = $this->
lng->txt(
'dcl_file_not_readable');
91 if (count($this->warnings)) {
95 for ($sheet = 0; $sheet < $sheet_count; $sheet++) {
96 $excel->setActiveSheet($sheet);
97 $table = $this->tables[$sheet];
100 $sheet_title = substr($table->getTitle(), 0, 31);
101 if ($excel->getSheetTitle() != $sheet_title) {
102 $this->warnings[] = $this->
lng->txt(
'dcl_table_title_not_matching');
107 $sheet_data = $excel->getSheetAsArray();
109 foreach ($sheet_data[0] as $column) {
110 $field_names[] = $column;
115 for (
$i = 2;
$i <= count($sheet_data);
$i++) {
117 $record->setOwner($this->
user->getId());
119 $record->setCreateDate($date_obj);
120 $record->setLastUpdate($date_obj);
121 $record->setLastEditBy($this->
user->getId());
122 $record->setTableId($table->getId());
127 foreach ($fields as $col => $field) {
129 if ($field->isStandardField()) {
130 $record->setStandardFieldValueFromExcel($excel,
$i, $col, $field);
132 $value = $record->getRecordFieldValueFromExcel($excel,
$i, $col, $field);
134 if (is_array($value) && isset($value[
'warning'])) {
135 $this->warnings[] = $value[
'warning'];
139 $field->checkValidity($value, $record->getId());
141 $record->setRecordFieldValue($field->getId(), $value);
150 if ($fields_failed < count($fields)) {
151 $record_imported =
true;
154 $record_imported =
false;
158 if (!$record_imported) {
159 $record->doDelete(
true);
164 if ((
$i - 1) - $records_failed > $this->max_imports) {
165 $this->warnings[] = $this->
lng->txt(
"dcl_max_import") . (count($sheet_data) - 1) .
" > " . $this->max_imports;
171 return array(
'line' => ((
$i ?? 2) - 2),
'warnings' => $this->warnings);
179 $this->warnings[] = $field->
getTitle() .
": " . $this->
lng->txt(
"dcl_not_supported_in_import");
192 $import_fields = array();
193 foreach ($fields as $field) {
196 $field->checkTitlesForImport($titles, $import_fields);
200 foreach ($titles as
$key => $value) {
203 foreach ($importable_titles as $identifier => $values) {
204 if (in_array($value, $values)) {
206 $std_field->setId(substr($identifier, 4));
207 $import_fields[
$key] = $std_field;
211 if (in_array($value, $not_importable_titles)) {
214 if (!isset($import_fields[
$key])) {
220 return $import_fields;
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getNonImportableStandardFieldTitles()
const INPUTFORMAT_BOOLEAN
__construct(int $ref_id, ?int $table_id=null)
array $supported_import_datatypes
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const INPUTFORMAT_TEXT_SELECTION
const INPUTFORMAT_DATE_SELECTION
int $ref_id
Ref-ID of DataCollection.
static _getImportableStandardFieldTitle()
getImportFieldsFromTitles(ilDclTable $table, array $titles)
getRecordFields()
Returns all fields of this table which are NOT standard fields.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const INPUTFORMAT_DATETIME
int $table_id
Table-Id for export.
const INPUTFORMAT_REFERENCE
static getExcelCharForInteger(int $int)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkImportType(ilDclBaseFieldModel $field)
getDatatypeId()
Get datatype_id.