19declare(strict_types=1);
 
   49        return (
string) $a_adt_search->getADT()->getSelection();
 
   55        $def->setNumeric(
false);
 
   58        $translated_options = [];
 
   62        $def->setOptions(array_replace(
$options, $translated_options));
 
   68        if ($a_values !== 
null) {
 
   69            foreach ($a_values as $idx => $value) {
 
   70                $a_values[$idx] = trim($value);
 
   71                if (!$a_values[$idx]) {
 
   72                    unset($a_values[$idx]);
 
   75            $a_values = array_unique($a_values);
 
   77        $this->options = $a_values;
 
  100        $this->option_translations = $translations;
 
  105        $this->option_translations[
$language] = $translations;
 
  125        if (strlen($content_language)) {
 
  137        bool $a_disabled = 
false,
 
  159        $field = new 
ilTextInputGUI($this->
lng->txt(
'meta_advmd_select_options'), 
'opts_new');
 
  161        $field->setMulti(
true);
 
  162        $field->setMaxLength(255);
 
  163        $field->setDisabled($a_disabled);
 
  174            $this->
lng->txt(
'meta_advmd_select_options_edit'),
 
  178        $position_identifiers = [
'0' => $this->
lng->txt(
'meta_advmd_select_first_position_identifier')];
 
  180        foreach ($options as $idx => $option) {
 
  181            $position_identifiers[$idx + 1] = sprintf(
 
  182                $this->
lng->txt(
'meta_advmd_select_position_identifier'),
 
  185            $last_idx = $idx + 1;
 
  188        $options[$last_idx] = $this->
lng->txt(
'meta_advmd_select_new_option');
 
  190        $disabled_checkbox_overwrites = [];
 
  192        foreach ($options as $idx => $option) {
 
  196                $this->
lng->txt(
'meta_advmd_select_option_value'),
 
  199            $value->setRequired(
true);
 
  200            $value->setMaxLength(255);
 
  201            $value->setValue($idx !== $last_idx ? $option : 
'');
 
  202            $value->setDisabled($a_disabled);
 
  203            $radio->addSubItem($value);
 
  206                $this->
lng->txt(
'meta_advmd_select_option_position'),
 
  209            $relevant_position_identifiers = $position_identifiers;
 
  210            unset($relevant_position_identifiers[$idx + 1]);
 
  211            $position->setOptions($relevant_position_identifiers);
 
  212            $position->setValue($idx);
 
  213            $position->setDisabled($a_disabled);
 
  214            $radio->addSubItem($position);
 
  216            if ($idx !== $last_idx && $last_idx > 1) {
 
  218                    $this->
lng->txt(
'meta_advmd_select_delete_option'),
 
  221                $delete->setDisabled($a_disabled);
 
  222                $radio->addSubItem($delete);
 
  230                    $hidden->setValue(
"1");
 
  231                    $disabled_checkbox_overwrites[] = $hidden;
 
  235            $radio->setDisabled($a_disabled);
 
  236            $entries->addOption($radio);
 
  239        $entries->setDisabled($a_disabled);
 
  242        foreach ($disabled_checkbox_overwrites as $input) {
 
  250        string $language = 
'' 
  252        $default_language = 
ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id)->getDefaultLanguage();
 
  254        $translation = $this->getOptionTranslation($language);
 
  257        foreach ($this->getOptions() as 
$index => $option) {
 
  260                $title = $this->
lng->txt(
"meta_advmd_select_options");
 
  264                'opts__' . $language . 
'__' . 
$index 
  266            if (isset($translation[
$index])) {
 
  267                $text->setValue($translation[
$index]);
 
  269            $text->setInfo($default_language . 
': ' . $option);
 
  270            $text->setMaxLength(255);
 
  271            $text->setRequired(
true);
 
  284        $recipes = $a_form->
getInput(
"conf_det");
 
  285        if (is_array($recipes[$this->getFieldId()] ?? 
null)) {
 
  286            $recipes = $recipes[$this->getFieldId()];
 
  287            $sum = $a_form->
getInput(
"conf_det_act");
 
  288            $sum = $sum[$this->getFieldId()];
 
  290            $sgl = $sgl[$this->getFieldId()];
 
  293            foreach ($recipes as $old_option => $recipe) {
 
  294                $sum_act = $sum[$old_option];
 
  295                $sgl_act = $sgl[$old_option];
 
  297                if ($recipe == 
"sum") {
 
  303                    foreach (array_keys($sgl_act) as $obj_idx) {
 
  304                        if ($sum_act == self::REMOVE_ACTION_ID) {
 
  307                        if (substr($sum_act, 0, 4) == 
'idx_') {
 
  308                            $parts = explode(
'_', $sum_act);
 
  311                        $res[$old_option][$obj_idx] = $sum_act;
 
  315                    foreach ($sgl_act as $sgl_index => $sgl_item) {
 
  318                        } elseif ($sgl_item == self::REMOVE_ACTION_ID) {
 
  319                            $sgl_act[$sgl_index] = 
"";
 
  321                        if (substr($sgl_item, 0, 4) == 
'idx_') {
 
  322                            $parts = explode(
'_', $sgl_item);
 
  323                            $sgl_act[$sgl_index] = 
$parts[1];
 
  327                    $res[$old_option] = $sgl_act;
 
  337        $this->importNewSelectOptions(
true, $a_form, $language);
 
  343        string $language = 
'' 
  345        if (!$this->useDefaultLanguageMode($language)) {
 
  346            $this->importTranslatedFormPostValues($a_form, $language);
 
  350        if (!strlen($language)) {
 
  354        $old = $this->getOptionTranslation($language);
 
  355        if ($new = $a_form->
getInput(
'opts_new')) {
 
  356            $this->setOptions($new);
 
  357            $this->setOptionTranslationsForLanguage($new, $language);
 
  361        $edited_idx = $a_form->
getInput(
'opts_edit');
 
  362        if($edited_idx === 
'' || is_null($edited_idx)) {
 
  365        $edited_idx = (
int) $edited_idx;
 
  367        $new_value = (string) $a_form->
getInput(
'value_' . $edited_idx);
 
  368        $new_position = (
int) $a_form->
getInput(
'position_' . $edited_idx);
 
  369        $delete = (bool) $a_form->
getInput(
'delete_me_' . $edited_idx);
 
  382        if ($new_position > $edited_idx) {
 
  386        foreach ($old as $old_idx => $old_value) {
 
  387            if ($old_idx === $edited_idx) {
 
  391            if (!$delete && $new_idx === $new_position) {
 
  392                $new[$new_idx] = $new_value;
 
  397                if ($edited_idx !== $new_idx && array_key_exists($edited_idx, $old)) {
 
  398                    $index_map[$edited_idx] = $new_idx;
 
  403            $new[$new_idx] = $old_value;
 
  404            if ($old_idx !== $new_idx) {
 
  405                $index_map[$old_idx] = $new_idx;
 
  413        if (!$delete && $new_idx === $new_position) {
 
  414            $new[$new_idx] = $new_value;
 
  415            if ($edited_idx !== $new_idx) {
 
  416                $index_map[$edited_idx] = $new_idx;
 
  424        if ($delete || count($index_map)) {
 
  425            $this->confirmed_objects = $this->buildConfirmedObjects($a_form);
 
  426            $already_confirmed = is_array($this->confirmed_objects);
 
  429                $this->getADTDefinition(),
 
  439                $in_use = $this->findBySingleValue($search, $edited_idx);
 
  440                foreach ($in_use as $item) {
 
  441                    if (!$already_confirmed) {
 
  442                        $this->confirm_objects[$edited_idx][] = $item;
 
  443                        $this->confirm_objects_values[$edited_idx] = $old[$edited_idx];
 
  451            foreach ($index_map as $old_idx => $new_idx) {
 
  452                $in_use = $this->findBySingleValue($search, $old_idx);
 
  453                foreach ($in_use as $item) {
 
  454                    $complete_id = $item[0] . 
"_" . $item[1] . 
"_" . $item[2];
 
  455                    $this->confirmed_objects[$old_idx][$complete_id] = $new_idx;
 
  459        $this->old_options = $old;
 
  465        $this->setOptionTranslationsForLanguage($new, $language);
 
  466        $this->setOptions($new);
 
  467        foreach ($this->getOptionTranslations() as $current_lang => $options) {
 
  468            $current_lang = (string) $current_lang;
 
  469            if ($current_lang === $language) {
 
  472            $updated_translations = [];
 
  473            foreach ($options as $idx => $option) {
 
  474                if (array_key_exists($idx, $index_map)) {
 
  475                    $updated_translations[$index_map[$idx]] = $option;
 
  478                $updated_translations[$idx] = $option;
 
  480            $this->setOptionTranslationsForLanguage($updated_translations, $current_lang);
 
  493        $a_search->getADT()->setSelections((array) $a_value);
 
  503            foreach ($in_use as $item) {
 
  504                $res[] = array($item[
"obj_id"], $item[
"sub_type"], $item[
"sub_id"], $item[
"value_index"]);
 
  512        $translated_options = [];
 
  513        foreach ($this->getOptions() as $idx => $value) {
 
  514            $value = $form->
getInput(
'opts__' . $language . 
'__' . $idx);
 
  515            $translated_options[] = trim($value);
 
  517        $translations = $this->getOptionTranslations();
 
  518        $translations[$language] = $translated_options;
 
  519        $this->setOptionTranslations($translations);
 
  524        return is_array($this->confirm_objects) && count($this->confirm_objects) > 0;
 
  531        $objDefinition = 
$DIC[
'objDefinition'];
 
  533        $post_conf_det = (array) ($this->
http->request()->getParsedBody()[
'conf_det'] ?? []);
 
  534        $post_conf = (array) ($this->
http->request()->getParsedBody()[
'conf'] ?? []);
 
  537        $custom_field->setDisabled(
true);
 
  538        foreach ($custom_field->getSubInputItemsRecursive() as $sub_input) {
 
  539            $sub_input->setDisabled(
true);
 
  546                $hidden->setValue($sub_input->getValue());
 
  551        if (is_array($this->confirm_objects) && count($this->confirm_objects) > 0) {
 
  553            $sec->setTitle(
$lng->txt(
"md_adv_confirm_definition_select_section"));
 
  556            foreach ($this->confirm_objects as $old_option_index => $items) {
 
  557                $old_option_value = $this->confirm_objects_values[$old_option_index];
 
  559                    $lng->txt(
"md_adv_confirm_definition_select_option") . 
': "' . $old_option_value . 
'"',
 
  560                    "conf_det[" . $this->getFieldId() . 
"][" . $old_option_index . 
"]" 
  567                if (isset($post_conf_det[$this->getFieldId()][$old_option_index])) {
 
  568                    $details->setValue($post_conf_det[$this->getFieldId()][$old_option_index]);
 
  571                $sum = 
new ilRadioOption(
$lng->txt(
"md_adv_confirm_definition_select_option_all"), 
"sum");
 
  575                    $lng->txt(
"md_adv_confirm_definition_select_option_all_action"),
 
  576                    "conf_det_act[" . $this->getFieldId() . 
"][" . $old_option_index . 
"]" 
  578                $sel->setRequired(
true);
 
  580                    "" => 
$lng->txt(
"please_select"),
 
  581                    self::REMOVE_ACTION_ID => 
$lng->txt(
"md_adv_confirm_definition_select_option_remove")
 
  583                foreach ($this->getOptions() as $new_option_index => $new_option) {
 
  584                    $options[
'idx_' . $new_option_index] = 
$lng->txt(
"md_adv_confirm_definition_select_option_overwrite") . 
': "' . $new_option . 
'"';
 
  586                $sel->setOptions($options);
 
  587                $sum->addSubItem($sel);
 
  590                if (isset($post_conf_det[$this->getFieldId()][$old_option_index])) {
 
  591                    if ($post_conf_det[$this->getFieldId()][$old_option_index]) {
 
  592                        $sel->setValue($post_conf_det[$this->getFieldId()][$old_option_index]);
 
  593                    } elseif ($post_conf_det[$this->getFieldId()][$old_option_index] == 
"sum") {
 
  594                        $sel->setAlert(
$lng->txt(
"msg_input_is_required"));
 
  595                        $DIC->ui()->mainTemplate()->setOnScreenMessage(
'failure', 
$lng->txt(
"form_input_not_valid"));
 
  598                $single = 
new ilRadioOption(
$lng->txt(
"md_adv_confirm_definition_select_option_single"), 
"sgl");
 
  600                foreach ($items as $item) {
 
  601                    $obj_id = (
int) $item[0];
 
  602                    $sub_type = (string) $item[1];
 
  603                    $sub_id = (
int) $item[2];
 
  609                    if ($sub_type === 
'mob') {
 
  614                    $item_id = $obj_id . 
"_" . $sub_type . 
"_" . $sub_id;
 
  621                        $class = 
"ilObj" . $objDefinition->getClassName(
$type);
 
  622                        $class_path = $objDefinition->getLocation(
$type);
 
  623                        $ints = class_implements($class);
 
  624                        if (isset($ints[
"ilAdvancedMetaDataSubItems"])) {
 
  626                            $sub_title = $class::getAdvMDSubItemTitle($obj_id, $sub_type, $sub_id);
 
  628                                $title .= 
' (' . $sub_title . 
')';
 
  634                        $type_title . 
' ' . $title,
 
  635                        "conf[" . $this->getFieldId() . 
"][" . $old_option_index . 
"][" . $item_id . 
"]" 
  637                    $sel->setRequired(
true);
 
  639                        "" => 
$lng->txt(
"please_select"),
 
  640                        self::REMOVE_ACTION_ID => 
$lng->txt(
"md_adv_confirm_definition_select_option_remove")
 
  642                    foreach ($this->getOptions() as $new_option_index => $new_option) {
 
  643                        $options[
'idx_' . $new_option_index] = 
$lng->txt(
"md_adv_confirm_definition_select_option_overwrite") . 
': "' . $new_option . 
'"';
 
  645                    $sel->setOptions($options);
 
  648                    if (isset($post_conf[$this->getFieldId()][$old_option_index][$item_id])) {
 
  649                        if ($post_conf[$this->getFieldId()][$old_option_index][$item_id]) {
 
  650                            $sel->setValue($post_conf[$this->getFieldId()][$old_option_index][$item_id]);
 
  651                        } elseif ($post_conf_det[$this->getFieldId()][$old_option_index] == 
"sgl") {
 
  652                            $sel->setAlert(
$lng->txt(
"msg_input_is_required"));
 
  653                            $DIC->ui()->mainTemplate()->setOnScreenMessage(
'failure', 
$lng->txt(
"form_input_not_valid"));
 
  657                    $single->addSubItem($sel);
 
  663    public function delete(): 
void 
  665        $this->deleteOptionTranslations();
 
  669    public function save(
bool $a_keep_pos = 
false): void
 
  671        parent::save($a_keep_pos);
 
  672        $this->saveOptionTranslations();
 
  677        $query = 
'delete from adv_mdf_enum ' .
 
  679        $this->db->manipulate(
$query);
 
  684        $this->deleteOptionTranslations();
 
  685        $this->saveOptionTranslations();
 
  690        $options = $this->getOptionTranslations();
 
  695        if (empty($options)) {
 
  697            $options = [$record->getDefaultLanguage() => $this->getOptions()];
 
  699        foreach ($options as $lang_key => $options_in_lang) {
 
  700            foreach ($options_in_lang as $idx => $option) {
 
  701                $query = 
'insert into adv_mdf_enum (field_id, lang_code, idx, value )' .
 
  708                $this->db->manipulate(
$query);
 
  715        if (is_array($this->confirmed_objects) && count($this->confirmed_objects) > 0) {
 
  717            $def = $this->getADTDefinition();
 
  719            $def->setOptions($this->old_options);
 
  723            $page_list_mappings = [];
 
  725            foreach ($this->confirmed_objects as $old_option => $item_ids) {
 
  727                $old_values = array();
 
  728                foreach ($this->findBySingleValue($search, $old_option) as $item) {
 
  729                    $old_values[$item[0] . 
"_" . $item[1] . 
"_" . $item[2]] = $item[3];
 
  732                foreach ($item_ids as $item => $new_option) {
 
  733                    $parts = explode(
"_", $item);
 
  739                    if (isset($old_values[$item])) {
 
  740                        $old_value = $old_values[$item];
 
  748                        $old_idx = $old_value;
 
  749                        if (isset($old_idx)) {
 
  751                                "obj_id" => array(
"integer", $obj_id),
 
  752                                "sub_type" => array(
"text", $sub_type),
 
  753                                "sub_id" => array(
"integer", $sub_id),
 
  754                                "field_id" => array(
"integer", $this->getFieldId())
 
  757                            $index_old = array_merge(
 
  763                            $index_new = array_merge(
 
  771                            if (is_numeric($new_option)) {
 
  779                    if ($sub_type == 
"wpg") {
 
  781                        $page_list_mappings[(string) $old_option] = (
string) $new_option;
 
  786            if (!empty($page_list_mappings)) {
 
  793            $this->confirmed_objects = array();
 
  797        $this->updateOptionTranslations();
 
  802        foreach ($this->getOptions() as $value) {
 
  803            $a_writer->
xmlElement(
'FieldValue', 
null, $value);
 
  805        foreach ($this->getOptionTranslations() as $lang_key => $translations) {
 
  806            foreach ((array) $translations as $value) {
 
  807                $a_writer->
xmlElement(
'FieldValue', [
'id' => $lang_key], $value);
 
  815            $this->options[] = $a_value;
 
  817            $this->option_translations[$a_key][] = $a_value;
 
  823        return $element->getSelection();
 
  828        $a_cdata = $this->translateLegacyImportValueFromXML($a_cdata);
 
  829        $this->getADT()->setSelection($a_cdata);
 
  844            !in_array($value, array_keys($this->options)) &&
 
  845            in_array($value, $this->options)
 
  847            $value = (string) array_search($value, $this->options);
 
  856        $a_bridge->setAutoSort(
false);
 
  859    protected function import(array $a_data): 
void 
  861        parent::import($a_data);
 
  863        $query = 
'select * from adv_mdf_enum ' .
 
  871            if ($row->lang_code == $record->getDefaultLanguage()) {
 
  872                $default[(
int) $row->idx] = (
string) $row->value;
 
  874            $options[(string) $row->lang_code][(
int) $row->idx] = (string) $row->value;
 
  876        $this->setOptions($default);
 
  877        $this->setOptionTranslations($options);
 
  880    public function _clone(
int $a_new_record_id): self
 
  883        $obj = parent::_clone($a_new_record_id);
 
  884        $query = 
'select * from adv_mdf_enum ' .
 
  892            if ($row->lang_code == $record->getDefaultLanguage()) {
 
  893                $default[(
int) $row->idx] = (
string) $row->value;
 
  895            $options[(string) $row->lang_code][(
int) $row->idx] = (string) $row->value;
 
  897        $obj->setOptions($default);
 
  898        $obj->setOptionTranslations($options);
 
static find(string $a_table, string $a_type, int $a_field_id, string $a_condition, ?string $a_additional_fields=null)
Find entries.
 
static create(string $table, array $fields, string $type)
 
static deleteByPrimary(string $a_table, array $a_primary, string $a_type=null)
 
ADT definition base class.
 
static initActiveRecordByType()
Init active record by type.
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
 
importTranslatedFormPostValues(ilPropertyFormGUI $form, string $language)
 
addCustomFieldToDefinitionFormInTranslationMode(ilPropertyFormGUI $form, bool $disabled, string $language='')
 
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Get value for search query parser.
 
updateOptionTranslations()
 
importValueFromXML(string $a_cdata)
Import value from xml.
 
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, bool $a_disabled=false, string $language='')
Add custom input elements to definition form.
 
array $confirm_objects_values
 
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
 
addCreateOptionsFieldsToDefinitionForm(ilPropertyFormGUI $a_form, bool $a_disabled)
 
prepareCustomDefinitionFormConfirmation(ilPropertyFormGUI $a_form)
 
getOptionTranslation(string $language)
 
importXMLProperty(string $a_key, string $a_value)
Import property from XML.
 
setOptions(array $a_values=null)
 
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
 
importDefinitionFormPostValuesNeedsConfirmation()
 
array $option_translations
 
importNewSelectOptions(bool $multi, ilPropertyFormGUI $a_form, string $language='')
 
addEditOptionsFieldsToDefinitionForm(array $options, ilPropertyFormGUI $a_form, bool $a_disabled)
 
setOptionTranslations(array $translations)
 
update()
Update field entry.
 
prepareElementForEditor(ilADTFormBridge $a_bridge)
Prepare editor form elements.
 
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
 
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
 
save(bool $a_keep_pos=false)
Create new field entry.
 
translateLegacyImportValueFromXML(string $value)
On import from <7 options are not given by index but by their label.
 
getFieldDefinition()
Get (type-specific) field definition.
 
__construct(?int $a_field_id=null, string $language='')
 
initADTDefinition()
Init adt instance.
 
setOptionTranslationsForLanguage(array $translations, string $language)
 
buildConfirmedObjects(ilPropertyFormGUI $a_form)
Process custom post values from definition form.
 
deleteOptionTranslations()
 
findBySingleValue(ilADTSearchBridge $a_search, $a_value)
 
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
 
AMD field abstract base class.
 
useDefaultLanguageMode(string $language)
Check if default language mode has to be used: no language given or language equals default language.
 
static _getInstanceByRecordId(int $a_record_id)
 
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
 
static _lookupType(int $id, bool $reference=false)
 
static _lookupTitle(int $obj_id)
 
static migrateField(int $a_field_id, array $mapping)
Migrate search/filter values on advmd change.
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
This class represents a text property in a property form.
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
 
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
 
static http()
Fetches the global http state from ILIAS.
 
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc