ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAdvancedMDFieldDefinitionSelect Class Reference

AMD field type select. More...

+ Inheritance diagram for ilAdvancedMDFieldDefinitionSelect:
+ Collaboration diagram for ilAdvancedMDFieldDefinitionSelect:

Public Member Functions

 getType ()
 
 getSearchQueryParserValue (ilADTSearchBridge $search_bridge)
 
 setOptions (array $a_values=null)
 Set options. More...
 
 getOptions ()
 Get options. More...
 
 getOptionTranslations ()
 
 getOptionTranslation (string $language)
 
 setOptionTranslations (array $translations)
 
 setOptionTranslationsForLanguage (array $translations, string $language)
 
 getFieldDefinitionForTableGUI (string $content_language)
 
 importCustomDefinitionFormPostValues (ilPropertyFormGUI $a_form, string $language='')
 Import custom post values from definition form. More...
 
 importDefinitionFormPostValuesNeedsConfirmation ()
 
 prepareCustomDefinitionFormConfirmation (ilPropertyFormGUI $a_form)
 
 delete ()
 
 save ($a_keep_pos=false)
 
 update ()
 
 importXMLProperty ($a_key, $a_value)
 
 getValueForXML (ilADT $element)
 
 importValueFromXML ($a_cdata)
 
 prepareElementForEditor (ilADTFormBridge $a_enum)
 
 _clone ($a_new_record_id)
 
- Public Member Functions inherited from ilAdvancedMDFieldDefinition
 __construct ($a_field_id=null, string $language='')
 Constructor. More...
 
 getType ()
 Get type. More...
 
 useDefaultLanguageMode (string $language)
 Check if default language mode has to be used: no language given or language equals default language. More...
 
 getTypeTitle ()
 Get type title (lang id) More...
 
 getADTDefinition ()
 Get ADT definition instance. More...
 
 getADT ()
 Get ADT instance. More...
 
 getFieldId ()
 Get field_id. More...
 
 setRecordId ($a_id)
 Set record id. More...
 
 getRecordId ()
 Get record id. More...
 
 setImportId ($a_id_string)
 Set import id. More...
 
 getImportId ()
 Get import id. More...
 
 setPosition ($a_pos)
 Set position. More...
 
 getPosition ()
 Get position. More...
 
 setTitle ($a_title)
 Get title. More...
 
 getTitle ()
 Get title. More...
 
 setDescription ($a_desc)
 Set description. More...
 
 getDescription ()
 Get description. More...
 
 isSearchSupported ()
 Is search supported at all. More...
 
 isFilterSupported ()
 Is search by filter supported. More...
 
 setSearchable ($a_status)
 Toggle searchable. More...
 
 isSearchable ()
 Is searchable. More...
 
 setRequired ($a_status)
 Toggle required. More...
 
 isRequired ()
 Is required field. More...
 
 getFieldDefinitionForTableGUI (string $content_language)
 Parse properties for table gui. More...
 
 addToFieldDefinitionForm (ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $language='')
 Add input elements to definition form. More...
 
 importCustomDefinitionFormPostValues (ilPropertyFormGUI $a_form, string $language='')
 Import custom post values from definition form. More...
 
 importDefinitionFormPostValues (ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $active_language)
 Import post values from definition form. More...
 
 importDefinitionFormPostValuesNeedsConfirmation ()
 
 prepareCustomDefinitionFormConfirmation (ilPropertyFormGUI $a_form)
 
 prepareDefinitionFormConfirmation (ilPropertyFormGUI $a_form)
 
 generateImportId ($a_field_id)
 Generate unique record id. More...
 
 save ($a_keep_pos=false)
 Create new field entry. More...
 
 update ()
 Update field entry. More...
 
 delete ()
 Delete field entry. More...
 
 toXML (ilXmlWriter $a_writer)
 To Xml. More...
 
 importXMLProperty ($a_key, $a_value)
 Import property from XML. More...
 
 getValueForXML (ilADT $element)
 Parse ADT value for xml (export) More...
 
 importValueFromXML ($a_cdata)
 Import value from xml. More...
 
 importFromECS ($a_ecs_type, $a_value, $a_sub_id)
 Import meta data from ECS. More...
 
 prepareElementForEditor (ilADTFormBridge $a_bridge)
 Prepare editor form elements. More...
 
 getSearchQueryParserValue (ilADTSearchBridge $a_adt_search)
 Get value for search query parser. More...
 
 getSearchValueSerialized (ilADTSearchBridge $a_adt_search)
 Get value for search persistence. More...
 
 setSearchValueSerialized (ilADTSearchBridge $a_adt_search, $a_value)
 Set value from search persistence. More...
 
 searchSubObjects (ilADTSearchBridge $a_adt_search, $a_obj_id, $sub_obj_type)
 
 searchObjects (ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
 Search objects. More...
 
 getLuceneSearchString ($a_value)
 Get search string in lucene syntax. More...
 
 prepareElementForSearch (ilADTSearchBridge $a_bridge)
 Prepare search form elements. More...
 
 _clone ($a_new_record_id)
 Clone field definition. More...
 
 hasComplexOptions ()
 
 getComplexOptionsOverview ($a_parent_gui, string $parent_cmd)
 

Data Fields

const REMOVE_ACTION_ID = "-iladvmdrm-"
 
- Data Fields inherited from ilAdvancedMDFieldDefinition
const TYPE_SELECT = 1
 
const TYPE_TEXT = 2
 
const TYPE_DATE = 3
 
const TYPE_DATETIME = 4
 
const TYPE_INTEGER = 5
 
const TYPE_FLOAT = 6
 
const TYPE_LOCATION = 7
 
const TYPE_SELECT_MULTI = 8
 
const TYPE_ADDRESS = 99
 
const TYPE_EXTERNAL_LINK = 9
 
const TYPE_INTERNAL_LINK = 10
 

Protected Member Functions

 initADTDefinition ()
 
 importFieldDefinition (array $a_def)
 
 getFieldDefinition ()
 
 addCustomFieldToDefinitionForm (ilPropertyFormGUI $a_form, $a_disabled=false, string $language='')
 Add input elements to definition form. More...
 
 addCustomFieldToDefinitionFormInTranslationMode (ilPropertyFormGUI $form, bool $disabled, string $language='')
 
 buildConfirmedObjects (ilPropertyFormGUI $a_form)
 Process custom post values from definition form. More...
 
 importNewSelectOptions (bool $multi, ilPropertyFormGUI $a_form, string $language='')
 
 findBySingleValue (ilADTEnumSearchBridgeMulti $a_search, $a_value)
 
 importTranslatedFormPostValues (ilPropertyFormGUI $form, string $language)
 
 deleteOptionTranslations ()
 
 updateOptionTranslations ()
 
 saveOptionTranslations ()
 
 addPropertiesToXML (ilXmlWriter $a_writer)
 
 import (array $db_data)
 
- Protected Member Functions inherited from ilAdvancedMDFieldDefinition
 init ()
 Init properties. More...
 
 initADTDefinition ()
 Init adt instance. More...
 
 setADT (ilADT $a_adt)
 Set ADT instance. More...
 
 setFieldId ($a_id)
 Set field_id. More...
 
 importFieldDefinition (array $a_def)
 Import (type-specific) field definition from DB. More...
 
 getFieldDefinition ()
 Get (type-specific) field definition. More...
 
 addCustomFieldToDefinitionForm (ilPropertyFormGUI $a_form, $a_disabled=false, string $language='')
 Add custom input elements to definition form. More...
 
 getLastPosition ()
 Get last position of record. More...
 
 getDBProperties ()
 Get all definition properties for DB. More...
 
 import (array $a_data)
 Import from DB. More...
 
 read ($a_field_id)
 Read field definition. More...
 
 addPropertiesToXML (ilXmlWriter $a_writer)
 Add (type-specific) properties to xml export. More...
 
 parseSearchObjects (array $a_records, array $a_object_types)
 Add object-data needed for global search to AMD search results. More...
 

Protected Attributes

 $options = []
 
 $confirm_objects = []
 
 $confirm_objects_values = []
 
 $confirmed_objects
 
 $option_translations = []
 
- Protected Attributes inherited from ilAdvancedMDFieldDefinition
 $field_id
 
 $record_id
 
 $import_id
 
 $position
 
 $title
 
 $description
 
 $searchable
 
 $required
 
 $adt_def
 
 $adt
 
 $language = ''
 
 $logger
 

Additional Inherited Members

- Static Public Member Functions inherited from ilAdvancedMDFieldDefinition
static getInstance ($a_field_id, $a_type=null, string $language='')
 Get definition instance by type. More...
 
static exists ($a_field_id)
 Check if field exists. More...
 
static getInstanceByTypeString ($a_type)
 Get instance by type string (used by import) More...
 
static getInstancesByRecordId ($a_record_id, $a_only_searchable=false, string $language='')
 Get definitions by record id. More...
 
static getInstancesByObjType ($a_obj_type, $a_active_only=true)
 
static getInstanceByImportId ($a_import_id)
 Get definition instance by import id. More...
 
static getSearchableDefinitionIds ()
 Get searchable definition ids (performance is key) More...
 
static getADTGroupForDefinitions (array $a_defs)
 Init ADTGroup for definitions. More...
 
static getValidTypes ()
 Get all valid types. More...
 
static isValidType ($a_type)
 Is given type valid. More...
 
- Static Protected Member Functions inherited from ilAdvancedMDFieldDefinition
static getTypeString ($a_type)
 Get type string. More...
 

Detailed Description

AMD field type select.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 14 of file class.ilAdvancedMDFieldDefinitionSelect.php.

Member Function Documentation

◆ _clone()

ilAdvancedMDFieldDefinitionSelect::_clone (   $a_new_record_id)
Parameters
int$a_new_record_id
Returns
ilAdvancedMDFieldDefinition

Definition at line 752 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $DIC, $options, $query, $res, ilAdvancedMDRecord\_getInstanceByRecordId(), ilDBConstants\FETCHMODE_OBJECT, ilAdvancedMDFieldDefinition\getFieldId(), ilAdvancedMDFieldDefinition\getRecordId(), and ilDBConstants\T_INTEGER.

753  {
754  global $DIC;
755 
756  $db = $DIC->database();
757 
758  $obj = parent::_clone($a_new_record_id);
759  $query = 'select * from adv_mdf_enum ' .
760  'where field_id = ' . $db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' ' .
761  'order by idx';
762  $res = $db->query($query);
763  $options = [];
764  $default = [];
766  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
767  if ($row->lang_code == $record->getDefaultLanguage()) {
768  $default[$row->idx] = $row->value;
769  }
770  $options[$row->lang_code][$row->idx] = $row->value;
771  }
772  $obj->setOptions($default);
773  $obj->setOptionTranslations($options);
774  $obj->update();
775  return $obj;
776  }
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
$query
+ Here is the call graph for this function:

◆ addCustomFieldToDefinitionForm()

ilAdvancedMDFieldDefinitionSelect::addCustomFieldToDefinitionForm ( ilPropertyFormGUI  $a_form,
  $a_disabled = false,
string  $language = '' 
)
protected

Add input elements to definition form.

