ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclReferenceFieldModel.php
Go to the documentation of this file.
1<?php
2
10{
11 const PROP_REFERENCE = 'table_id';
12 const PROP_N_REFERENCE = 'multiple_selection';
13
14
23 public function getRecordQuerySortObject($direction = "asc", $sort_by_status = false)
24 {
25 global $DIC;
26 $ilDB = $DIC['ilDB'];
27
28 if ($this->hasProperty(self::PROP_N_REFERENCE)) {
29 return null;
30 }
31
32 $ref_field = ilDclCache::getFieldCache($this->getProperty(self::PROP_REFERENCE));
33
34 $select_str = "stloc_{$this->getId()}_joined.value AS field_{$this->getId()},";
35 $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 = "
36 . $ilDB->quote($this->getId(), 'integer') . ") ";
37 $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) ";
38 $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 = "
39 . $ilDB->quote($ref_field->getId(), 'integer') . ") ";
40 $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) ";
41
42 $sql_obj = new ilDclRecordQueryObject();
43 $sql_obj->setSelectStatement($select_str);
44 $sql_obj->setJoinStatement($join_str);
45 $sql_obj->setOrderStatement("field_{$this->getId()} " . $direction);
46
47
48 return $sql_obj;
49 }
50
51
59 public function getRecordQueryFilterObject($filter_value = "", ilDclBaseFieldModel $sort_field = null)
60 {
61 global $DIC;
62 $ilDB = $DIC['ilDB'];
63
65
66 $join_str
67 = " 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 = "
68 . $ilDB->quote($this->getId(), 'integer') . ") ";
69 $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) ";
70
71 $where_str = " AND ";
72
73 if ($filter_value == 'none') {
74 $where_str .= "("
75 . "filter_stloc_{$this->getId()}.value IS NULL "
76 . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("", 'text')
77 . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("[]", 'text')
78 . ") ";
79 } else {
80 if ($n_ref) {
81 $where_str
82 .= " filter_stloc_{$this->getId()}.value LIKE "
83 . $ilDB->quote("%$filter_value%", 'text');
84 } else {
85 $where_str
86 .= " filter_stloc_{$this->getId()}.value = "
87 . $ilDB->quote($filter_value, 'integer');
88 }
89 }
90
91 $sql_obj = new ilDclRecordQueryObject();
92 $sql_obj->setJoinStatement($join_str);
93 $sql_obj->setWhereStatement($where_str);
94
95 return $sql_obj;
96 }
97
98
102 public function getValidFieldProperties()
103 {
105 }
106
107
111 public function allowFilterInListView()
112 {
113 //A reference-field is not filterable if the referenced field is of datatype MOB or File
114 $ref_field = $this->getFieldRef();
115
116 return !($ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB
117 || $ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILE);
118 }
119
120
121 public function getFieldRef()
122 {
124 }
125
126
127 public function afterClone($records)
128 {
131 $reference_clone = ilDclCache::getCloneOf((int) $clone->getProperty(ilDclBaseFieldModel::PROP_REFERENCE), ilDclCache::TYPE_FIELD);
132 if ($reference_clone) {
133 $this->setProperty(ilDclBaseFieldModel::PROP_REFERENCE, $reference_clone->getId());
134 $this->updateProperties();
135 }
136 parent::afterClone($records);
137 }
138}
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseFieldModel.
updateProperties()
Update properties of this field in Database.
setProperty($key, $value)
Set a property for a field (does not save)
hasProperty($key)
Checks if a certain property for a field is set.
getProperty($key)
Returns a certain property of a field.
static getCloneOf($id, $type)
static getFieldCache($field_id=0)
Class ilDclRecordQueryObject.
Class ilDclReferenceFieldModel.
getRecordQueryFilterObject($filter_value="", ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.
getRecordQuerySortObject($direction="asc", $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
global $DIC
Definition: goto.php:24
global $ilDB