19 declare(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();
105 string $language =
'' 111 if (self::isValidType((
int) $a_type)) {
129 $generic_data = $db_gateway->readByID($a_field_id);
132 if (isset($generic_data)) {
133 return self::getInstanceWithData($generic_data);
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);
218 $ilDB = $DIC->database();
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);
265 $ilDB = $DIC[
'ilDB'];
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()));
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();
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 =
'' 569 string $language =
'' 600 $title->setValue($this->
getTitle());
602 $title->setMaxLength(70);
603 $title->setRequired(
true);
605 $translations->modifyTranslationInfoForTitle($this->
getFieldId(), $a_form, $title, $language);
607 $title->setValue($this->
getTitle());
613 $title->setDisabled(
true);
622 $translations->modifyTranslationInfoForDescription($this->
getFieldId(), $a_form, $desc, $language);
630 $desc->setDisabled(
true);
641 $check->setDisabled(
true);
672 string $active_language
675 $is_translation = (($active_language !==
'') && ($active_language != $record->getDefaultLanguage()));
676 if (!$a_form->
getItemByPostVar(
"title")->getDisabled() && !$is_translation) {
679 if (!$a_form->
getItemByPostVar(
"description")->getDisabled() && !$is_translation) {
688 (
string) $this->getFieldId(),
712 if ($a_form->
getInput(
"searchable")) {
714 $hidden->setValue(
"1");
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
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);
774 $this->db_gateway->update($this->generic_data);
780 public function delete():
void 789 $this->db_gateway->delete($this->
getFieldId());
802 'fieldType' => self::getTypeString($this->
getType())
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');
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)) {
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
974 if (
sizeof($objects)) {
1002 public function _clone(
int $a_new_record_id): self
1004 $class = get_class($this);
1005 $obj =
new $class();
1006 $obj->setRecordId($a_new_record_id);
isSearchable()
Is searchable.
getDescription()
Get description.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, bool $a_disabled=false, string $language='')
Add custom input elements to definition form.
static getInstanceByImportId(string $a_import_id)
parseSearchObjects(array $a_records, array $a_object_types)
Add object-data needed for global search to AMD search results.
static _deleteByFieldId(int $a_field_id, ilADT $a_adt)
Delete values by field_id.
toXML(ilXmlWriter $a_writer)
To Xml.
getComplexOptionsOverview(object $a_parent_gui, string $parent_cmd)
isFilterSupported()
Is search by filter supported.
const SUBACTION_FIELD_PROPERTIES
setSearchValueSerialized(ilADTSearchBridge $a_adt_search, $a_value)
Set value from search persistence.
static isValidType(int $a_type)
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...
getADTDefinition()
Get ADT definition instance.
fetchAssoc(ilDBStatement $statement)
isRequired()
Is required field.
AMD field abstract base class.
const TYPE_SELECT
TODO: put this in when minimum php version is set to 8.2.
searchSubObjects(ilADTSearchBridge $a_adt_search, int $a_obj_id, string $sub_obj_type)
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
getImportId()
Get import id.
const ACTION_FIELD_EDIT_PROPERTY
hasPermissions(int $a_context_type, string $a_context_id, array $a_action_ids)
Check permissions.
quote($value, string $type)
update()
Update field entry.
importFromECS(string $a_ecs_type, $a_value, string $a_sub_id)
Import meta data from ECS.
static getInstancesByRecordId( $a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
importValueFromXML(string $a_cdata)
Import value from xml.
static getInstance(?int $a_field_id, ?int $a_type=null, string $language='')
__construct(GenericData $generic_data, string $language='')
const SUBACTION_FIELD_SEARCHABLE
_clone(int $a_new_record_id)
Clone field definition.
save(bool $keep_pos_and_import_id=false, bool $keep_import_id=false)
Create new field entry.
prepareCustomDefinitionFormConfirmation(ilPropertyFormGUI $a_form)
xmlEndTag(string $tag)
Writes an endtag.
setValue(string $a_value)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setRecordId(int $a_id)
Set record id.
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
importCustomDefinitionFormPostValues(ilPropertyFormGUI $a_form, string $language='')
Import custom post values from definition form.
static _getInstanceByRecordId(int $a_record_id)
generateImportId(int $a_field_id)
Generate unique record id.
static getTypeString(int $a_type)
Get type as string.
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Get value for search query parser.
static http()
Fetches the global http state from ILIAS.
setTitle(string $a_title)
Get title.
Advanced metadata permission helper.
getSearchValueSerialized(ilADTSearchBridge $a_adt_search)
const SUBACTION_FIELD_TITLE
static getSearchableDefinitionIds()
Get searchable definition ids (performance is key)
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
getSQLCondition(string $a_element_id, int $mode=self::SQL_LIKE, array $quotedWords=[])
Get SQL condition for current value(s)
static getInstancesByObjType($a_obj_type, $a_active_only=true)
hasPermission(int $a_context_type, string $a_context_id, int $a_action_id, ?int $a_action_sub_id=null)
Check permission.
searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, string $a_locate, string $a_search_type)
Search objects.
importDefinitionFormPostValuesNeedsConfirmation()
query(string $query)
Run a (read-only) Query on the database.
setRequired(bool $a_status)
Toggle required.
importXMLProperty(string $a_key, string $a_value)
Import property from XML.
setPosition(int $a_pos)
Set position.
prepareElementForSearch(ilADTSearchBridge $a_bridge)
Prepare search form elements.
static getValidTypes()
Get all valid types.
static getInstanceByRecordId(int $record_id)
setDescription(string $a_desc)
Set description.
prepareElementForEditor(ilADTFormBridge $a_bridge)
Prepare editor form elements.
getLuceneSearchString($a_value)
Get search string in lucene syntax.
ADT search bridge base class.
getFieldDefinition()
Get (type-specific) field definition.
setADT(ilADT $a_adt)
Set ADT instance.
static getInstanceWithData(GenericData $generic_data, string $language='')
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
static exists(int $a_field_id)
importDefinitionFormPostValues(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $active_language)
Import post values from definition form.
getValueForXML(ilADT $element)
Parse ADT value for xml (export)
useDefaultLanguageMode(string $language)
Check if default language mode has to be used: no language given or language equals default language...
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
This class represents a text area property in a property form.
getPosition()
Get position.
const SUBACTION_FIELD_DESCRIPTION
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
GenericData $generic_data
RefineryFactory $refinery
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
language()
description: > Example for rendring a language glyph.
initADTDefinition()
Init adt instance.
addToFieldDefinitionForm(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $language='')
Add input elements to definition form.
setImportId(string $a_id_string)
Set import id.
ADT definition base class.
isSearchSupported()
Is search supported at all.
setSearchable(bool $a_status)
Toggle searchable.
getRecordId()
Get record id.
getFieldId()
Get field_id.
setSerializedValue(string $a_value)
Set current value(s) in serialized form (for easy persisting)
prepareDefinitionFormConfirmation(ilPropertyFormGUI $a_form)
static find(string $a_table, string $a_type, int $a_field_id, string $a_condition, ?string $a_additional_fields=null)
Find entries.
static getInstanceByTypeString(string $a_type)
Get instance by type string (used by import)