Parameters
ilPropertyFormGUI$a_form
bool$a_disabled
string$language
Exceptions
ilFormException

Definition at line 169 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $DIC, ilAdvancedMDFieldDefinition\$language, $lng, $options, addCustomFieldToDefinitionFormInTranslationMode(), ilPropertyFormGUI\addItem(), getOptions(), and ilAdvancedMDFieldDefinition\useDefaultLanguageMode().

170  {
171  global $DIC;
172 
173  $lng = $DIC['lng'];
174 
175  if (!$this->useDefaultLanguageMode($language)) {
176  return $this->addCustomFieldToDefinitionFormInTranslationMode($a_form, $a_disabled, $language);
177  }
178 
179  // if not the default language is chosen => no add/remove; no sorting
180  $field = new ilTextInputGUI($lng->txt("meta_advmd_select_options"), "opts");
181  $field->setRequired(true);
182  $field->setMulti(true, true);
183  $field->setMaxLength(255); // :TODO:
184  $a_form->addItem($field);
185 
186  $options = $this->getOptions();
187  if ($options) {
188  $field->setMultiValues($options);
189  $field->setValue(array_shift($options));
190  }
191 
192  if ($a_disabled) {
193  $field->setDisabled(true);
194  }
195  }
addCustomFieldToDefinitionFormInTranslationMode(ilPropertyFormGUI $form, bool $disabled, string $language='')
addItem($a_item)
Add Item (Property, SectionHeader).
$lng
global $DIC
Definition: goto.php:24
useDefaultLanguageMode(string $language)
Check if default language mode has to be used: no language given or language equals default language...
+ Here is the call graph for this function:

◆ addCustomFieldToDefinitionFormInTranslationMode()

ilAdvancedMDFieldDefinitionSelect::addCustomFieldToDefinitionFormInTranslationMode ( ilPropertyFormGUI  $form,
bool  $disabled,
string  $language = '' 
)
protected
Parameters
ilPropertyFormGUI$form
bool$disabled
string$language

Definition at line 202 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $DIC, $index, ilAdvancedMDFieldDefinition\$language, $lng, ilAdvancedMDFieldDefinition\$title, ilAdvancedMDRecord\_getInstanceByRecordId(), ilPropertyFormGUI\addItem(), getOptions(), and getOptionTranslation().

Referenced by addCustomFieldToDefinitionForm().

203  {
204  global $DIC;
205 
206  $lng = $DIC->language();
207 
208  $default_language = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id)->getDefaultLanguage();
209 
210  $translation = $this->getOptionTranslation($language);
211 
212  $first = true;
213  foreach ($this->getOptions() as $index => $option) {
214  $title = '';
215  if ($first) {
216  $title = $lng->txt("meta_advmd_select_options");
217  }
218  $text = new ilTextInputGUI($title, 'opts__' . $language . '__' . (string) $index);
219  if (isset($translation[$index])) {
220  $text->setValue($translation[$index]);
221  };
222  $text->setInfo($default_language . ': ' . $option);
223  $text->setMaxLength(255);
224  $text->setRequired(true);
225 
226  $first = false;
227  $form->addItem($text);
228  }
229  }
addItem($a_item)
Add Item (Property, SectionHeader).
$index
Definition: metadata.php:128
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
$lng
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addPropertiesToXML()

ilAdvancedMDFieldDefinitionSelect::addPropertiesToXML ( ilXmlWriter  $a_writer)
protected

Definition at line 672 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References getOptions(), getOptionTranslations(), and ilXmlWriter\xmlElement().

673  {
674  foreach ($this->getOptions() as $value) {
675  $a_writer->xmlElement('FieldValue', null, $value);
676  }
677  foreach ($this->getOptionTranslations() as $lang_key => $translations) {
678  foreach ((array) $translations as $value) {
679  $a_writer->xmlElement('FieldValue', ['id' => $lang_key], $value);
680  }
681  }
682  }
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:

◆ buildConfirmedObjects()

ilAdvancedMDFieldDefinitionSelect::buildConfirmedObjects ( ilPropertyFormGUI  $a_form)
protected

Process custom post values from definition form.

Parameters
ilPropertyFormGUI$a_form

Definition at line 236 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $res, ilAdvancedMDFieldDefinition\getFieldId(), and ilPropertyFormGUI\getInput().

Referenced by importNewSelectOptions().

237  {
238  // #15719
239  $recipes = $a_form->getInput("conf_det");
240  if (is_array($recipes[$this->getFieldId()])) {
241  $recipes = $recipes[$this->getFieldId()];
242  $sum = $a_form->getInput("conf_det_act");
243  $sum = $sum[$this->getFieldId()];
244  $sgl = $a_form->getInput("conf");
245  $sgl = $sgl[$this->getFieldId()];
246 
247  $res = array();
248  foreach ($recipes as $old_option => $recipe) {
249  $sum_act = $sum[$old_option];
250  $sgl_act = $sgl[$old_option];
251 
252  if ($recipe == "sum") {
253  // #18885
254  if (!$sum_act) {
255  return;
256  }
257 
258  foreach (array_keys($sgl_act) as $obj_idx) {
259  if ($sum_act == self::REMOVE_ACTION_ID) {
260  $sum_act = "";
261  }
262  if (substr($sum_act, 0, 4) == 'idx_') {
263  $parts = explode('_', $sum_act);
264  $sum_act = $parts[1];
265  }
266  $res[$old_option][$obj_idx] = $sum_act;
267  }
268  } else {
269  // #18885
270  foreach ($sgl_act as $sgl_index => $sgl_item) {
271  if (!$sgl_item) {
272  return;
273  } elseif ($sgl_item == self::REMOVE_ACTION_ID) {
274  $sgl_act[$sgl_index] = "";
275  }
276  if (substr($sgl_item, 0, 4) == 'idx_') {
277  $parts = explode('_', $sgl_item);
278  $sgl_act[$sgl_index] = $parts[1];
279  }
280  }
281 
282  $res[$old_option] = $sgl_act;
283  }
284  }
285  return $res;
286  }
287  }
foreach($_POST as $key=> $value) $res
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete()

