ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDclReferenceFieldModel.php
Go to the documentation of this file.
1 <?php
2 
20 {
21  public const PROP_REFERENCE = 'table_id';
22  public const PROP_N_REFERENCE = 'multiple_selection';
23 
30  public function getRecordQuerySortObject(
31  string $direction = "asc",
32  bool $sort_by_status = false
34  global $DIC;
35  $ilDB = $DIC['ilDB'];
36 
37  if (
38  $this->hasProperty(self::PROP_N_REFERENCE) ||
39  $this->getProperty(self::PROP_REFERENCE) === null ||
40  ilDclCache::getFieldCache((int) $this->getProperty(self::PROP_REFERENCE))->getTableId() === 0
41  ) {
42  return null;
43  }
44 
45  $ref_field = ilDclCache::getFieldCache((int) $this->getProperty(self::PROP_REFERENCE));
46 
47  $select_str = "stloc_{$this->getId()}_joined.value AS field_{$this->getId()},";
48  $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 = "
49  . $ilDB->quote($this->getId(), 'integer') . ") ";
50  $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) ";
51  $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 = "
52  . $ilDB->quote($ref_field->getId(), 'integer') . ") ";
53  $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) ";
54 
55  $sql_obj = new ilDclRecordQueryObject();
56  $sql_obj->setSelectStatement($select_str);
57  $sql_obj->setJoinStatement($join_str);
58  $sql_obj->setOrderStatement("field_{$this->getId()} " . $direction . ", ID ASC");
59 
60  return $sql_obj;
61  }
62 
63  public function getRecordQueryFilterObject(
64  $filter_value = "",
65  ?ilDclBaseFieldModel $sort_field = null
67  global $DIC;
68  $ilDB = $DIC['ilDB'];
69 
71 
72  $join_str
73  = " 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 = "
74  . $ilDB->quote($this->getId(), 'integer') . ") ";
75  $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) ";
76 
77  $where_str = " AND ";
78 
79  if ($filter_value == 'none') {
80  $where_str .= "("
81  . "filter_stloc_{$this->getId()}.value IS NULL "
82  . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("", 'text')
83  . " OR filter_stloc_{$this->getId()}.value = " . $ilDB->quote("[]", 'text')
84  . ") ";
85  } else {
86  if ($n_ref) {
87  $where_str
88  .= " filter_stloc_{$this->getId()}.value LIKE "
89  . $ilDB->quote("%$filter_value%", 'text');
90  } else {
91  $where_str
92  .= " filter_stloc_{$this->getId()}.value = "
93  . $ilDB->quote($filter_value, 'integer');
94  }
95  }
96 
97  $sql_obj = new ilDclRecordQueryObject();
98  $sql_obj->setJoinStatement($join_str);
99  $sql_obj->setWhereStatement($where_str);
100 
101  return $sql_obj;
102  }
103 
104  public function getValidFieldProperties(): array
105  {
109  ];
110  }
111 
112  public function allowFilterInListView(): bool
113  {
114  //A reference-field is not filterable if the referenced field is of datatype MOB or File
115  $ref_field = $this->getFieldRef();
116 
117  return !($ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB
118  || $ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILE);
119  }
120 
121  public function getFieldRef(): ilDclBaseFieldModel
122  {
124  }
125 
126  public function afterClone(array $records): void
127  {
130  $reference_clone = ilDclCache::getCloneOf(
131  (int) $clone->getProperty(ilDclBaseFieldModel::PROP_REFERENCE),
133  );
134  if ($reference_clone) {
135  $this->setProperty(ilDclBaseFieldModel::PROP_REFERENCE, $reference_clone->getId());
136  $this->updateProperties();
137  }
138  parent::afterClone($records);
139  }
140 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
hasProperty(string $key)
Checks if a certain property for a field is set.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getFieldCache(int $field_id=0)
getRecordQuerySortObject(string $direction="asc", bool $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateProperties()
Update properties of this field in Database.
global $DIC
Definition: feed.php:28
getRecordQueryFilterObject( $filter_value="", ?ilDclBaseFieldModel $sort_field=null)
getProperty(string $key)
Returns a certain property of a field.
static getCloneOf(int $id, string $type)
setProperty(string $key, $value)
Set a property for a field (does not save)