ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDclReferenceFieldModel.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const PROP_REFERENCE = 'table_id';
24 public const PROP_N_REFERENCE = 'multiple_selection';
25
26
27 public function getRecordQuerySortObject(
28 string $direction = "asc",
29 bool $sort_by_status = false
31 global $DIC;
32 $ilDB = $DIC['ilDB'];
33
34 if (
35 $this->hasProperty(self::PROP_N_REFERENCE) ||
36 $this->getProperty(self::PROP_REFERENCE) === null ||
37 ilDclCache::getFieldCache((int) $this->getProperty(self::PROP_REFERENCE))->getTableId() === 0
38 ) {
39 return null;
40 }
41
42 $ref_field = ilDclCache::getFieldCache((int) $this->getProperty(self::PROP_REFERENCE));
43
44 //ATM, some referenced fields can not be sorted (Ratings, Formulas and Plugins), PR would be nice if fixeable.
45 if ($ref_field->getStorageLocation() == 0) {
46 return null;
47 }
48
49 $select_str = "stloc_{$this->getId()}_joined.value AS field_{$this->getId()},";
50 $join_str = "LEFT JOIN il_dcl_record_field AS record_field_{$this->getId()} ON (record_field_{$this->getId()}.record_id = record.id AND record_field_{$this->getId()}.field_id = "
51 . $ilDB->quote($this->getId(), 'integer') . ") ";
52 $join_str .= "LEFT JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS stloc_{$this->getId()} ON (stloc_{$this->getId()}.record_field_id = record_field_{$this->getId()}.id) ";
53 $join_str .= "LEFT JOIN il_dcl_record_field AS record_field_{$this->getId()}_joined ON (record_field_{$this->getId()}_joined.record_id = stloc_{$this->getId()}.value AND record_field_{$this->getId()}_joined.field_id = "
54 . $ilDB->quote($ref_field->getId(), 'integer') . ") ";
55 $join_str .= "LEFT JOIN il_dcl_stloc{$ref_field->getStorageLocation()}_value AS stloc_{$this->getId()}_joined ON (stloc_{$this->getId()}_joined.record_field_id = record_field_{$this->getId()}_joined.id) ";
56
57 $sql_obj = new ilDclRecordQueryObject();
58 $sql_obj->setSelectStatement($select_str);
59 $sql_obj->setJoinStatement($join_str);
60 $sql_obj->setOrderStatement("field_{$this->getId()} " . $direction . ", ID ASC");
61
62 return $sql_obj;
63 }
64
66 $filter_value = "",
67 ?ilDclBaseFieldModel $sort_field = null
69 global $DIC;
70 $ilDB = $DIC['ilDB'];
71
72 $n_ref = $this->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE);
73
74 $join_str
75 = " LEFT JOIN il_dcl_record_field AS filter_record_field_{$this->getId()} ON (filter_record_field_{$this->getId()}.record_id = record.id AND filter_record_field_{$this->getId()}.field_id = "
76 . $ilDB->quote($this->getId(), 'integer') . ") ";
77 $join_str .= " LEFT JOIN il_dcl_stloc{$this->getStorageLocation()}_value AS filter_stloc_{$this->getId()} ON (filter_stloc_{$this->getId()}.record_field_id = filter_record_field_{$this->getId()}.id) ";
78
79 $where_str = " AND ";
80
81 if ($filter_value == 'none') {
82 $where_str .= "("
83 . "filter_stloc_{$this->getId()}.value IS NULL "
84 . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("", 'text')
85 . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("[]", 'text')
86 . ") ";
87 } else {
88 if ($n_ref) {
89 $where_str
90 .= " filter_stloc_{$this->getId()}.value LIKE "
91 . $ilDB->quote("%$filter_value%", 'text');
92 } else {
93 $where_str
94 .= " filter_stloc_{$this->getId()}.value = "
95 . $ilDB->quote($filter_value, 'integer');
96 }
97 }
98
99 $sql_obj = new ilDclRecordQueryObject();
100 $sql_obj->setJoinStatement($join_str);
101 $sql_obj->setWhereStatement($where_str);
102
103 return $sql_obj;
104 }
105
106 public function getValidFieldProperties(): array
107 {
111 ];
112 }
113
114 public function allowFilterInListView(): bool
115 {
116 //A reference-field is not filterable if the referenced field is of datatype MOB or File
117 $ref_field = $this->getFieldRef();
118
119 return !($ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB
120 || $ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILEUPLOAD);
121 }
122
124 {
125 return ilDclCache::getFieldCache((int) $this->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
126 }
127
128 public function afterClone(array $records): void
129 {
131 $clone = ilDclCache::getCloneOf((int) $this->getId(), ilDclCache::TYPE_FIELD);
132 $reference_clone = ilDclCache::getCloneOf(
133 (int) $clone->getProperty(ilDclBaseFieldModel::PROP_REFERENCE),
135 );
136 if ($reference_clone) {
137 $this->setProperty(ilDclBaseFieldModel::PROP_REFERENCE, $reference_clone->getId());
138 $this->updateProperties();
139 }
140 parent::afterClone($records);
141 }
142}
hasProperty(string $key)
Checks if a certain property for a field is set.
static getFieldCache(int $field_id=0)
static getCloneOf(int $id, string $type)
getRecordQuerySortObject(string $direction="asc", bool $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
getValidFieldProperties()
Returns all valid properties for a field-type.
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.
global $DIC
Definition: shib_login.php:26