ilAdvancedMDFieldDefinitionSelect::delete ( )

Definition at line 522 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References deleteOptionTranslations().

523  {
524  $this->deleteOptionTranslations();
525  parent::delete();
526  }
+ Here is the call graph for this function:

◆ deleteOptionTranslations()

ilAdvancedMDFieldDefinitionSelect::deleteOptionTranslations ( )
protected

Definition at line 537 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $DIC, $query, ilAdvancedMDFieldDefinition\getFieldId(), and ilDBConstants\T_INTEGER.

Referenced by delete(), and updateOptionTranslations().

538  {
539  global $DIC;
540 
541  $db = $DIC->database();
542  $query = 'delete from adv_mdf_enum ' .
543  'where field_id = ' . $db->quote($this->getFieldId(), ilDBConstants::T_INTEGER);
544  $db->manipulate($query);
545  }
global $DIC
Definition: goto.php:24
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ findBySingleValue()

ilAdvancedMDFieldDefinitionSelect::findBySingleValue ( ilADTEnumSearchBridgeMulti  $a_search,
  $a_value 
)
protected

Definition at line 369 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $res, ilADTActiveRecordByType\find(), ilADTSearchBridgeSingle\getADT(), ilAdvancedMDFieldDefinition\getFieldId(), and ilADTEnumSearchBridgeMulti\getSQLCondition().

Referenced by importNewSelectOptions(), and update().

370  {
371  $res = array();
372  $a_search->getADT()->setSelections((array) $a_value);
373  $condition = $a_search->getSQLCondition('value_index');
374 
376  "adv_md_values",
377  "Enum",
378  $this->getFieldId(),
379  $condition
380  );
381  if ($in_use) {
382  foreach ($in_use as $item) {
383  $res[] = array($item["obj_id"], $item["sub_type"], $item["sub_id"], $item["value_index"]);
384  }
385  }
386 
387  return $res;
388  }
static find($a_table, $a_type, $a_field_id, $a_condition, $a_additional_fields=null)
Find entries.
foreach($_POST as $key=> $value) $res
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldDefinition()

ilAdvancedMDFieldDefinitionSelect::getFieldDefinition ( )
protected
Returns
array

Definition at line 141 of file class.ilAdvancedMDFieldDefinitionSelect.php.

142  {
143  return [];
144  }

◆ getFieldDefinitionForTableGUI()

ilAdvancedMDFieldDefinitionSelect::getFieldDefinitionForTableGUI ( string  $content_language)

Definition at line 146 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $DIC, $lng, $options, getOptions(), and getOptionTranslation().

147  {
148  global $DIC;
149 
150  $lng = $DIC['lng'];
151 
152  if (strlen($content_language)) {
153  $options = $this->getOptionTranslation($content_language);
154  } else {
155  $options = $this->getOptions();
156  }
157  return [
158  $lng->txt("meta_advmd_select_options") => implode(",", $options)
159  ];
160  }
$lng
global $DIC
Definition: goto.php:24
+ Here is the call graph for this function:

◆ getOptions()

◆ getOptionTranslation()

ilAdvancedMDFieldDefinitionSelect::getOptionTranslation ( string  $language)
Parameters
string$language

Definition at line 104 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilAdvancedMDFieldDefinition\$language, and getOptionTranslations().

Referenced by addCustomFieldToDefinitionFormInTranslationMode(), getFieldDefinitionForTableGUI(), and importNewSelectOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOptionTranslations()

◆ getSearchQueryParserValue()

ilAdvancedMDFieldDefinitionSelect::getSearchQueryParserValue ( ilADTSearchBridge  $search_bridge)

Definition at line 36 of file class.ilAdvancedMDFieldDefinitionSelect.php.

37  {
38  return $search_bridge->getADT()->getSelection();
39  }

◆ getType()

ilAdvancedMDFieldDefinitionSelect::getType ( )

Definition at line 30 of file class.ilAdvancedMDFieldDefinitionSelect.php.

31  {
32  return self::TYPE_SELECT;
33  }

◆ getValueForXML()

ilAdvancedMDFieldDefinitionSelect::getValueForXML ( ilADT  $element)

Definition at line 702 of file class.ilAdvancedMDFieldDefinitionSelect.php.

703  {
704  return $element->getSelection();
705  }

◆ import()

ilAdvancedMDFieldDefinitionSelect::import ( array  $db_data)
protected

Definition at line 724 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $DIC, $options, $query, $res, ilAdvancedMDRecord\_getInstanceByRecordId(), ilDBConstants\FETCHMODE_OBJECT, ilAdvancedMDFieldDefinition\getFieldId(), ilAdvancedMDFieldDefinition\getRecordId(), setOptions(), setOptionTranslations(), and ilDBConstants\T_INTEGER.

725  {
726  global $DIC;
727 
728  parent::import($db_data);
729 
730  $db = $DIC->database();
731  $query = 'select * from adv_mdf_enum ' .
732  'where field_id = ' . $db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ' ' .
733  'order by idx';
734  $res = $db->query($query);
735  $options = [];
736  $default = [];
738  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
739  if ($row->lang_code == $record->getDefaultLanguage()) {
740  $default[$row->idx] = $row->value;
741  }
742  $options[$row->lang_code][$row->idx] = $row->value;
743  }
744  $this->setOptions($default);
746  }
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
foreach($_POST as $key=> $value) $res
global $DIC
Definition: goto.php:24
$query
+ Here is the call graph for this function:

