3 declare(strict_types=1);
63 public function __construct(?
int $a_field_id = null,
string $language =
'')
67 $this->
lng = $DIC->language();
68 $this->
language = $DIC->language()->getLangKey();
70 $this->
http = $DIC->http();
77 $this->
logger = $DIC->logger()->amet();
78 $this->db = $DIC->database();
81 $this->
read($a_field_id);
91 $db = $DIC->database();
94 $set = $db->
query(
"SELECT field_type" .
95 " FROM adv_mdf_definition" .
96 " WHERE field_id = " . $db->
quote($a_field_id,
"integer"));
98 $a_type = (
int) $a_type[
"field_type"];
101 if (self::isValidType($a_type)) {
102 $class =
"ilAdvancedMDFieldDefinition" . self::getTypeString($a_type);
103 return new $class($a_field_id, $language);
108 public static function exists(
int $a_field_id): bool
113 $set = $db->
query(
"SELECT field_type" .
114 " FROM adv_mdf_definition" .
115 " WHERE field_id = " . $db->
quote($a_field_id,
"integer"));
129 self::TYPE_TEXT =>
"Text",
130 self::TYPE_SELECT =>
"Select",
131 self::TYPE_DATE =>
"Date",
132 self::TYPE_DATETIME =>
"DateTime",
133 self::TYPE_FLOAT =>
"Float",
134 self::TYPE_LOCATION =>
"Location",
135 self::TYPE_INTEGER =>
"Integer",
136 self::TYPE_SELECT_MULTI =>
"SelectMulti",
137 self::TYPE_EXTERNAL_LINK =>
'ExternalLink',
138 self::TYPE_INTERNAL_LINK =>
'InternalLink',
139 self::TYPE_ADDRESS =>
"Address" 141 $map = array_flip($map);
142 if (array_key_exists($a_type, $map)) {
143 return self::getInstance(null, $map[$a_type]);
157 $a_only_searchable =
false,
158 string $language =
'' 162 $ilDB = $DIC[
'ilDB'];
164 $query =
"SELECT * FROM adv_mdf_definition" .
165 " WHERE record_id = " .
$ilDB->quote($a_record_id,
"integer");
166 if ($a_only_searchable) {
167 $query .=
" AND searchable = " .
$ilDB->quote(1,
"integer");
169 $query .=
" ORDER BY position";
172 while ($row =
$ilDB->fetchAssoc($set)) {
173 $field = self::getInstance(null, (
int) $row[
"field_type"], $language);
174 $field->import($row);
175 $defs[(
int) $row[
"field_id"]] = $field;
189 $ilDB = $DIC[
'ilDB'];
191 $query =
"SELECT amf.* FROM adv_md_record_objs aro" .
192 " JOIN adv_md_record amr ON aro.record_id = amr.record_id" .
193 " JOIN adv_mdf_definition amf ON aro.record_id = amf.record_id" .
194 " WHERE obj_type = " .
$ilDB->quote($a_obj_type,
'text');
195 if ($a_active_only) {
196 $query .=
" AND active = " .
$ilDB->quote(1,
"integer");
198 $query .=
" ORDER BY aro.record_id,position";
202 $field = self::getInstance(null, (
int) $row[
"field_type"]);
203 $field->import($row);
204 $defs[(
int) $row[
"field_id"]] = $field;
213 $ilDB = $DIC[
'ilDB'];
215 $query =
"SELECT field_id, field_type FROM adv_mdf_definition" .
216 " WHERE import_id = " .
$ilDB->quote($a_import_id,
'text');
218 if (
$ilDB->numRows($set)) {
219 $row =
$ilDB->fetchAssoc($set);
220 return self::getInstance((
int) $row[
"field_id"], (
int) $row[
"field_type"]);
233 $ilDB = $DIC[
'ilDB'];
235 $field_ids = array();
237 $query =
"SELECT field_id FROM adv_md_record amr" .
238 " JOIN adv_mdf_definition amfd ON (amr.record_id = amfd.record_id)" .
239 " WHERE active = " .
$ilDB->quote(1,
"integer") .
240 " AND searchable = " .
$ilDB->quote(1,
"integer");
242 while ($row =
$ilDB->fetchAssoc($set)) {
243 $field_ids[] = (
int) $row[
"field_id"];
257 $group_def =
$factory->getDefinitionInstanceByType(
"Group");
258 foreach ($a_defs as $def) {
259 $group_def->addElement($def->getFieldId(), $def->getADTDefinition());
261 $group =
$factory->getInstanceByDefinition($group_def);
264 foreach ($group->getElements() as $element_id => $element) {
265 $a_defs[$element_id]->setADT($element);
270 protected function init(): void
290 self::TYPE_SELECT_MULTI,
291 self::TYPE_EXTERNAL_LINK,
292 self::TYPE_INTERNAL_LINK,
299 return in_array($a_type, self::getValidTypes());
312 if (self::isValidType($a_type)) {
314 self::TYPE_TEXT =>
"Text",
315 self::TYPE_SELECT =>
"Select",
316 self::TYPE_DATE =>
"Date",
317 self::TYPE_DATETIME =>
"DateTime",
318 self::TYPE_FLOAT =>
"Float",
319 self::TYPE_LOCATION =>
"Location",
320 self::TYPE_INTEGER =>
"Integer",
321 self::TYPE_SELECT_MULTI =>
"SelectMulti",
322 self::TYPE_EXTERNAL_LINK =>
'ExternalLink',
323 self::TYPE_INTERNAL_LINK =>
'InternalLink',
324 self::TYPE_ADDRESS =>
"Address" 326 return $map[$a_type];
336 if (!strlen($language)) {
340 return strcmp($record->getDefaultLanguage(),
$language) === 0;
348 return "udf_type_" . strtolower(self::getTypeString($this->
getType()));
370 if (!$this->adt instanceof
ilADT) {
382 if (!$this->adt instanceof
ilADT) {
392 $this->field_id = $a_id;
408 $this->record_id = $a_id;
424 if ($a_id_string !== null) {
425 $a_id_string = trim($a_id_string);
427 $this->import_id = $a_id_string;
443 $this->position = $a_pos;
459 if ($a_title !== null) {
460 $a_title = trim($a_title);
462 $this->title = $a_title;
478 if ($a_desc !== null) {
479 $a_desc = trim($a_desc);
481 $this->description = $a_desc;
517 $this->searchable = (bool) $a_status;
533 $this->required = $a_status;
572 bool $a_disabled =
false,
573 string $language =
'' 583 string $language =
'' 614 $title->setValue($this->
getTitle());
616 $title->setMaxLength(70);
617 $title->setRequired(
true);
619 $translations->modifyTranslationInfoForTitle($this->
getFieldId(), $a_form, $title, $language);
621 $title->setValue($this->
getTitle());
627 $title->setDisabled(
true);
636 $translations->modifyTranslationInfoForDescription($this->
getFieldId(), $a_form, $desc, $language);
644 $desc->setDisabled(
true);
655 $check->setDisabled(
true);
686 string $active_language
689 $is_translation = (($active_language !==
'') && ($active_language != $record->getDefaultLanguage()));
690 if (!$a_form->
getItemByPostVar(
"title")->getDisabled() && !$is_translation) {
693 if (!$a_form->
getItemByPostVar(
"description")->getDisabled() && !$is_translation) {
702 (
string) $this->getFieldId(),
726 if ($a_form->
getInput(
"searchable")) {
728 $hidden->setValue(
"1");
740 $sql =
"SELECT max(position) pos" .
741 " FROM adv_mdf_definition" .
742 " WHERE record_id = " . $this->db->quote($this->
getRecordId(),
"integer");
743 $set = $this->db->query($sql);
744 if ($this->db->numRows($set)) {
745 $pos = $this->db->fetchAssoc($set);
746 return (
int) $pos[
"pos"];
756 return 'il_' .
IL_INST_ID .
'_adv_md_field_' . $a_field_id;
765 "field_type" => array(
"integer", $this->
getType()),
766 "record_id" => array(
"integer", $this->
getRecordId()),
767 "import_id" => array(
"text", $this->
getImportId()),
768 "title" => array(
"text", $this->
getTitle()),
770 "position" => array(
"integer", $this->
getPosition()),
771 "searchable" => array(
"integer", $this->
isSearchable()),
772 "required" => array(
"integer", $this->
isRequired())
776 if (is_array($def)) {
777 $fields[
"field_values"] = array(
"text", serialize($def));
785 protected function import(array $a_data):
void 790 $this->
setTitle((
string) $a_data[
"title"]);
795 if (isset($a_data[
'field_values'])) {
796 $field_values = unserialize($a_data[
'field_values']);
797 if (is_array($field_values)) {
806 protected function read(?
int $a_field_id): void
808 if (!(
int) $a_field_id) {
812 $sql =
"SELECT * FROM adv_mdf_definition" .
813 " WHERE field_id = " . $this->db->quote($a_field_id,
"integer");
814 $set = $this->db->query($sql);
815 if ($this->db->numRows($set)) {
816 $row = $this->db->fetchAssoc($set);
824 public function save(
bool $a_keep_pos =
false): void
831 $next_id = $this->db->nextId(
"adv_mdf_definition");
844 $fields[
"field_id"] = array(
"integer", $next_id);
846 $this->db->insert(
"adv_mdf_definition", $fields);
862 "adv_mdf_definition",
864 array(
"field_id" => array(
"integer", $this->
getFieldId()))
871 public function delete():
void 880 $query =
"DELETE FROM adv_mdf_definition" .
881 " WHERE field_id = " . $this->db->quote($this->
getFieldId(),
"integer");
882 $this->db->manipulate(
$query);
895 'fieldType' => self::getTypeString($this->
getType())
903 foreach ($translations->getTranslations($this->getFieldId()) as $translation) {
904 $a_writer->
xmlStartTag(
'FieldTranslation', [
'language' => $translation->getLangKey()]);
906 'FieldTranslationTitle',
908 $translation->getTitle()
911 'FieldTranslationDescription',
913 $translation->getDescription()
915 $a_writer->
xmlEndTag(
'FieldTranslation');
917 $a_writer->
xmlEndTag(
'FieldTranslations');
954 public function importFromECS(
string $a_ecs_type, $a_value,
string $a_sub_id): bool
998 foreach ($a_records as $record) {
999 if ($record[
"sub_type"] ==
"-") {
1000 $obj_ids[] = $record[
"obj_id"];
1004 $sql =
"SELECT obj_id,type" .
1005 " FROM object_data" .
1006 " WHERE " . $this->db->in(
"obj_id", $obj_ids,
false,
"integer") .
1007 " AND " . $this->db->in(
"type", $a_object_types,
false,
"text");
1008 $set = $this->db->query($sql);
1009 while ($row = $this->db->fetchAssoc($set)) {
1021 $element_id =
"loc";
1032 if (
sizeof($objects)) {
1034 foreach ($objects as $item) {
1035 if ($item[
"obj_id"] == $a_obj_id &&
1036 $item[
"sub_type"] == $sub_obj_type) {
1037 $res[] = $item[
"sub_id"];
1053 array $a_object_types,
1055 string $a_search_type
1067 if (
sizeof($objects)) {
1095 public function _clone(
int $a_new_record_id): self
1097 $class = get_class($this);
1098 $obj =
new $class();
1099 $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)
Interface GlobalHttpState.
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isRequired()
Is required field.
AMD field abstract base class.
save(bool $a_keep_pos=false)
Create new field entry.
searchSubObjects(ilADTSearchBridge $a_adt_search, int $a_obj_id, string $sub_obj_type)
read(?int $a_field_id)
Read field definition.
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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='')
const SUBACTION_FIELD_SEARCHABLE
getDBProperties()
Get all definition properties for DB.
_clone(int $a_new_record_id)
Clone field definition.
prepareCustomDefinitionFormConfirmation(ilPropertyFormGUI $a_form)
xmlEndTag(string $tag)
Writes an endtag.
setValue(string $a_value)
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.
getLastPosition()
Get last position of record.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getFieldDefinition()
Get (type-specific) field definition.
setADT(ilADT $a_adt)
Set ADT instance.
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.
RefineryFactory $refinery
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
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.
setFieldId(int $a_id)
Set 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)
__construct(?int $a_field_id=null, string $language='')