Skip to content

Commit

Permalink
AdvMD: fix creation of (multi) select fields for plugins (37217)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Jun 24, 2024
1 parent 27a55df commit b1f8a01
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ public static function createDBField(
return null;
}

$options_in_different_table = $a_definition &&
($a_type === ilAdvancedMDFieldDefinition::TYPE_SELECT ||
$a_type === ilAdvancedMDFieldDefinition::TYPE_SELECT_MULTI);

$pos = self::getDBFieldLastPosition($a_record_id) + 1;

$fields = array(
Expand All @@ -229,11 +233,44 @@ public static function createDBField(
"description" => array("text", trim((string) $a_description)),
"searchable" => array("integer", (int) $a_searchable)
);
if ($a_definition) {
if ($a_definition && !$options_in_different_table) {
$fields["field_values"] = array("text", serialize($a_definition));
}
$ilDB->insert("adv_mdf_definition", $fields);

if ($options_in_different_table) {
$ilDB->manipulate(
'DELETE FROM adv_mdf_enum WHERE field_id = ' .
$ilDB->quote($field_id, ilDBConstants::T_INTEGER)
);

$default_language = '';
$res = $ilDB->query(
'SELECT lang_default FROM adv_md_record WHERE record_id = ' .
$ilDB->quote($a_record_id, 'integer')
);
if ($row = $res->fetchAssoc()) {
$default_language = (string) $row['lang_default'];
}

$idx = 0;
foreach ($a_definition as $option) {
if (!is_string($option)) {
continue;
}
$ilDB->insert(
'adv_mdf_enum',
[
'field_id' => [ilDBConstants::T_INTEGER, $field_id],
'lang_code' => [ilDBConstants::T_TEXT, $default_language],
'idx' => [ilDBConstants::T_INTEGER, $idx],
'value' => [ilDBConstants::T_TEXT, $option],
]
);
$idx++;
}
}

return $field_id;
}

Expand Down

0 comments on commit b1f8a01

Please sign in to comment.