ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
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 $n_ref = $this->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE);
70
71 $join_str
72 = " 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 = "
73 . $this->db->quote($this->getId(), 'integer') . ") ";
74 $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) ";
75
76 $where_str = " AND ";
77
78 if ($filter_value == 'none') {
79 $where_str .= "("
80 . "filter_stloc_{$this->getId()}.value IS NULL "
81 . " OR filter_stloc_{$this->getId()}.value = " . $this->db->quote("", 'text')
82 . " OR filter_stloc_{$this->getId()}.value = " . $this->db->quote("[]", 'text')
83 . ") ";
84 } else {
85 if ($n_ref) {
86 $where_str
87 .= " filter_stloc_{$this->getId()}.value LIKE " . $this->db->quote("%\"$filter_value\"%", 'text');
88 } else {
89 $where_str
90 .= " filter_stloc_{$this->getId()}.value = "
91 . $this->db->quote($filter_value, 'integer');
92 }
93 }
94
95 $sql_obj = new ilDclRecordQueryObject();
96 $sql_obj->setJoinStatement($join_str);
97 $sql_obj->setWhereStatement($where_str);
98
99 return $sql_obj;
100 }
101
102 public function getValidFieldProperties(): array
103 {
107 ];
108 }
109
110 public function allowFilterInListView(): bool
111 {
112 //A reference-field is not filterable if the referenced field is of datatype MOB or File
113 $ref_field = $this->getFieldRef();
114
115 return !($ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB
116 || $ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILEUPLOAD);
117 }
118
120 {
121 return ilDclCache::getFieldCache((int) $this->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
122 }
123
124 public function afterClone(array $records): void
125 {
127 $clone = ilDclCache::getCloneOf((int) $this->getId(), ilDclCache::TYPE_FIELD);
128 $reference_clone = ilDclCache::getCloneOf(
129 (int) $clone->getProperty(ilDclBaseFieldModel::PROP_REFERENCE),
131 );
132 if ($reference_clone) {
133 $this->setProperty(ilDclBaseFieldModel::PROP_REFERENCE, $reference_clone->getId());
134 $this->updateProperties();
135 }
136 parent::afterClone($records);
137 }
138}
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