◆ importCustomDefinitionFormPostValues()

ilAdvancedMDFieldDefinitionSelect::importCustomDefinitionFormPostValues ( ilPropertyFormGUI  $a_form,
string  $language = '' 
)

Import custom post values from definition form.

Parameters
ilPropertyFormGUI$a_form
string$language

Definition at line 294 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilAdvancedMDFieldDefinition\$language, and importNewSelectOptions().

295  {
296  $this->importNewSelectOptions(true, $a_form, $language);
297  }
importNewSelectOptions(bool $multi, ilPropertyFormGUI $a_form, string $language='')
+ Here is the call graph for this function:

◆ importDefinitionFormPostValuesNeedsConfirmation()

ilAdvancedMDFieldDefinitionSelect::importDefinitionFormPostValuesNeedsConfirmation ( )

Definition at line 407 of file class.ilAdvancedMDFieldDefinitionSelect.php.

408  {
409  return is_array($this->confirm_objects) && count($this->confirm_objects) > 0;
410  }

◆ importFieldDefinition()

ilAdvancedMDFieldDefinitionSelect::importFieldDefinition ( array  $a_def)
protected
Parameters
array$a_def

Definition at line 132 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References setOptions().

133  {
134  // options (field_values from adv_mdf_field_definitions are not used)
135  $this->setOptions([]);
136  }
+ Here is the call graph for this function:

◆ importNewSelectOptions()

ilAdvancedMDFieldDefinitionSelect::importNewSelectOptions ( bool  $multi,
ilPropertyFormGUI  $a_form,
string  $language = '' 
)
protected

Definition at line 299 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilAdvancedMDFieldDefinition\$language, $options, ilAdvancedMDRecord\_getInstanceByRecordId(), buildConfirmedObjects(), findBySingleValue(), ilAdvancedMDFieldDefinition\getADTDefinition(), ilPropertyFormGUI\getInput(), ilADTFactory\getInstance(), getOptionTranslation(), getOptionTranslations(), ilAdvancedMDFieldDefinition\getRecordId(), importTranslatedFormPostValues(), setOptionTranslationsForLanguage(), and ilAdvancedMDFieldDefinition\useDefaultLanguageMode().

Referenced by ilAdvancedMDFieldDefinitionSelectMulti\importCustomDefinitionFormPostValues(), and importCustomDefinitionFormPostValues().

303  : void {
304  if (!$this->useDefaultLanguageMode($language)) {
305  $this->importTranslatedFormPostValues($a_form, $language);
306  return;
307  }
308 
309  if (!strlen($language)) {
310  $language = ilAdvancedMDRecord::_getInstanceByRecordId($this->getRecordId())->getDefaultLanguage();
311  }
312 
313  $old = $this->getOptionTranslation($language);
314  $new = $a_form->getInput("opts");
315 
316  $missing = array_diff_assoc($old, $new);
317  // keep track of the indices of entries persisting through the operation
318  $index_map = [];
319  foreach ($missing as $missing_idx => $missing_value) {
320  if (in_array($missing_value, $new)) {
321  $index_map[$missing_idx] = array_search($missing_value, $new);
322  }
323  }
324 
325  if (sizeof($missing)) {
326  $this->confirmed_objects = $this->buildConfirmedObjects($a_form);
327  $already_confirmed = is_array($this->confirmed_objects);
328 
329  $search = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($this->getADTDefinition(), false, $multi);
330  foreach ($missing as $missing_idx => $missing_value) {
331  $in_use = $this->findBySingleValue($search, $missing_idx);
332  if (is_array($in_use)) {
333  foreach ($in_use as $item) {
334  if (array_key_exists($missing_idx, $index_map)) {
335  $complete_id = $item[0] . "_" . $item[1] . "_" . $item[2];
336  $new_index = $index_map[$missing_idx];
337  $this->confirmed_objects[$missing_idx][$complete_id] = $new_index;
338  continue;
339  }
340  if (!$already_confirmed) {
341  $this->confirm_objects[$missing_idx][] = $item;
342  $this->confirm_objects_values[$missing_idx] = $old[$missing_idx];
343  }
344  }
345  }
346  }
347  }
348  $this->old_options = $old;
349 
350  // update the options along with their translations
352  foreach ($this->getOptionTranslations() as $current_lang => $options) {
353  $current_lang = (string) $current_lang;
354  if ($current_lang === $language) {
355  continue;
356  }
357  $updated_translations = [];
358  foreach ($options as $idx => $option) {
359  if (array_key_exists($idx, $index_map)) {
360  $updated_translations[$index_map[$idx]] = $option;
361  continue;
362  }
363  $updated_translations[$idx] = $option;
364  }
365  $this->setOptionTranslationsForLanguage($updated_translations, $current_lang);
366  }
367  }
getADTDefinition()
Get ADT definition instance.
static getInstance()
Get singleton.
importTranslatedFormPostValues(ilPropertyFormGUI $form, string $language)
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
findBySingleValue(ilADTEnumSearchBridgeMulti $a_search, $a_value)
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
useDefaultLanguageMode(string $language)
Check if default language mode has to be used: no language given or language equals default language...
setOptionTranslationsForLanguage(array $translations, string $language)
buildConfirmedObjects(ilPropertyFormGUI $a_form)
Process custom post values from definition form.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importTranslatedFormPostValues()

ilAdvancedMDFieldDefinitionSelect::importTranslatedFormPostValues ( ilPropertyFormGUI  $form,
string  $language 
)
protected
Parameters
ilPropertyFormGUI$form
string$language

