ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDFieldDefinitionInternalLink.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 public function getType(): int
29 {
31 }
32
33 protected function initADTDefinition(): ilADTDefinition
34 {
35 return ilADTFactory::getInstance()->getDefinitionInstanceByType("InternalLink");
36 }
37
38 public function getValueForXML(ilADT $element): string
39 {
40 $type = ilObject::_lookupType($element->getTargetRefId(), true);
41
42 if ($element->getTargetRefId() && strlen($type)) {
43 return 'il_' . IL_INST_ID . '_' . $type . '_' . $element->getTargetRefId();
44 }
45 return '';
46 }
47
48 public function importValueFromXML(string $a_cdata): void
49 {
50 $parsed_import_id = ilUtil::parseImportId($a_cdata);
51
52 if (
53 (strcmp((string) $parsed_import_id['inst_id'], IL_INST_ID) == 0) &&
54 ilObject::_exists($parsed_import_id['id'], true, $parsed_import_id['type'])
55 ) {
56 $this->getADT()->setTargetRefId($parsed_import_id['id']);
57 }
58 }
59
60 public function searchObjects(
61 ilADTSearchBridge $a_adt_search,
62 ilQueryParser $a_parser,
63 array $a_object_types,
64 string $a_locate,
65 string $a_search_type
66 ): array {
67 $condition = $a_adt_search->getSQLCondition(ilADTActiveRecordByType::SINGLE_COLUMN_NAME);
68 if ($condition) {
70 "adv_md_values",
71 $this->getADT()->getType(),
72 $this->getFieldId(),
73 $condition,
74 $a_locate
75 );
76 if (!is_null($objects) && count($objects)) {
77 return $this->parseSearchObjects($objects, $a_object_types);
78 }
79 }
80 return [];
81 }
82
86 public function getLuceneSearchString($a_value): string
87 {
88 $query = 'select ref_id from object_reference obr join object_data obd on obr.obj_id = obd.obj_id ' .
89 'where ' . $this->db->like('title', 'text', $a_value . '%');
90 $res = $this->db->query($query);
91 $ref_ids = [];
92 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
93 $ref_ids[] = (int) $row->ref_id;
94 }
95 if (count($ref_ids)) {
96 return '(' . implode(' ', $ref_ids) . ') ';
97 }
98 return 'null';
99 }
100}
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.
ADT base class.
Definition: class.ilADT.php:26
parseSearchObjects(array $a_records, array $a_object_types)
Add object-data needed for global search to AMD search results.
static _lookupType(int $id, bool $reference=false)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static parseImportId(string $a_import_id)
Parse an ilias import id Typically of type il_[IL_INST_ID]_[OBJ_TYPE]_[OBJ_ID] returns array( 'orig' ...
const IL_INST_ID
Definition: constants.php:40
$res
Definition: ltiservices.php:69