3declare(strict_types=1);
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);
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)) {
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 =
''
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;
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;
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"]);
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
272 $this->setRequired(
false);
273 $this->setSearchable(
false);
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()));
363 $this->adt_def = $this->initADTDefinition();
365 return $this->adt_def;
370 if (!$this->adt instanceof
ilADT) {
382 if (!$this->adt instanceof
ilADT) {
392 $this->field_id = $a_id;
400 return $this->field_id;
408 $this->record_id = $a_id;
416 return $this->record_id;
424 if ($a_id_string !==
null) {
425 $a_id_string = trim($a_id_string);
427 $this->import_id = $a_id_string;
435 return $this->import_id;
443 $this->position = $a_pos;
451 return $this->position;
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;
489 return $this->description;
514 if (!$this->isSearchSupported()) {
517 $this->searchable = (bool) $a_status;
525 return $this->searchable;
533 $this->required = $a_status;
541 return $this->required;
572 bool $a_disabled =
false,
573 string $language =
''
583 string $language =
''
588 $perm = $a_permissions->hasPermissions(
590 (
string) $this->getFieldId(),
614 $title->setValue($this->getTitle());
616 $title->setMaxLength(70);
617 $title->setRequired(
true);
618 if ($this->getFieldId()) {
619 $translations->modifyTranslationInfoForTitle($this->getFieldId(), $a_form, $title, $language);
621 $title->setValue($this->getTitle());
627 $title->setDisabled(
true);
632 $desc->setValue($this->getDescription());
635 if ($this->getFieldId()) {
636 $translations->modifyTranslationInfoForDescription($this->getFieldId(), $a_form, $desc, $language);
638 $desc->setValue($this->getDescription());
644 $desc->setDisabled(
true);
649 $check->setChecked($this->isSearchable());
654 !$this->isSearchSupported()) {
655 $check->setDisabled(
true);
665 $this->addCustomFieldToDefinitionForm(
686 string $active_language
689 $is_translation = (($active_language !==
'') && ($active_language != $record->getDefaultLanguage()));
690 if (!$a_form->
getItemByPostVar(
"title")->getDisabled() && !$is_translation) {
691 $this->setTitle($a_form->
getInput(
"title"));
693 if (!$a_form->
getItemByPostVar(
"description")->getDisabled() && !$is_translation) {
694 $this->setDescription($a_form->
getInput(
"description"));
697 $this->setSearchable((
bool) $a_form->
getInput(
"searchable"));
702 (
string) $this->getFieldId(),
706 $this->importCustomDefinitionFormPostValues($a_form, $active_language);
726 if ($a_form->
getInput(
"searchable")) {
728 $hidden->setValue(
"1");
732 $this->prepareCustomDefinitionFormConfirmation($a_form);
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()),
769 "description" => array(
"text", $this->getDescription()),
770 "position" => array(
"integer", $this->getPosition()),
771 "searchable" => array(
"integer", $this->isSearchable()),
772 "required" => array(
"integer", $this->isRequired())
775 $def = $this->getFieldDefinition();
776 if (is_array($def)) {
777 $fields[
"field_values"] = array(
"text", serialize($def));
785 protected function import(array $a_data):
void
787 $this->setFieldId((
int) $a_data[
"field_id"]);
789 $this->setImportId((
string) $a_data[
"import_id"]);
790 $this->setTitle((
string) $a_data[
"title"]);
791 $this->setDescription((
string) $a_data[
"description"]);
792 $this->setPosition((
int) $a_data[
"position"]);
793 $this->setSearchable((
bool) $a_data[
"searchable"]);
794 $this->setRequired((
bool) $a_data[
"required"]);
795 if (isset($a_data[
'field_values'])) {
796 $field_values = unserialize($a_data[
'field_values']);
797 if (is_array($field_values)) {
798 $this->importFieldDefinition($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
826 if ($this->getFieldId()) {
831 $next_id = $this->db->nextId(
"adv_mdf_definition");
835 $this->setPosition($this->getLastPosition() + 1);
839 if (!$this->getImportId()) {
840 $this->setImportId($this->generateImportId($next_id));
843 $fields = $this->getDBProperties();
844 $fields[
"field_id"] = array(
"integer", $next_id);
846 $this->db->insert(
"adv_mdf_definition", $fields);
848 $this->setFieldId($next_id);
856 if (!$this->getFieldId()) {
862 "adv_mdf_definition",
863 $this->getDBProperties(),
864 array(
"field_id" => array(
"integer", $this->getFieldId()))
871 public function delete():
void
873 if (!$this->getFieldId()) {
880 $query =
"DELETE FROM adv_mdf_definition" .
881 " WHERE field_id = " . $this->db->quote($this->getFieldId(),
"integer");
882 $this->db->manipulate(
$query);
893 'id' => $this->generateImportId($this->getFieldId()),
894 'searchable' => ($this->isSearchable() ?
'Yes' :
'No'),
895 'fieldType' => self::getTypeString($this->getType())
898 $a_writer->
xmlElement(
'FieldTitle',
null, $this->getTitle());
899 $a_writer->
xmlElement(
'FieldDescription',
null, $this->getDescription());
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');
918 $a_writer->
xmlElement(
'FieldPosition',
null, $this->getPosition());
920 $this->addPropertiesToXML($a_writer);
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";
1028 $this->getADT()->getType(),
1029 $this->getFieldId(),
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
1062 $this->getADT()->getType(),
1063 $this->getFieldId(),
1067 if (
sizeof($objects)) {
1068 return $this->parseSearchObjects($objects, $a_object_types);
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);
1100 $obj->setTitle($this->getTitle());
1101 $obj->setDescription($this->getDescription());
1102 $obj->setRequired($this->isRequired());
1103 $obj->setPosition($this->getPosition());
1104 $obj->setSearchable($this->isSearchable());
1105 $obj->importFieldDefinition($this->getFieldDefinition());
static return function(ContainerConfigurator $containerConfigurator)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
read(?int $a_field_id)
Read field definition.
getLuceneSearchString($a_value)
Get search string in lucene syntax.
getLastPosition()
Get last position of record.
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.
getFieldId()
Get field_id.
getDescription()
Get description.
getADTDefinition()
Get ADT definition instance.
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.
getDBProperties()
Get all definition properties for DB.
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.
__construct(?int $a_field_id=null, string $language='')
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()
save(bool $a_keep_pos=false)
Create new field entry.
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.
setFieldId(int $a_id)
Set field_id.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.