Definition at line 395 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilAdvancedMDFieldDefinition\$language, ilPropertyFormGUI\getInput(), getOptions(), getOptionTranslations(), and setOptionTranslations().

Referenced by importNewSelectOptions().

396  {
397  $translated_options = [];
398  foreach ($this->getOptions() as $idx => $value) {
399  $value = $form->getInput('opts__' . $language . '__' . (string) $idx);
400  $translated_options[] = trim($value);
401  }
402  $translations = $this->getOptionTranslations();
403  $translations[$language] = $translated_options;
404  $this->setOptionTranslations($translations);
405  }
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importValueFromXML()

ilAdvancedMDFieldDefinitionSelect::importValueFromXML (   $a_cdata)

Definition at line 707 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilAdvancedMDFieldDefinition\getADT().

708  {
709  $this->getADT()->setSelection($a_cdata);
710  }
+ Here is the call graph for this function:

◆ importXMLProperty()

ilAdvancedMDFieldDefinitionSelect::importXMLProperty (   $a_key,
  $a_value 
)
Parameters
string$a_key
string$a_value

Definition at line 688 of file class.ilAdvancedMDFieldDefinitionSelect.php.

689  {
690  if (!$a_key) {
691  $this->options[] = $a_value;
692  } else {
693  $this->option_translations[$a_key][] = $a_value;
694  }
695  }

◆ initADTDefinition()

ilAdvancedMDFieldDefinitionSelect::initADTDefinition ( )
protected

Definition at line 47 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilAdvancedMDFieldDefinition\$language, $options, ilADTFactory\getInstance(), getOptions(), getOptionTranslations(), and language().

48  {
49  $def = ilADTFactory::getInstance()->getDefinitionInstanceByType("Enum");
50  $def->setNumeric(false);
51 
52  $options = $this->getOptions();
53  $translated_options = [];
54  if (isset($this->getOptionTranslations()[$this->language])) {
55  $translated_options = $this->getOptionTranslations()[$this->language];
56  }
57  $def->setOptions(array_replace($options, $translated_options));
58  return $def;
59  }
static getInstance()
Get singleton.
language()
Definition: language.php:2
+ Here is the call graph for this function:

◆ prepareCustomDefinitionFormConfirmation()

ilAdvancedMDFieldDefinitionSelect::prepareCustomDefinitionFormConfirmation ( ilPropertyFormGUI  $a_form)

Definition at line 412 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $_POST, $DIC, $lng, $options, ilAdvancedMDFieldDefinition\$title, $type, ilObject\_lookupTitle(), ilObject\_lookupType(), ilPropertyFormGUI\addItem(), ilAdvancedMDFieldDefinition\getFieldId(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), ilUtil\sendFailure(), and ilFormPropertyGUI\setRequired().

413  {
414  global $DIC;
415 
416  $lng = $DIC['lng'];
417  $objDefinition = $DIC['objDefinition'];
418 
419  $a_form->getItemByPostVar("opts")->setDisabled(true);
420  if (is_array($this->confirm_objects) && count($this->confirm_objects) > 0) {
421  $new_options = $a_form->getInput("opts");
422 
423  $sec = new ilFormSectionHeaderGUI();
424  $sec->setTitle($lng->txt("md_adv_confirm_definition_select_section"));
425  $a_form->addItem($sec);
426 
427  foreach ($this->confirm_objects as $old_option => $items) {
428  $old_option_value = $this->confirm_objects_values[$old_option];
429  $details = new ilRadioGroupInputGUI($lng->txt("md_adv_confirm_definition_select_option") . ': "' . $old_option_value . '"', "conf_det[" . $this->getFieldId() . "][" . $old_option . "]");
430  $details->setRequired(true);
431  $details->setValue("sum");
432  $a_form->addItem($details);
433 
434  // automatic reload does not work
435  if (isset($_POST["conf_det"][$this->getFieldId()][$old_option])) {
436  $details->setValue($_POST["conf_det"][$this->getFieldId()][$old_option]);
437  }
438 
439  $sum = new ilRadioOption($lng->txt("md_adv_confirm_definition_select_option_all"), "sum");
440  $details->addOption($sum);
441 
442  $sel = new ilSelectInputGUI(
443  $lng->txt("md_adv_confirm_definition_select_option_all_action"),
444  "conf_det_act[" . $this->getFieldId() . "][" . $old_option . "]"
445  );
446  $sel->setRequired(true);
447  $options = array(
448  "" => $lng->txt("please_select"),
449  self::REMOVE_ACTION_ID => $lng->txt("md_adv_confirm_definition_select_option_remove")
450  );
451  foreach ($new_options as $new_option_index => $new_option) {
452  $options['idx_' . $new_option_index] = $lng->txt("md_adv_confirm_definition_select_option_overwrite") . ': "' . $new_option . '"';
453  }
454  $sel->setOptions($options);
455  $sum->addSubItem($sel);
456 
457  // automatic reload does not work
458  if (isset($_POST["conf_det_act"][$this->getFieldId()][$old_option])) {
459  if ($_POST["conf_det_act"][$this->getFieldId()][$old_option]) {
460  $sel->setValue($_POST["conf_det_act"][$this->getFieldId()][$old_option]);
461  } elseif ($_POST["conf_det"][$this->getFieldId()][$old_option] == "sum") {
462  $sel->setAlert($lng->txt("msg_input_is_required"));
463  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
464  }
465  }
466  $single = new ilRadioOption($lng->txt("md_adv_confirm_definition_select_option_single"), "sgl");
467  $details->addOption($single);
468  foreach ($items as $item) {
469  $obj_id = $item[0];
470  $sub_type = $item[1];
471  $sub_id = $item[2];
472 
473  $item_id = $obj_id . "_" . $sub_type . "_" . $sub_id;
474 
475  $type = ilObject::_lookupType($obj_id);
476  $type_title = $lng->txt("obj_" . $type);
477  $title = ' "' . ilObject::_lookupTitle($obj_id) . '"';
478 
479  if ($sub_id) {
480  $class = "ilObj" . $objDefinition->getClassName($type);
481  $class_path = $objDefinition->getLocation($type);
482  include_once $class_path . "/class." . $class . ".php";
483  $ints = class_implements($class);
484  if (isset($ints["ilAdvancedMetaDataSubItems"])) {
485  $sub_title = $class::getAdvMDSubItemTitle($obj_id, $sub_type, $sub_id);
486  if ($sub_title) {
487  $title .= ' (' . $sub_title . ')';
488  }
489  }
490  }
491 
492  $sel = new ilSelectInputGUI(
493  $type_title . ' ' . $title,
494  "conf[" . $this->getFieldId() . "][" . $old_option . "][" . $item_id . "]"
495  );
496  $sel->setRequired(true);
497  $options = array(
498  "" => $lng->txt("please_select"),
499  self::REMOVE_ACTION_ID => $lng->txt("md_adv_confirm_definition_select_option_remove")
500  );
501  foreach ($new_options as $new_option_index => $new_option) {
502  $options['idx_' . $new_option_index] = $lng->txt("md_adv_confirm_definition_select_option_overwrite") . ': "' . $new_option . '"';
503  }
504  $sel->setOptions($options);
505 
506  // automatic reload does not work
507  if (isset($_POST["conf"][$this->getFieldId()][$old_option][$item_id])) {
508  if ($_POST["conf"][$this->getFieldId()][$old_option][$item_id]) {
509  $sel->setValue($_POST["conf"][$this->getFieldId()][$old_option][$item_id]);
510  } elseif ($_POST["conf_det"][$this->getFieldId()][$old_option] == "sgl") {
511  $sel->setAlert($lng->txt("msg_input_is_required"));
512  ilUtil::sendFailure($lng->txt("form_input_not_valid"));
513  }
514  }
515 
516  $single->addSubItem($sel);
517  }
518  }
519  }
520  }
This class represents an option in a radio group.
getItemByPostVar($a_post_var)
Get Item by POST variable.
$type
This class represents a section header in a property form.
static _lookupTitle($a_id)
lookup object title
addItem($a_item)
Add Item (Property, SectionHeader).
This class represents a property in a property form.
$lng
global $DIC
Definition: goto.php:24
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
$_POST["username"]
setRequired($a_required)
Set Required.
+ Here is the call graph for this function:

