ILIAS  release_7 Revision v7.30-3-g800a261c036
ilDclReferenceRecordFieldModel Class Reference

Class ilDclBaseFieldModel. More...

+ Inheritance diagram for ilDclReferenceRecordFieldModel:
+ Collaboration diagram for ilDclReferenceRecordFieldModel:

Public Member Functions

 __construct (ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
 
 getExportValue ()
 
 getValueFromExcel ($excel, $row, $col)
 
 getReferenceFromValue ($value)
 
 afterClone ()
 
- Public Member Functions inherited from ilDclBaseRecordFieldModel
 __construct (ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
 
 doCreate ()
 Creates an Id and a database entry. More...
 
 doUpdate ()
 Update object in database. More...
 
 delete ()
 Delete record field in database. More...
 
 getValue ()
 
 getValueForRepresentation ()
 
 serializeData ($value)
 Serialize data before storing to db. More...
 
 deserializeData ($value)
 Deserialize data before applying to field. More...
 
 setValue ($value, $omit_parsing=false)
 Set value for record field. More...
 
 setValueFromForm ($form)
 
 getFormulaValue ()
 
 parseExportValue ($value)
 Function to parse incoming data from form input value $value. More...
 
 getValueFromExcel ($excel, $row, $col)
 
 parseValue ($value)
 Function to parse incoming data from form input value $value. More...
 
 getExportValue ()
 
 fillExcelExport (ilExcel $worksheet, &$row, &$col)
 
 getPlainText ()
 
 getSortingValue ($link=true)
 
 addHiddenItemsToConfirmation (ilConfirmationGUI &$confirmation)
 
 parseSortingValue ($value, $link=true)
 Returns sortable value for the specific field-types. More...
 
 cloneStructure (ilDclBaseRecordFieldModel $old_record_field)
 
 afterClone ()
 
 getField ()
 
 getId ()
 
 getRecord ()
 
 getRecordRepresentation ()
 
 setRecordRepresentation ($record_representation)
 
 getFieldRepresentation ()
 
 setFieldRepresentation ($field_representation)
 

Protected Member Functions

 getReferencesFromString ($stringValues)
 This method tries to get as many valid references out of a string separated by commata. More...
 
 getCloneRecordId (string $clone_reference)
 
- Protected Member Functions inherited from ilDclBaseRecordFieldModel
 doRead ()
 Read object data from database. More...
 
 loadValue ()
 Load the value. More...
 

Protected Attributes

 $dcl_obj_id
 
- Protected Attributes inherited from ilDclBaseRecordFieldModel
 $id
 
 $field
 
 $record
 
 $record_representation
 
 $field_representation
 
 $value
 
 $user
 
 $ctrl
 
 $db
 
 $lng
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilDclReferenceRecordFieldModel::__construct ( ilDclBaseRecordModel  $record,
ilDclBaseFieldModel  $field 
)

Member Function Documentation

◆ afterClone()

ilDclReferenceRecordFieldModel::afterClone ( )

Reimplemented from ilDclBaseRecordFieldModel.

Definition at line 167 of file class.ilDclReferenceRecordFieldModel.php.

168 {
169 $field_clone = ilDclCache::getCloneOf($this->getField()->getId(), ilDclCache::TYPE_FIELD);
171
172 if ($field_clone && $record_clone) {
173 $record_field_clone = ilDclCache::getRecordFieldCache($record_clone, $field_clone);
174 $clone_references = $record_field_clone->getValue();
175
176 if (is_array($clone_references)) {
177 $value = [];
178 foreach ($clone_references as $clone_reference) {
179 if (!is_null($temp_value = $this->getCloneRecordId($clone_reference))) {
180 $value[] = $temp_value;
181 }
182 }
183 } elseif (!is_null($temp_value = $this->getCloneRecordId($clone_references))) {
184 $value = $temp_value;
185 }
186
187 $this->setValue($value, true); // reference fields store the id of the reference's record as their value
188 $this->doUpdate();
189 }
190 }
setValue($value, $omit_parsing=false)
Set value for record field.
static getRecordFieldCache($record, $field)
static getCloneOf($id, $type)

References ilDclBaseRecordFieldModel\$value, ilDclBaseRecordFieldModel\doUpdate(), ilDclCache\getCloneOf(), getCloneRecordId(), ilDclBaseRecordFieldModel\getField(), ilDclBaseRecordFieldModel\getId(), ilDclBaseRecordFieldModel\getRecord(), ilDclCache\getRecordFieldCache(), ilDclBaseRecordFieldModel\setValue(), ilDclCache\TYPE_FIELD, and ilDclCache\TYPE_RECORD.

+ Here is the call graph for this function:

◆ getCloneRecordId()

ilDclReferenceRecordFieldModel::getCloneRecordId ( string  $clone_reference)
protected

Definition at line 192 of file class.ilDclReferenceRecordFieldModel.php.

192 : ?string
193 {
194 $reference_record = ilDclCache::getCloneOf($clone_reference, ilDclCache::TYPE_RECORD);
195 if ($reference_record) {
196 return (string) $reference_record->getId();
197 }
198 return null;
199 }

References ilDclCache\getCloneOf(), and ilDclCache\TYPE_RECORD.

Referenced by afterClone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExportValue()

ilDclReferenceRecordFieldModel::getExportValue ( )
Returns
int|string

Reimplemented from ilDclBaseRecordFieldModel.

Reimplemented in ilDclNReferenceRecordFieldModel.

Definition at line 40 of file class.ilDclReferenceRecordFieldModel.php.

41 {
42 $value = $this->getValue();
43 if ($value) {
44 if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
45 if (!is_array($value)) {
46 $value = array($value);
47 }
48 foreach ($value as $val) {
49 if ($val) {
50 $ref_rec = ilDclCache::getRecordCache($val);
51 $ref_record_field = $ref_rec->getRecordField($this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
52 if ($ref_record_field) {
53 $exp_value = $ref_record_field->getExportValue();
54 $names[] = is_array($exp_value) ? array_shift($exp_value) : $exp_value;
55 }
56 }
57 }
58
59 return implode('; ', $names);
60 } else {
61 $ref_rec = ilDclCache::getRecordCache($this->getValue());
62 $ref_record_field = $ref_rec->getRecordField($this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
63
64 $exp_value = "";
65 if ($ref_record_field) {
66 $exp_value = $ref_record_field->getExportValue();
67 }
68
69 return (is_array($exp_value) ? array_shift($exp_value) : $exp_value);
70 }
71 } else {
72 return "";
73 }
74 }
static getRecordCache($record_id=0)

References ilDclBaseRecordFieldModel\$value, ilDclBaseRecordFieldModel\getField(), ilDclCache\getRecordCache(), ilDclBaseRecordFieldModel\getValue(), ilDclBaseFieldModel\PROP_N_REFERENCE, and ilDclBaseFieldModel\PROP_REFERENCE.

+ Here is the call graph for this function:

◆ getReferenceFromValue()

ilDclReferenceRecordFieldModel::getReferenceFromValue (   $value)
Parameters
$fieldilDclBaseFieldModel
$value
Returns
int

Definition at line 147 of file class.ilDclReferenceRecordFieldModel.php.

148 {
150 $table = ilDclCache::getTableCache($field->getTableId());
151 $record_id = 0;
152 foreach ($table->getRecords() as $record) {
153 $record_value = $record->getRecordField($field->getId())->getExportValue();
154 // in case of a url-field
155 if (is_array($record_value) && !is_array($value)) {
156 $record_value = array_shift($record_value);
157 }
158 if ($record_value == $value) {
159 $record_id = $record->getId();
160 }
161 }
162
163 return $record_id;
164 }
static getFieldCache($field_id=0)

References ilDclBaseRecordFieldModel\$field, ilDclBaseRecordFieldModel\$record, ilDclBaseRecordFieldModel\$value, ilDclBaseRecordFieldModel\getField(), ilDclCache\getFieldCache(), ilDclCache\getTableCache(), and ilDclBaseFieldModel\PROP_REFERENCE.

Referenced by ilDclNReferenceRecordFieldModel\getReferencesFromString(), getReferencesFromString(), and getValueFromExcel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getReferencesFromString()

ilDclReferenceRecordFieldModel::getReferencesFromString (   $stringValues)
protected

This method tries to get as many valid references out of a string separated by commata.

This is problematic as a string value could contain commata itself. It is optimized to work with an exported list from this DataCollection. And works fine in most cases. Only areference list with the values "hello" and "hello, world" Will mess with it.

Parameters
$stringValuesstring
Returns
int[]

Reimplemented in ilDclNReferenceRecordFieldModel.

Definition at line 111 of file class.ilDclReferenceRecordFieldModel.php.

112 {
113 $delimiter = strpos($stringValues, '; ') ? '; ' : ', ';
114 $slicedStrings = explode($delimiter, $stringValues);
115 $slicedReferences = array();
116 $resolved = 0;
117 for ($i = 0; $i < count($slicedStrings); $i++) {
118 //try to find a reference since the last resolved value separated by a comma.
119 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
120 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
121 if ($ref = $this->getReferenceFromValue($searchString)) {
122 $slicedReferences[] = $ref;
123 $resolved = $i;
124 continue;
125 }
126
127 //try to find a reference with the current index.
128 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
129 $searchString = $slicedStrings[$i];
130 if ($ref = $this->getReferenceFromValue($searchString)) {
131 $slicedReferences[] = $ref;
132 $resolved = $i;
133 continue;
134 }
135 }
136
137 return $slicedReferences;
138 }
$i
Definition: metadata.php:24

References $i, and getReferenceFromValue().

Referenced by getValueFromExcel().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getValueFromExcel()

ilDclReferenceRecordFieldModel::getValueFromExcel (   $excel,
  $row,
  $col 
)
Parameters
$excel
$row
$col
Returns
array|string

Reimplemented from ilDclBaseRecordFieldModel.

Reimplemented in ilDclNReferenceRecordFieldModel.

Definition at line 77 of file class.ilDclReferenceRecordFieldModel.php.

78 {
79 global $DIC;
80 $lng = $DIC['lng'];
81 $value = parent::getValueFromExcel($excel, $row, $col);
82 $old = $value;
83 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
85 $has_value = count($value);
86 } else {
88 $has_value = $value;
89 }
90
91 if (!$has_value && $old) {
92 $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col + 1) . ") " . $lng->txt("dcl_no_such_reference") . " "
93 . $old;
94
95 return array('warning' => $warning);
96 }
97
98 return $value;
99 }
getReferencesFromString($stringValues)
This method tries to get as many valid references out of a string separated by commata.
global $DIC
Definition: goto.php:24

References $DIC, ilDclBaseRecordFieldModel\$lng, ilDclBaseRecordFieldModel\$value, ilDataCollectionImporter\getExcelCharForInteger(), ilDclBaseRecordFieldModel\getField(), getReferenceFromValue(), getReferencesFromString(), and ilDclBaseFieldModel\PROP_N_REFERENCE.

+ Here is the call graph for this function:

Field Documentation

◆ $dcl_obj_id

ilDclReferenceRecordFieldModel::$dcl_obj_id
protected

Definition at line 22 of file class.ilDclReferenceRecordFieldModel.php.


The documentation for this class was generated from the following file: