ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilDclReferenceFieldModel.php
Go to the documentation of this file.
1 <?php
2 require_once("./Modules/DataCollection/classes/Fields/Fileupload/class.ilDclFileuploadFieldModel.php");
3 require_once("./Modules/DataCollection/classes/Helpers/class.ilDclRecordQueryObject.php");
4 
12  const PROP_REFERENCE = 'table_id';
13  const PROP_N_REFERENCE = 'multiple_selection';
14 
23  public function getRecordQuerySortObject($direction = "asc", $sort_by_status = false){
24  global $DIC;
25  $ilDB = $DIC['ilDB'];
26 
27  $ref_field = ilDclCache::getFieldCache($this->getProperty(self::PROP_REFERENCE));
28  if($this->hasProperty(self::PROP_N_REFERENCE)) {
29  $n_ref = true;
30  }
31 
32  $select_str = ($n_ref) ? " ". $ilDB->groupConcat("stloc_{$this->getId()}_joined.value") . " AS field_{$this->getId()}" : "stloc_{$this->getId()}_joined.value AS field_{$this->getId()},";
33  $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 = "
34  . $ilDB->quote($this->getId(), 'integer') . ") ";
35  $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) ";
36  $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 = "
37  . $ilDB->quote($ref_field->getId(), 'integer') . ") ";
38  $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) ";
39 
40  $sql_obj = new ilDclRecordQueryObject();
41  $sql_obj->setSelectStatement($select_str);
42  $sql_obj->setJoinStatement($join_str);
43  $sql_obj->setOrderStatement("field_{$this->getId()} ".$direction);
44 
45  if($n_ref) {
46  $sql_obj->setGroupStatement("record.id, record.owner");
47  }
48 
49  return $sql_obj;
50  }
51 
52 
60  public function getRecordQueryFilterObject($filter_value = "", ilDclBaseFieldModel $sort_field = null) {
61  global $DIC;
62  $ilDB = $DIC['ilDB'];
63 
65 
66  $join_str =
67  " INNER 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 
70  if ($n_ref) {
71  $join_str .=
72  " INNER 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 AND filter_stloc_{$this->getId()}.value LIKE "
73  . $ilDB->quote("%$filter_value%", 'text') . ") ";
74  } else {
75  $join_str .=
76  " INNER 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 AND filter_stloc_{$this->getId()}.value = "
77  . $ilDB->quote($filter_value, 'integer') . ") ";
78  }
79 
80  $sql_obj = new ilDclRecordQueryObject();
81  $sql_obj->setJoinStatement($join_str);
82 
83  return $sql_obj;
84  }
85 
89  public function getValidFieldProperties() {
91  }
92 
96  public function allowFilterInListView() {
97  //A reference-field is not filterable if the referenced field is of datatype MOB or File
98  $ref_field = $this->getFieldRef();
99  return ! ($ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_MOB
100  || $ref_field->getDatatypeId() == ilDclDatatype::INPUTFORMAT_FILE);
101  }
102 
103  public function getFieldRef() {
105  }
106 
107 
108  public function afterClone($records) {
111  $reference_clone = ilDclCache::getCloneOf((int)$clone->getProperty(ilDclBaseFieldModel::PROP_REFERENCE), ilDclCache::TYPE_FIELD);
112  if ($reference_clone) {
113  $this->setProperty(ilDclBaseFieldModel::PROP_REFERENCE, $reference_clone->getId());
114  $this->updateProperties();
115  }
116  parent::afterClone($records);
117  }
118 }
Class ilDclBaseFieldModel.
static getCloneOf($id, $type)
Class ilDclRecordQueryObject.
static getFieldCache($field_id=0)
Class ilDclReferenceFieldModel.
updateProperties()
Update properties of this field in Database.
$records
Definition: simple_test.php:22
setProperty($key, $value)
Set a property for a field (does not save)
getRecordQueryFilterObject($filter_value="", ilDclBaseFieldModel $sort_field=null)
Returns a query-object for building the record-loader-sql-query.
hasProperty($key)
Checks if a certain property for a field is set.
getRecordQuerySortObject($direction="asc", $sort_by_status=false)
Returns a query-object for building the record-loader-sql-query.
Create styles array
The data for the language used.
getProperty($key)
Returns a certain property of a field.
global $ilDB
global $DIC