◆ prepareElementForEditor()

ilAdvancedMDFieldDefinitionSelect::prepareElementForEditor ( ilADTFormBridge  $a_enum)

Definition at line 717 of file class.ilAdvancedMDFieldDefinitionSelect.php.

718  {
719  assert($a_enum instanceof ilADTEnumFormBridge);
720 
721  $a_enum->setAutoSort(false);
722  }

◆ save()

ilAdvancedMDFieldDefinitionSelect::save (   $a_keep_pos = false)

Definition at line 528 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References saveOptionTranslations().

529  {
530  parent::save($a_keep_pos);
531  $this->saveOptionTranslations();
532  }
+ Here is the call graph for this function:

◆ saveOptionTranslations()

ilAdvancedMDFieldDefinitionSelect::saveOptionTranslations ( )
protected

Definition at line 553 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References $DIC, $options, $query, ilAdvancedMDFieldDefinition\getFieldId(), getOptionTranslations(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by save(), and updateOptionTranslations().

554  {
555  global $DIC;
556 
557  $db = $DIC->database();
558 
559  foreach ($this->getOptionTranslations() as $lang_key => $options) {
560  foreach ($options as $idx => $option) {
561  $query = 'insert into adv_mdf_enum (field_id, lang_code, idx, value )' .
562  'values ( ' .
563  $db->quote($this->getFieldId(), ilDBConstants::T_INTEGER) . ', ' .
564  $db->quote($lang_key, ilDBConstants::T_TEXT) . ', ' .
565  $db->quote($idx, ilDBConstants::T_INTEGER) . ', ' .
566  $db->quote($option, ilDBConstants::T_TEXT) .
567  ')' ;
568  $db->manipulate($query);
569  }
570  }
571  }
global $DIC
Definition: goto.php:24
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setOptions()

ilAdvancedMDFieldDefinitionSelect::setOptions ( array  $a_values = null)

Set options.

Parameters
array$a_values

Definition at line 71 of file class.ilAdvancedMDFieldDefinitionSelect.php.

Referenced by import(), and importFieldDefinition().

72  {
73  if ($a_values !== null) {
74  foreach ($a_values as $idx => $value) {
75  $a_values[$idx] = trim($value);
76  if (!$a_values[$idx]) {
77  unset($a_values[$idx]);
78  }
79  }
80  $a_values = array_unique($a_values);
81  // sort($a_values);
82  }
83  $this->options = $a_values;
84  }
+ Here is the caller graph for this function:

◆ setOptionTranslations()

ilAdvancedMDFieldDefinitionSelect::setOptionTranslations ( array  $translations)
Parameters
array$translations

Definition at line 115 of file class.ilAdvancedMDFieldDefinitionSelect.php.

Referenced by import(), and importTranslatedFormPostValues().

116  {
117  $this->option_translations = $translations;
118  }
+ Here is the caller graph for this function:

◆ setOptionTranslationsForLanguage()

ilAdvancedMDFieldDefinitionSelect::setOptionTranslationsForLanguage ( array  $translations,
string  $language 
)
Parameters
array$translations
string$language

Definition at line 124 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilAdvancedMDFieldDefinition\$language.

Referenced by importNewSelectOptions().

125  {
126  $this->option_translations[$language] = $translations;
127  }
+ Here is the caller graph for this function:

◆ update()

ilAdvancedMDFieldDefinitionSelect::update ( )

Definition at line 578 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References ilADTActiveRecordByType\create(), ilADTActiveRecordByType\deleteByPrimary(), findBySingleValue(), ilAdvancedMDFieldDefinition\getADTDefinition(), ilAdvancedMDFieldDefinition\getFieldId(), ilADTFactory\getInstance(), ilADTFactory\initActiveRecordByType(), ilPCAMDPageList\migrateField(), ilDBConstants\T_INTEGER, and updateOptionTranslations().

579  {
580  if (is_array($this->confirmed_objects) && count($this->confirmed_objects) > 0) {
581  // we need the "old" options for the search
582  $def = $this->getADTDefinition();
583  $def = clone($def);
584  $def->setOptions($this->old_options);
585  $search = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($def, false, true);
587 
588  $page_list_mappings = [];
589 
590  foreach ($this->confirmed_objects as $old_option => $item_ids) {
591  // get complete old values
592  $old_values = array();
593  foreach ($this->findBySingleValue($search, $old_option) as $item) {
594  $old_values[$item[0] . "_" . $item[1] . "_" . $item[2]] = $item[3];
595  }
596 
597 
598  foreach ($item_ids as $item => $new_option) {
599  $parts = explode("_", $item);
600  $obj_id = $parts[0];
601  $sub_type = $parts[1];
602  $sub_id = $parts[2];
603 
604  // update existing value (with changed option)
605  if (isset($old_values[$item])) {
606  $old_value = $old_values[$item];
607  // find changed option in old value
608  //$old_value = explode(ilADTMultiEnumDBBridge::SEPARATOR, $old_values[$item]);
609  // remove separators
610  //array_shift($old_value);
611  //array_pop($old_value);
612 
613 
614  //$old_idx = array_keys($old_value, $old_option);
615  $old_idx = $old_value;
616  if (isset($old_idx)) {
617  $primary = array(
618  "obj_id" => array("integer", $obj_id),
619  "sub_type" => array("text", $sub_type),
620  "sub_id" => array("integer", $sub_id),
621  "field_id" => array("integer", $this->getFieldId())
622  );
623 
624  $index_old = array_merge(
625  $primary,
626  [
627  'value_index' => [ilDBConstants::T_INTEGER, $old_idx]
628  ]
629  );
630  $index_new = array_merge(
631  $primary,
632  [
633  'value_index' => [ilDBConstants::T_INTEGER, $new_option]
634  ]
635  );
636  ilADTActiveRecordByType::deleteByPrimary('adv_md_values', $index_old, 'MultiEnum');
637 
638  if (is_numeric($new_option)) {
639  ilADTActiveRecordByType::deleteByPrimary('adv_md_values', $index_new, 'MultiEnum');
640  ilADTActiveRecordByType::create('adv_md_values', $index_new, 'MultiEnum');
641  } else {
642  }
643  }
644  }
645 
646  if ($sub_type == "wpg") {
647  // #15763 - adapt advmd page lists
648  $page_list_mappings[(string) $old_option] = (string) $new_option;
649  }
650  }
651  }
652 
653  if (!empty($page_list_mappings)) {
655  $this->getFieldId(),
656  $page_list_mappings
657  );
658  }
659 
660  $this->confirmed_objects = array();
661  }
662 
663  parent::update();
664  $this->updateOptionTranslations();
665  }
getADTDefinition()
Get ADT definition instance.
static initActiveRecordByType()
Init active record by type.
static getInstance()
Get singleton.
static migrateField(int $a_field_id, array $mapping)
Migrate search/filter values on advmd change.
static deleteByPrimary($a_table, array $a_primary, $a_type=null)
Delete values by (partial) primary key.
findBySingleValue(ilADTEnumSearchBridgeMulti $a_search, $a_value)
static create(string $table, array $fields, string $type)
+ Here is the call graph for this function:

