19declare(strict_types=1);
82 $this->
lng = $DIC->language();
83 $this->
language = $DIC->language()->getLangKey();
85 $this->
http = $DIC->http();
92 $this->
logger = $DIC->logger()->amet();
93 $this->db =
$DIC->database();
111 if (self::isValidType((
int) $a_type)) {
140 string $language =
''
142 $class =
"ilAdvancedMDFieldDefinition" . $generic_data->type()->stringValue();
143 return new $class($generic_data, $language);
146 public static function exists(
int $a_field_id): bool
151 $set = $db->
query(
"SELECT field_type" .
152 " FROM adv_mdf_definition" .
153 " WHERE field_id = " . $db->
quote($a_field_id,
"integer"));
167 self::TYPE_TEXT =>
"Text",
168 self::TYPE_SELECT =>
"Select",
169 self::TYPE_DATE =>
"Date",
170 self::TYPE_DATETIME =>
"DateTime",
171 self::TYPE_FLOAT =>
"Float",
172 self::TYPE_LOCATION =>
"Location",
173 self::TYPE_INTEGER =>
"Integer",
174 self::TYPE_SELECT_MULTI =>
"SelectMulti",
175 self::TYPE_EXTERNAL_LINK =>
'ExternalLink',
176 self::TYPE_INTERNAL_LINK =>
'InternalLink',
177 self::TYPE_ADDRESS =>
"Address"
179 $map = array_flip($map);
180 if (array_key_exists($a_type, $map)) {
181 return self::getInstance(
null, $map[$a_type]);
195 $a_only_searchable =
false,
196 string $language =
''
203 foreach ($db_gateway->readByRecords($a_only_searchable, $a_record_id) as
$data) {
204 $defs[
$data->id()] = self::getInstanceWithData(
$data);
221 $query =
"SELECT amf.* FROM adv_md_record_objs aro" .
222 " JOIN adv_md_record amr ON aro.record_id = amr.record_id" .
223 " JOIN adv_mdf_definition amf ON aro.record_id = amf.record_id" .
224 " WHERE obj_type = " .
$ilDB->quote($a_obj_type,
'text');
225 if ($a_active_only) {
226 $query .=
" AND active = " .
$ilDB->quote(1,
"integer");
228 $query .=
" ORDER BY aro.record_id,position";
233 $ids[] = (
int) $row[
"field_id"];
235 $data = $db_gateway->readByIDs(...$ids);
238 foreach (
$data as $datum) {
239 $defs[$datum->id()] = self::getInstanceWithData($datum);
251 if (is_null(
$data = $db_gateway->readByImportID($a_import_id))) {
254 return self::getInstanceWithData(
$data);
267 $field_ids = array();
269 $query =
"SELECT field_id FROM adv_md_record amr" .
270 " JOIN adv_mdf_definition amfd ON (amr.record_id = amfd.record_id)" .
271 " WHERE active = " .
$ilDB->quote(1,
"integer") .
272 " AND searchable = " .
$ilDB->quote(1,
"integer");
273 $set =
$ilDB->query($query);
274 while ($row =
$ilDB->fetchAssoc($set)) {
275 $field_ids[] = (
int) $row[
"field_id"];
289 $group_def = $factory->getDefinitionInstanceByType(
"Group");
290 foreach ($a_defs as $def) {
291 $group_def->addElement($def->getFieldId(), $def->getADTDefinition());
293 $group = $factory->getInstanceByDefinition($group_def);
296 foreach ($group->getElements() as $element_id => $element) {
297 $a_defs[$element_id]->setADT($element);
308 $types = Type::cases();
310 foreach ($types as $type) {
311 $values[] = $type->value;
318 return !is_null(Type::tryFrom($a_type));
331 return (
string) (Type::tryFrom($a_type)?->stringValue());
339 if (!strlen($language)) {
343 return strcmp($record->getDefaultLanguage(), $language) === 0;
351 return "udf_type_" . strtolower(self::getTypeString($this->getType()));
366 $this->adt_def = $this->initADTDefinition();
368 return $this->adt_def;
373 if (!$this->adt instanceof
ilADT) {
385 if (!$this->adt instanceof
ilADT) {
395 return $this->generic_data->id();
403 $this->generic_data->setRecordID($a_id);
411 return $this->generic_data->getRecordID();
419 $this->generic_data->setImportID(trim($a_id_string));
427 return $this->generic_data->getImportID();
435 $this->generic_data->setPosition($a_pos);
443 return $this->generic_data->getPosition();
451 $this->generic_data->setTitle(trim($a_title));
459 return $this->generic_data->getTitle();
467 $this->generic_data->setDescription(trim($a_desc));
475 return $this->generic_data->getDescription();
500 if (!$this->isSearchSupported()) {
503 $this->generic_data->setSearchable($a_status);
511 return $this->generic_data->isSearchable();
519 $this->generic_data->setRequired($a_status);
527 return $this->generic_data->isRequired();
558 bool $a_disabled =
false,
559 string $language =
''
566 public function addToFieldDefinitionForm(
569 string $language =
''
574 $perm = $a_permissions->hasPermissions(
576 (
string) $this->getFieldId(),
600 $title->setValue($this->
getTitle());
602 $title->setMaxLength(70);
603 $title->setRequired(
true);
604 if ($this->getFieldId()) {
605 $translations->modifyTranslationInfoForTitle($this->getFieldId(), $a_form, $title, $language);
607 $title->setValue($this->
getTitle());
613 $title->setDisabled(
true);
618 $desc->setValue($this->getDescription());
621 if ($this->getFieldId()) {
622 $translations->modifyTranslationInfoForDescription($this->getFieldId(), $a_form, $desc, $language);
624 $desc->setValue($this->getDescription());
630 $desc->setDisabled(
true);
635 $check->setChecked($this->isSearchable());
640 !$this->isSearchSupported()) {
641 $check->setDisabled(
true);
651 $this->addCustomFieldToDefinitionForm(
672 string $active_language
675 $is_translation = (($active_language !==
'') && ($active_language != $record->getDefaultLanguage()));
676 if (!$a_form->
getItemByPostVar(
"title")->getDisabled() && !$is_translation) {
677 $this->setTitle($a_form->
getInput(
"title"));
679 if (!$a_form->
getItemByPostVar(
"description")->getDisabled() && !$is_translation) {
680 $this->setDescription($a_form->
getInput(
"description"));
683 $this->setSearchable((
bool) $a_form->
getInput(
"searchable"));
688 (
string) $this->getFieldId(),
692 $this->importCustomDefinitionFormPostValues($a_form, $active_language);
712 if ($a_form->
getInput(
"searchable")) {
714 $hidden->setValue(
"1");
718 $this->prepareCustomDefinitionFormConfirmation($a_form);
726 return 'il_' .
IL_INST_ID .
'_adv_md_field_' . $a_field_id;
732 public function save(
bool $keep_pos_and_import_id =
false,
bool $keep_import_id =
false): void
734 if ($this->getFieldId()) {
744 $this->generic_data->setFieldValues($this->getFieldDefinition());
746 if ($keep_pos_and_import_id) {
747 $field_id = $this->db_gateway->create($this->generic_data);
748 } elseif ($keep_import_id) {
749 $field_id = $this->db_gateway->createWithNewPosition($this->generic_data);
751 $field_id = $this->db_gateway->createFromScratch($this->generic_data);
754 $this->generic_data = $this->db_gateway->readByID($field_id);
762 if (!$this->getFieldId()) {
772 $this->generic_data->setFieldValues($this->getFieldDefinition());
774 $this->db_gateway->update($this->generic_data);
780 public function delete():
void
782 if (!$this->getFieldId()) {
789 $this->db_gateway->delete($this->getFieldId());
800 'id' => $this->getImportId(),
801 'searchable' => ($this->isSearchable() ?
'Yes' :
'No'),
802 'fieldType' => self::getTypeString($this->getType())
806 $a_writer->
xmlElement(
'FieldDescription',
null, $this->getDescription());
810 foreach ($translations->getTranslations($this->getFieldId()) as $translation) {
811 $a_writer->
xmlStartTag(
'FieldTranslation', [
'language' => $translation->getLangKey()]);
813 'FieldTranslationTitle',
815 $translation->getTitle()
818 'FieldTranslationDescription',
820 $translation->getDescription()
822 $a_writer->
xmlEndTag(
'FieldTranslation');
824 $a_writer->
xmlEndTag(
'FieldTranslations');
825 $a_writer->
xmlElement(
'FieldPosition',
null, $this->getPosition());
827 $this->addPropertiesToXML($a_writer);
861 public function importFromECS(
string $a_ecs_type, $a_value,
string $a_sub_id): bool
905 foreach ($a_records as $record) {
906 if ($record[
"sub_type"] ==
"-") {
907 $obj_ids[] = $record[
"obj_id"];
911 $sql =
"SELECT obj_id,type" .
912 " FROM object_data" .
913 " WHERE " . $this->db->in(
"obj_id", $obj_ids,
false,
"integer") .
914 " AND " . $this->db->in(
"type", $a_object_types,
false,
"text");
915 $set = $this->db->query($sql);
916 while ($row = $this->db->fetchAssoc($set)) {
935 $this->getADT()->getType(),
939 if (
sizeof($objects)) {
941 foreach ($objects as $item) {
942 if ($item[
"obj_id"] == $a_obj_id &&
943 $item[
"sub_type"] == $sub_obj_type) {
944 $res[] = $item[
"sub_id"];
960 array $a_object_types,
962 string $a_search_type
969 $this->getADT()->getType(),
974 if (
sizeof($objects)) {
975 return $this->parseSearchObjects($objects, $a_object_types);
1002 public function _clone(
int $a_new_record_id): self
1005 $this->generic_data->type(),
1016 $class = get_class($this);
1017 $obj =
new $class($empty_generic_data);
1018 $obj->setRecordId($a_new_record_id);
1020 $obj->setDescription($this->getDescription());
1021 $obj->setRequired($this->isRequired());
1022 $obj->setPosition($this->getPosition());
1023 $obj->setSearchable($this->isSearchable());
1024 $obj->importFieldDefinition($this->getFieldDefinition());
ADT Active Record by type helper class This class expects a valid primary for all actions!
static find(string $a_table, string $a_type, int $a_field_id, string $a_condition, ?string $a_additional_fields=null)
Find entries.
ADT definition base class.
ADT search bridge base class.
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
AMD field abstract base class.
__construct(GenericData $generic_data, string $language='')
getLuceneSearchString($a_value)
Get search string in lucene syntax.
getImportId()
Get import id.
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
update()
Update field entry.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, bool $a_disabled=false, string $language='')
Add custom input elements to definition form.
importValueFromXML(string $a_cdata)
Import value from xml.
isRequired()
Is required field.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
static getInstanceByImportId(string $a_import_id)
setRecordId(int $a_id)
Set record id.
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
getSearchValueSerialized(ilADTSearchBridge $a_adt_search)
setDescription(string $a_desc)
Set description.
useDefaultLanguageMode(string $language)
Check if default language mode has to be used: no language given or language equals default language.
static getInstanceByTypeString(string $a_type)
Get instance by type string (used by import)
importFromECS(string $a_ecs_type, $a_value, string $a_sub_id)
Import meta data from ECS.
getComplexOptionsOverview(object $a_parent_gui, string $parent_cmd)
setImportId(string $a_id_string)
Set import id.
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
_clone(int $a_new_record_id)
Clone field definition.
initADTDefinition()
Init adt instance.
setADT(ilADT $a_adt)
Set ADT instance.
static getInstancesByObjType($a_obj_type, $a_active_only=true)
isSearchSupported()
Is search supported at all.
parseSearchObjects(array $a_records, array $a_object_types)
Add object-data needed for global search to AMD search results.
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Get value for search query parser.
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
const TYPE_SELECT
TODO: put this in when minimum php version is set to 8.2.
getFieldId()
Get field_id.
getDescription()
Get description.
getADTDefinition()
Get ADT definition instance.
GenericData $generic_data
getRecordId()
Get record id.
toXML(ilXmlWriter $a_writer)
To Xml.
static getValidTypes()
Get all valid types.
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
static exists(int $a_field_id)
getFieldDefinition()
Get (type-specific) field definition.
static getInstanceWithData(GenericData $generic_data, string $language='')
save(bool $keep_pos_and_import_id=false, bool $keep_import_id=false)
Create new field entry.
searchSubObjects(ilADTSearchBridge $a_adt_search, int $a_obj_id, string $sub_obj_type)
static getTypeString(int $a_type)
Get type as string.
setSearchable(bool $a_status)
Toggle searchable.
setSearchValueSerialized(ilADTSearchBridge $a_adt_search, $a_value)
Set value from search persistence.
RefineryFactory $refinery
importXMLProperty(string $a_key, string $a_value)
Import property from XML.
static isValidType(int $a_type)
getPosition()
Get position.
setTitle(string $a_title)
Get title.
prepareElementForSearch(ilADTSearchBridge $a_bridge)
Prepare search form elements.
static getSearchableDefinitionIds()
Get searchable definition ids (performance is key)
generateImportId(int $a_field_id)
Generate unique record id.
searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, string $a_locate, string $a_search_type)
Search objects.
isFilterSupported()
Is search by filter supported.
importDefinitionFormPostValuesNeedsConfirmation()
prepareElementForEditor(ilADTFormBridge $a_bridge)
Prepare editor form elements.
importDefinitionFormPostValues(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $active_language)
Import post values from definition form.
setPosition(int $a_pos)
Set position.
prepareDefinitionFormConfirmation(ilPropertyFormGUI $a_form)
isSearchable()
Is searchable.
prepareCustomDefinitionFormConfirmation(ilPropertyFormGUI $a_form)
static getInstance(?int $a_field_id, ?int $a_type=null, string $language='')
setRequired(bool $a_status)
Toggle required.
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
static getInstanceByRecordId(int $record_id)
Advanced metadata permission helper.
const SUBACTION_FIELD_SEARCHABLE
const SUBACTION_FIELD_DESCRIPTION
const ACTION_FIELD_EDIT_PROPERTY
const SUBACTION_FIELD_PROPERTIES
const SUBACTION_FIELD_TITLE
static _getInstanceByRecordId(int $a_record_id)
static _deleteByFieldId(int $a_field_id, ilADT $a_adt)
Delete values by field_id.
hasPermission(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission.
Base class for ILIAS Exception handling.
Component logger with individual log levels by component id.
This class represents a text area property in a property form.
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)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
Interface GlobalHttpState.
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)
static http()
Fetches the global http state from ILIAS.