ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAdvancedMDFieldDefinition.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "Services/ADT/classes/class.ilADTFactory.php";
5 
15 {
16  protected $field_id; // [int]
17  protected $record_id; // [int]
18  protected $import_id; // [string]
19  protected $position; // [int]
20  protected $title; // [string]
21  protected $description; // [string]
22  protected $searchable; // [bool]
23  protected $required; // [bool]
24  protected $adt_def; // [ilADTDefinition]
25  protected $adt; // [ilADT]
26 
30  protected $language = '';
31 
32  const TYPE_SELECT = 1;
33  const TYPE_TEXT = 2;
34  const TYPE_DATE = 3;
35  const TYPE_DATETIME = 4;
36  const TYPE_INTEGER = 5;
37  const TYPE_FLOAT = 6;
38  const TYPE_LOCATION = 7;
39  const TYPE_SELECT_MULTI = 8;
40  const TYPE_ADDRESS = 99;
41  const TYPE_EXTERNAL_LINK = 9;
42  const TYPE_INTERNAL_LINK = 10;
43 
47  protected $logger;
48 
55  public function __construct($a_field_id = null, string $language = '')
56  {
57  global $DIC;
58 
59  $this->language = $DIC->language()->getLangKey();
60  $this->logger = $DIC->logger()->amet();
61  if ($language) {
62  $this->language = $language;
63  }
64 
65  $this->init();
66  $this->read($a_field_id);
67  }
68 
76  public static function getInstance($a_field_id, $a_type = null, string $language = '')
77  {
78  global $DIC;
79 
80  $ilDB = $DIC['ilDB'];
81 
82  if (!$a_type) {
83  $set = $ilDB->query("SELECT field_type" .
84  " FROM adv_mdf_definition" .
85  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
86  $a_type = $ilDB->fetchAssoc($set);
87  $a_type = $a_type["field_type"];
88  }
89 
90  if (self::isValidType($a_type)) {
91  $class = "ilAdvancedMDFieldDefinition" . self::getTypeString($a_type);
92  require_once "Services/AdvancedMetaData/classes/Types/class." . $class . ".php";
93  return new $class($a_field_id, $language);
94  }
95 
96  throw new ilException("unknown type " . $a_type);
97  }
98 
104  public static function exists($a_field_id)
105  {
106  global $DIC;
107 
108  $ilDB = $DIC['ilDB'];
109 
110  $set = $ilDB->query("SELECT field_type" .
111  " FROM adv_mdf_definition" .
112  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer"));
113  if ($ilDB->fetchAssoc($set)) {
114  return true;
115  }
116  return false;
117  }
118 
125  public static function getInstanceByTypeString($a_type)
126  {
127  // see self::getTypeString()
128  $map = array(
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"
140  );
141  $map = array_flip($map);
142  if (array_key_exists($a_type, $map)) {
143  return self::getInstance(null, $map[$a_type]);
144  }
145  }
146 
154  public static function getInstancesByRecordId($a_record_id, $a_only_searchable = false, string $language = '')
155  {
156  global $DIC;
157 
158  $ilDB = $DIC['ilDB'];
159 
160  $defs = array();
161 
162  $query = "SELECT * FROM adv_mdf_definition" .
163  " WHERE record_id = " . $ilDB->quote($a_record_id, "integer");
164  if ($a_only_searchable) {
165  $query .= " AND searchable = " . $ilDB->quote(1, "integer");
166  }
167  $query .= " ORDER BY position";
168  $set = $ilDB->query($query);
169  while ($row = $ilDB->fetchAssoc($set)) {
170  $field = self::getInstance(null, $row["field_type"], $language);
171  $field->import($row);
172  $defs[$row["field_id"]] = $field;
173  }
174 
175  return $defs;
176  }
177 
178  public static function getInstancesByObjType($a_obj_type, $a_active_only = true)
179  {
180  global $DIC;
181 
182  $ilDB = $DIC['ilDB'];
183 
184  $defs = array();
185 
186  $query = "SELECT amf.* FROM adv_md_record_objs aro" .
187  " JOIN adv_md_record amr ON aro.record_id = amr.record_id" .
188  " JOIN adv_mdf_definition amf ON aro.record_id = amf.record_id" .
189  " WHERE obj_type = " . $ilDB->quote($a_obj_type, 'text');
190  if ((bool) $a_active_only) {
191  $query .= " AND active = " . $ilDB->quote(1, "integer");
192  }
193  $query .= " ORDER BY aro.record_id,position";
194  $res = $ilDB->query($query);
195  while ($row = $ilDB->fetchAssoc($res)) {
196  $field = self::getInstance(null, $row["field_type"]);
197  $field->import($row);
198  $defs[$row["field_id"]] = $field;
199  }
200  return $defs;
201  }
202 
209  public static function getInstanceByImportId($a_import_id)
210  {
211  global $DIC;
212 
213  $ilDB = $DIC['ilDB'];
214 
215  $query = "SELECT field_id, field_type FROM adv_mdf_definition" .
216  " WHERE import_id = " . $ilDB->quote($a_import_id, 'text');
217  $set = $ilDB->query($query);
218  if ($ilDB->numRows($set)) {
219  $row = $ilDB->fetchAssoc($set);
220  return self::getInstance($row["field_id"], $row["field_type"]);
221  }
222  }
223 
229  public static function getSearchableDefinitionIds()
230  {
231  global $DIC;
232 
233  $ilDB = $DIC['ilDB'];
234 
235  $field_ids = array();
236 
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");
241  $set = $ilDB->query($query);
242  while ($row = $ilDB->fetchAssoc($set)) {
243  $field_ids[] = $row["field_id"];
244  }
245  return $field_ids;
246  }
247 
254  public static function getADTGroupForDefinitions(array $a_defs)
255  {
257  $group_def = $factory->getDefinitionInstanceByType("Group");
258  foreach ($a_defs as $def) {
259  $group_def->addElement($def->getFieldId(), $def->getADTDefinition());
260  }
261  $group = $factory->getInstanceByDefinition($group_def);
262 
263  // bind adt instances to definition
264  foreach ($group->getElements() as $element_id => $element) {
265  $a_defs[$element_id]->setADT($element);
266  }
267 
268  return $group;
269  }
270 
274  protected function init()
275  {
276  $this->setRequired(false);
277  $this->setSearchable(false);
278  }
279 
280 
281  //
282  // generic types
283  //
284 
290  public static function getValidTypes()
291  {
292  return array(
293  self::TYPE_TEXT,
294  self::TYPE_DATE,
295  self::TYPE_DATETIME,
296  self::TYPE_SELECT,
297  self::TYPE_INTEGER,
298  self::TYPE_FLOAT,
299  self::TYPE_LOCATION,
300  self::TYPE_SELECT_MULTI,
301  self::TYPE_EXTERNAL_LINK,
302  self::TYPE_INTERNAL_LINK,
303  self::TYPE_ADDRESS
304  );
305  }
306 
313  public static function isValidType($a_type)
314  {
315  return in_array((int) $a_type, self::getValidTypes());
316  }
317 
323  abstract public function getType();
324 
331  protected static function getTypeString($a_type)
332  {
333  if (self::isValidType($a_type)) {
334  $map = array(
335  self::TYPE_TEXT => "Text",
336  self::TYPE_SELECT => "Select",
337  self::TYPE_DATE => "Date",
338  self::TYPE_DATETIME => "DateTime",
339  self::TYPE_FLOAT => "Float",
340  self::TYPE_LOCATION => "Location",
341  self::TYPE_INTEGER => "Integer",
342  self::TYPE_SELECT_MULTI => "SelectMulti" ,
343  self::TYPE_EXTERNAL_LINK => 'ExternalLink',
344  self::TYPE_INTERNAL_LINK => 'InternalLink',
345  self::TYPE_ADDRESS => "Address"
346  );
347  return $map[$a_type];
348  }
349  }
350 
355  public function useDefaultLanguageMode(string $language)
356  {
357  if (!strlen($language)) {
358  return true;
359  }
360  $record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
361  return strcmp($record->getDefaultLanguage(), $language) === 0;
362  }
363 
369  public function getTypeTitle()
370  {
371  // :TODO: reuse udf stuff here ?!
372  return "udf_type_" . strtolower(self::getTypeString($this->getType()));
373  }
374 
375 
376 
377  //
378  // ADT
379  //
380 
386  abstract protected function initADTDefinition();
387 
393  public function getADTDefinition()
394  {
395  if (!$this->adt_def instanceof ilADTDefinition) {
396  $this->adt_def = $this->initADTDefinition();
397  }
398  return $this->adt_def;
399  }
400 
406  public function getADT()
407  {
408  if (!$this->adt instanceof ilADT) {
409  $this->adt = ilADTFactory::getInstance()->getInstanceByDefinition($this->getADTDefinition());
410  }
411  return $this->adt;
412  }
413 
420  protected function setADT(ilADT $a_adt)
421  {
422  if (!$this->adt instanceof ilADT) {
423  $this->adt = $a_adt;
424  }
425  }
426 
427  //
428  // properties
429  //
430 
436  protected function setFieldId($a_id)
437  {
438  $this->field_id = (int) $a_id;
439  }
440 
446  public function getFieldId()
447  {
448  return $this->field_id;
449  }
450 
456  public function setRecordId($a_id)
457  {
458  $this->record_id = (int) $a_id;
459  }
460 
466  public function getRecordId()
467  {
468  return $this->record_id;
469  }
470 
476  public function setImportId($a_id_string)
477  {
478  if ($a_id_string !== null) {
479  $a_id_string = trim($a_id_string);
480  }
481  $this->import_id = $a_id_string;
482  }
483 
489  public function getImportId()
490  {
491  return $this->import_id;
492  }
493 
499  public function setPosition($a_pos)
500  {
501  $this->position = (int) $a_pos;
502  }
503 
509  public function getPosition()
510  {
511  return $this->position;
512  }
513 
519  public function setTitle($a_title)
520  {
521  if ($a_title !== null) {
522  $a_title = trim($a_title);
523  }
524  $this->title = $a_title;
525  }
526 
532  public function getTitle()
533  {
534  return $this->title;
535  }
536 
542  public function setDescription($a_desc)
543  {
544  if ($a_desc !== null) {
545  $a_desc = trim($a_desc);
546  }
547  $this->description = $a_desc;
548  }
549 
555  public function getDescription()
556  {
557  return $this->description;
558  }
559 
565  public function isSearchSupported()
566  {
567  return true;
568  }
569 
575  public function isFilterSupported()
576  {
577  return true;
578  }
579 
585  public function setSearchable($a_status)
586  {
587  // see above
588  if (!$this->isSearchSupported()) {
589  $a_status = false;
590  }
591  $this->searchable = (bool) $a_status;
592  }
593 
599  public function isSearchable()
600  {
601  return $this->searchable;
602  }
603 
609  public function setRequired($a_status)
610  {
611  $this->required = (bool) $a_status;
612  }
613 
619  public function isRequired()
620  {
621  return $this->required;
622  }
623 
624 
625  //
626  // definition (NOT ADT-based)
627  //
628 
634  protected function importFieldDefinition(array $a_def)
635  {
636  }
637 
643  protected function getFieldDefinition()
644  {
645  // type-specific properties
646  }
647 
653  public function getFieldDefinitionForTableGUI(string $content_language)
654  {
655  // type-specific properties
656  }
657 
664  protected function addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled = false, string $language = '')
665  {
666  // type-specific
667  }
668 
675  public function addToFieldDefinitionForm(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $language = '')
676  {
677  global $DIC;
678 
679  $lng = $DIC['lng'];
680 
681  $perm = $a_permissions->hasPermissions(
683  $this->getFieldId(),
684  array(
693  )
694  );
695 
696  // title
698 
699  $title = new ilTextInputGUI($lng->txt('title'), 'title');
700  $title->setValue($this->getTitle());
701  $title->setSize(20);
702  $title->setMaxLength(70);
703  $title->setRequired(true);
704  if ($this->getFieldId()) {
705  $translations->modifyTranslationInfoForTitle($this->getFieldId(), $a_form, $title, $language);
706  }
707  else {
708  $title->setValue($this->getTitle());
709  }
710 
711 
712  $a_form->addItem($title);
713 
715  $title->setDisabled(true);
716  }
717 
718  // desc
719  $desc = new ilTextAreaInputGUI($lng->txt('description'), 'description');
720  $desc->setValue($this->getDescription());
721  $desc->setRows(3);
722  $desc->setCols(50);
723  if ($this->getFieldId()) {
724  $translations->modifyTranslationInfoForDescription($this->getFieldId(), $a_form, $desc, $language);
725  }
726  else {
727  $desc->setValue($this->getDescription());
728  }
729 
730  $a_form->addItem($desc);
731 
732 
734  $desc->setDisabled(true);
735  }
736 
737  // searchable
738  $check = new ilCheckboxInputGUI($lng->txt('md_adv_searchable'), 'searchable');
739  $check->setChecked($this->isSearchable());
740  $check->setValue(1);
741  $a_form->addItem($check);
742 
744  !$this->isSearchSupported()) {
745  $check->setDisabled(true);
746  }
747 
748  /* required
749  $check = new ilCheckboxInputGUI($lng->txt('md_adv_required'), 'required');
750  $check->setChecked($this->isRequired());
751  $check->setValue(1);
752  $a_form->addItem($check);
753  */
754 
756  $a_form,
758  $language
759  );
760  }
761 
768  {
769  // type-specific
770  }
771 
778  public function importDefinitionFormPostValues(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $active_language)
779  {
780  $record = ilAdvancedMDRecord::_getInstanceByRecordId($this->record_id);
781  $is_translation = (($active_language !== '') && ($active_language != $record->getDefaultLanguage()));
782  if (!$a_form->getItemByPostVar("title")->getDisabled() && !$is_translation) {
783  $this->setTitle($a_form->getInput("title"));
784  }
785  if (!$a_form->getItemByPostVar("description")->getDisabled() && !$is_translation) {
786  $this->setDescription($a_form->getInput("description"));
787  }
788  if (!$a_form->getItemByPostVar("searchable")->getDisabled()) {
789  $this->setSearchable($a_form->getInput("searchable"));
790  }
791 
792  if ($a_permissions->hasPermission(
794  $this->getFieldId(),
797  )) {
798  $this->importCustomDefinitionFormPostValues($a_form, $active_language);
799  }
800  }
801 
803  {
804  return false;
805  }
806 
808  {
809  // type-specific
810  }
811 
813  {
814  $a_form->getItemByPostVar("title")->setDisabled(true);
815  $a_form->getItemByPostVar("description")->setDisabled(true);
816  $a_form->getItemByPostVar("searchable")->setDisabled(true);
817 
818  // checkboxes have no hidden on disabled
819  if ($a_form->getInput("searchable")) {
820  $hidden = new ilHiddenInputGUI("searchable");
821  $hidden->setValue(1);
822  $a_form->addItem($hidden);
823  }
824 
826  }
827 
828 
829  //
830  // definition CRUD
831  //
832 
838  protected function getLastPosition()
839  {
840  global $DIC;
841 
842  $ilDB = $DIC['ilDB'];
843 
844  $sql = "SELECT max(position) pos" .
845  " FROM adv_mdf_definition" .
846  " WHERE record_id = " . $ilDB->quote($this->getRecordId(), "integer");
847  $set = $ilDB->query($sql);
848  if ($ilDB->numRows($set)) {
849  $pos = $ilDB->fetchAssoc($set);
850  return (int) $pos["pos"];
851  }
852 
853  return 0;
854  }
855 
862  public function generateImportId($a_field_id)
863  {
864  return 'il_' . IL_INST_ID . '_adv_md_field_' . $a_field_id;
865  }
866 
872  protected function getDBProperties()
873  {
874  $fields = array(
875  "field_type" => array("integer", $this->getType()),
876  "record_id" => array("integer", $this->getRecordId()),
877  "import_id" => array("text", $this->getImportId()),
878  "title" => array("text", $this->getTitle()),
879  "description" => array("text", $this->getDescription()),
880  "position" => array("integer", $this->getPosition()),
881  "searchable" => array("integer", $this->isSearchable()),
882  "required" => array("integer", $this->isRequired())
883  );
884 
885  $def = $this->getFieldDefinition();
886  if (is_array($def)) {
887  $fields["field_values"] = array("text", serialize($def));
888  }
889 
890  return $fields;
891  }
892 
898  protected function import(array $a_data)
899  {
900  $this->setFieldId($a_data["field_id"]);
901 
902  $this->setRecordId($a_data["record_id"]);
903  $this->setImportId($a_data["import_id"]);
904  $this->setTitle($a_data["title"]);
905  $this->setDescription($a_data["description"]);
906  $this->setPosition($a_data["position"]);
907  $this->setSearchable($a_data["searchable"]);
908  $this->setRequired($a_data["required"]);
909  $field_values = unserialize($a_data['field_values']);
910  if ($a_data["field_values"] && is_array($field_values)) {
911  $this->importFieldDefinition($field_values);
912  }
913  }
914 
918  protected function read($a_field_id)
919  {
920  global $DIC;
921 
922  $ilDB = $DIC['ilDB'];
923 
924  if (!(int) $a_field_id) {
925  return;
926  }
927 
928  $sql = "SELECT * FROM adv_mdf_definition" .
929  " WHERE field_id = " . $ilDB->quote($a_field_id, "integer");
930  $set = $ilDB->query($sql);
931  if ($ilDB->numRows($set)) {
932  $row = $ilDB->fetchAssoc($set);
933  $this->import($row);
934  }
935  }
936 
940  public function save($a_keep_pos = false)
941  {
942  global $DIC;
943 
944  $ilDB = $DIC['ilDB'];
945 
946  if ($this->getFieldId()) {
947  return $this->update();
948  }
949 
950  $next_id = $ilDB->nextId("adv_mdf_definition");
951 
952  // append
953  if (!$a_keep_pos) {
954  $this->setPosition($this->getLastPosition() + 1);
955  }
956 
957  // needs unique import id
958  if (!$this->getImportId()) {
959  $this->setImportId($this->generateImportId($next_id));
960  }
961 
962  $fields = $this->getDBProperties();
963  $fields["field_id"] = array("integer", $next_id);
964 
965  $ilDB->insert("adv_mdf_definition", $fields);
966 
967  $this->setFieldId($next_id);
968  }
969 
973  public function update()
974  {
975  global $DIC;
976 
977  $ilDB = $DIC['ilDB'];
978 
979  if (!$this->getFieldId()) {
980  return $this->save();
981  }
982 
983  $ilDB->update(
984  "adv_mdf_definition",
985  $this->getDBProperties(),
986  array("field_id" => array("integer", $this->getFieldId()))
987  );
988  }
989 
993  public function delete()
994  {
995  global $DIC;
996 
997  $ilDB = $DIC['ilDB'];
998 
999  if (!$this->getFieldId()) {
1000  return;
1001  }
1002 
1003  // delete all values
1004  include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
1006 
1007  $query = "DELETE FROM adv_mdf_definition" .
1008  " WHERE field_id = " . $ilDB->quote($this->getFieldId(), "integer");
1009  $ilDB->manipulate($query);
1010  }
1011 
1012 
1013  //
1014  // export/import
1015  //
1016 
1024  public function toXML(ilXmlWriter $a_writer)
1025  {
1026  $a_writer->xmlStartTag('Field', array(
1027  'id' => $this->generateImportId($this->getFieldId()),
1028  'searchable' => ($this->isSearchable() ? 'Yes' : 'No'),
1029  'fieldType' => self::getTypeString($this->getType())));
1030 
1031  $a_writer->xmlElement('FieldTitle', null, $this->getTitle());
1032  $a_writer->xmlElement('FieldDescription', null, $this->getDescription());
1033 
1035  $a_writer->xmlStartTag('FieldTranslations');
1036  foreach ($translations->getTranslations($this->getFieldId()) as $translation) {
1037  $a_writer->xmlStartTag('FieldTranslation', ['language' => $translation->getLangKey()]);
1038  $a_writer->xmlElement('FieldTranslationTitle', [], (string) $translation->getTitle());
1039  $a_writer->xmlElement('FieldTranslationDescription',[], (string) $translation->getDescription());
1040  $a_writer->xmlEndTag('FieldTranslation');
1041  }
1042  $a_writer->xmlEndTag('FieldTranslations');
1043  $a_writer->xmlElement('FieldPosition', null, $this->getPosition());
1044 
1045  $this->addPropertiesToXML($a_writer);
1046 
1047  $a_writer->xmlEndTag('Field');
1048  }
1049 
1055  protected function addPropertiesToXML(ilXmlWriter $a_writer)
1056  {
1057  // type-specific properties
1058  }
1059 
1066  public function importXMLProperty($a_key, $a_value)
1067  {
1068  }
1069 
1076  abstract public function getValueForXML(ilADT $element);
1077 
1083  abstract public function importValueFromXML($a_cdata);
1084 
1093  public function importFromECS($a_ecs_type, $a_value, $a_sub_id)
1094  {
1095  return false;
1096  }
1097 
1098 
1099  //
1100  // presentation
1101  //
1102 
1108  public function prepareElementForEditor(ilADTFormBridge $a_bridge)
1109  {
1110  // type-specific
1111  }
1112 
1113 
1114  //
1115  // search
1116  //
1117 
1124  public function getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
1125  {
1126  return '';
1127  }
1128 
1135  public function getSearchValueSerialized(ilADTSearchBridge $a_adt_search)
1136  {
1137  return $a_adt_search->getSerializedValue();
1138  }
1139 
1146  public function setSearchValueSerialized(ilADTSearchBridge $a_adt_search, $a_value)
1147  {
1148  return $a_adt_search->setSerializedValue($a_value);
1149  }
1150 
1158  protected function parseSearchObjects(array $a_records, array $a_object_types)
1159  {
1160  global $DIC;
1161 
1162  $ilDB = $DIC['ilDB'];
1163 
1164  $res = array();
1165 
1166  $obj_ids = array();
1167  foreach ($a_records as $record) {
1168  if ($record["sub_type"] == "-") {
1169  $obj_ids[] = $record["obj_id"];
1170  }
1171  }
1172 
1173  $sql = "SELECT obj_id,type" .
1174  " FROM object_data" .
1175  " WHERE " . $ilDB->in("obj_id", $obj_ids, "", "integer") .
1176  " AND " . $ilDB->in("type", $a_object_types, "", "text");
1177  $set = $ilDB->query($sql);
1178  while ($row = $ilDB->fetchAssoc($set)) {
1179  $res[] = $row;
1180  }
1181 
1182  return $res;
1183  }
1184 
1185  public function searchSubObjects(ilADTSearchBridge $a_adt_search, $a_obj_id, $sub_obj_type)
1186  {
1187  include_once('Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
1189 
1190  // :TODO:
1191  if ($a_adt_search instanceof ilADTLocationSearchBridgeSingle) {
1192  $element_id = "loc";
1193  }
1194 
1195  $condition = $a_adt_search->getSQLCondition($element_id);
1196  if ($condition) {
1197  $objects = ilADTActiveRecordByType::find("adv_md_values", $this->getADT()->getType(), $this->getFieldId(), $condition);
1198  if (sizeof($objects)) {
1199  $res = array();
1200  foreach ($objects as $item) {
1201  if ($item["obj_id"] == $a_obj_id &&
1202  $item["sub_type"] == $sub_obj_type) {
1203  $res[] = $item["sub_id"];
1204  }
1205  }
1206  return $res;
1207  }
1208  }
1209 
1210  return array();
1211  }
1212 
1223  public function searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
1224  {
1225  // search type only supported/needed for text
1226  include_once('Services/ADT/classes/ActiveRecord/class.ilADTActiveRecordByType.php');
1227  $condition = $a_adt_search->getSQLCondition(ilADTActiveRecordByType::SINGLE_COLUMN_NAME);
1228  if ($condition) {
1229  $objects = ilADTActiveRecordByType::find("adv_md_values", $this->getADT()->getType(), $this->getFieldId(), $condition, $a_locate);
1230  if (sizeof($objects)) {
1231  return $this->parseSearchObjects($objects, $a_object_types);
1232  }
1233  return array();
1234  }
1235  }
1236 
1243  public function getLuceneSearchString($a_value)
1244  {
1245  return $a_value;
1246  }
1247 
1253  public function prepareElementForSearch(ilADTSearchBridge $a_bridge)
1254  {
1255  // type-specific
1256  }
1257 
1264  public function _clone($a_new_record_id)
1265  {
1266  $class = get_class($this);
1267  $obj = new $class();
1268  $obj->setRecordId($a_new_record_id);
1269  $obj->setTitle($this->getTitle());
1270  $obj->setDescription($this->getDescription());
1271  $obj->setRequired($this->isRequired());
1272  $obj->setPosition($this->getPosition());
1273  $obj->setSearchable($this->isSearchable());
1274  $obj->importFieldDefinition((array) $this->getFieldDefinition());
1275  $obj->save(true);
1276 
1277  return $obj;
1278  }
1279  //
1280  // complex options
1281  //
1282 
1283  public function hasComplexOptions()
1284  {
1285  return false;
1286  }
1287 
1293  public function getComplexOptionsOverview($a_parent_gui, string $parent_cmd) : ?string
1294  {
1295  return null;
1296  }
1297 }
parseSearchObjects(array $a_records, array $a_object_types)
Add object-data needed for global search to AMD search results.
__construct($a_field_id=null, string $language='')
Constructor.
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
isFilterSupported()
Is search by filter supported.
setSearchValueSerialized(ilADTSearchBridge $a_adt_search, $a_value)
Set value from search persistence.
getItemByPostVar($a_post_var)
Get Item by POST variable.
const IL_INST_ID
Definition: constants.php:38
save($a_keep_pos=false)
Create new field entry.
This class represents a property form user interface.
hasPermissions($a_context_type, $a_context_id, array $a_action_ids)
Check permissions.
getADTDefinition()
Get ADT definition instance.
ADT form bridge base class.
importValueFromXML($a_cdata)
Import value from xml.
setValue($a_value)
Set Value.
searchSubObjects(ilADTSearchBridge $a_adt_search, $a_obj_id, $sub_obj_type)
static getADTGroupForDefinitions(array $a_defs)
Init ADTGroup for definitions.
XML writer class.
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
This class represents a checkbox property in a property form.
static _deleteByFieldId($a_field_id, ilADT $a_adt)
Delete values by field_id.
addItem($a_item)
Add Item (Property, SectionHeader).
importFromECS($a_ecs_type, $a_value, $a_sub_id)
Import meta data from ECS.
static getInstance()
Get singleton.
ADT base class.
Definition: class.ilADT.php:11
static getInstanceByImportId($a_import_id)
Get definition instance by import id.
xmlEndTag($tag)
Writes an endtag.
static getTypeString($a_type)
Get type string.
getDBProperties()
Get all definition properties for DB.
hasPermission($a_context_type, $a_context_id, $a_action_id, $a_action_sub_id=null)
Check permission.
prepareCustomDefinitionFormConfirmation(ilPropertyFormGUI $a_form)
setChecked($a_checked)
Set Checked.
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 exists($a_field_id)
Check if field exists.
This class represents a hidden form property in a property form.
static find($a_table, $a_type, $a_field_id, $a_condition, $a_additional_fields=null)
Find entries.
getSearchQueryParserValue(ilADTSearchBridge $a_adt_search)
Get value for search query parser.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
Advanced metadata permission helper.
getSearchValueSerialized(ilADTSearchBridge $a_adt_search)
Get value for search persistence.
foreach($_POST as $key=> $value) $res
$lng
static getSearchableDefinitionIds()
Get searchable definition ids (performance is key)
getFieldDefinitionForTableGUI(string $content_language)
Parse properties for table gui.
static getInstancesByObjType($a_obj_type, $a_active_only=true)
global $DIC
Definition: goto.php:24
setSearchable($a_status)
Toggle searchable.
generateImportId($a_field_id)
Generate unique record id.
$query
getLastPosition()
Get last position of record.
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
importXMLProperty($a_key, $a_value)
Import property from XML.
prepareElementForSearch(ilADTSearchBridge $a_bridge)
Prepare search form elements.
static getValidTypes()
Get all valid types.
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.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
setADT(ilADT $a_adt)
Set ADT instance.
addPropertiesToXML(ilXmlWriter $a_writer)
Add (type-specific) properties to xml export.
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...
read($a_field_id)
Read field definition.
_clone($a_new_record_id)
Clone field definition.
importFieldDefinition(array $a_def)
Import (type-specific) field definition from DB.
This class represents a text area property in a property form.
static getInstance($a_field_id, $a_type=null, string $language='')
Get definition instance by type.
global $ilDB
searchObjects(ilADTSearchBridge $a_adt_search, ilQueryParser $a_parser, array $a_object_types, $a_locate, $a_search_type)
Search objects.
initADTDefinition()
Init adt instance.
language()
Definition: language.php:2
addToFieldDefinitionForm(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions, string $language='')
Add input elements to definition form.
ADT definition base class.
isSearchSupported()
Is search supported at all.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
static getInstancesByRecordId($a_record_id, $a_only_searchable=false, string $language='')
Get definitions by record id.
addCustomFieldToDefinitionForm(ilPropertyFormGUI $a_form, $a_disabled=false, string $language='')
Add custom input elements to definition form.
$factory
Definition: metadata.php:58
getComplexOptionsOverview($a_parent_gui, string $parent_cmd)
static getInstanceByTypeString($a_type)
Get instance by type string (used by import)
static isValidType($a_type)
Is given type valid.
prepareDefinitionFormConfirmation(ilPropertyFormGUI $a_form)