◆ updateOptionTranslations()

ilAdvancedMDFieldDefinitionSelect::updateOptionTranslations ( )
protected

Definition at line 547 of file class.ilAdvancedMDFieldDefinitionSelect.php.

References deleteOptionTranslations(), and saveOptionTranslations().

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $confirm_objects

ilAdvancedMDFieldDefinitionSelect::$confirm_objects = []
protected

Definition at line 17 of file class.ilAdvancedMDFieldDefinitionSelect.php.

◆ $confirm_objects_values

ilAdvancedMDFieldDefinitionSelect::$confirm_objects_values = []
protected

Definition at line 18 of file class.ilAdvancedMDFieldDefinitionSelect.php.

◆ $confirmed_objects

ilAdvancedMDFieldDefinitionSelect::$confirmed_objects
protected

Definition at line 19 of file class.ilAdvancedMDFieldDefinitionSelect.php.

◆ $option_translations

ilAdvancedMDFieldDefinitionSelect::$option_translations = []
protected

Definition at line 21 of file class.ilAdvancedMDFieldDefinitionSelect.php.

Referenced by getOptionTranslations().

◆ $options

◆ REMOVE_ACTION_ID

const ilAdvancedMDFieldDefinitionSelect::REMOVE_ACTION_ID = "-iladvmdrm-"

Definition at line 23 of file class.ilAdvancedMDFieldDefinitionSelect.php.


The documentation for this class was generated from the following file: