ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilDclReferenceRecordFieldModel Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct (ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
 
 getExportValue ()
 
 getValueFromExcel (ilExcel $excel, int $row, int $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, bool $omit_parsing=false)
 Set value for record field. More...
 
 setValueFromForm (ilPropertyFormGUI $form)
 
 getFormulaValue ()
 
 parseExportValue ($value)
 Function to parse incoming data from form input value $value. More...
 
 getValueFromExcel (ilExcel $excel, int $row, int $col)
 
 parseValue ($value)
 Function to parse incoming data from form input value $value. More...
 
 getExportValue ()
 
 fillExcelExport (ilExcel $worksheet, int &$row, int &$col)
 
 getPlainText ()
 
 getSortingValue (bool $link=true)
 
 addHiddenItemsToConfirmation (ilConfirmationGUI $confirmation)
 
 parseSortingValue ($value, bool $link=true)
 Returns sortable value for the specific field-types. More...
 
 cloneStructure (ilDclBaseRecordFieldModel $old_record_field)
 
 afterClone ()
 
 getField ()
 
 getId ()
 
 getRecord ()
 
 getRecordRepresentation ()
 
 setRecordRepresentation (ilDclBaseRecordRepresentation $record_representation)
 
 getFieldRepresentation ()
 
 setFieldRepresentation (ilDclBaseFieldRepresentation $field_representation)
 

Protected Member Functions

 getReferencesFromString (string $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

int $dcl_obj_id
 
- Protected Attributes inherited from ilDclBaseRecordFieldModel
int $id = null
 
ilDclBaseFieldModel $field
 
ilDclBaseRecordModel $record
 
ilDclBaseRecordRepresentation $record_representation = null
 
ilDclBaseFieldRepresentation $field_representation = null
 
 $value
 
ilObjUser $user
 
ilCtrl $ctrl
 
ilDBInterface $db
 
ilLanguage $lng
 
ILIAS HTTP Services $http
 
ILIAS Refinery Factory $refinery
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Constructor & Destructor Documentation

◆ __construct()

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

Reimplemented from ilDclBaseRecordFieldModel.

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

28 {
30 $dclTable = ilDclCache::getTableCache($this->getField()->getTableId());
31 $this->dcl_obj_id = $dclTable->getObjId();
32 }
static getTableCache(int $table_id=null)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ilDclBaseRecordFieldModel\$field, ilDclBaseRecordFieldModel\$record, ILIAS\GlobalScreen\Provider\__construct(), ilDclBaseRecordFieldModel\getField(), and ilDclCache\getTableCache().

+ Here is the call graph for this function:

Member Function Documentation

◆ afterClone()

ilDclReferenceRecordFieldModel::afterClone ( )

Reimplemented from ilDclBaseRecordFieldModel.

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

142 : void
143 {
144 $field_clone = ilDclCache::getCloneOf($this->getField()->getId(), ilDclCache::TYPE_FIELD);
146
147 if ($field_clone && $record_clone) {
148 $record_field_clone = ilDclCache::getRecordFieldCache($record_clone, $field_clone);
149 $clone_references = $record_field_clone->getValue();
150
151 $value = [];
152 if (is_array($clone_references)) {
153 foreach ($clone_references as $clone_reference) {
154 if (!is_null($temp_value = $this->getCloneRecordId($clone_reference))) {
155 $value[] = $temp_value;
156 }
157 }
158 } elseif (!is_null($temp_value = $this->getCloneRecordId($clone_references))) {
159 $value = $temp_value;
160 }
161
162 $this->setValue($value, true); // reference fields store the id of the reference's record as their value
163 $this->doUpdate();
164 }
165 }
setValue($value, bool $omit_parsing=false)
Set value for record field.
doUpdate()
Update object in database.
static getRecordFieldCache(object $record, object $field)
static getCloneOf(int $id, string $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 167 of file class.ilDclReferenceRecordFieldModel.php.

167 : ?string
168 {
169 $reference_record = ilDclCache::getCloneOf((int) $clone_reference, ilDclCache::TYPE_RECORD);
170 if ($reference_record) {
171 return (string) $reference_record->getId();
172 }
173 return null;
174 }

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.

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

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

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)

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

123 : int
124 {
127 $record_id = 0;
128 foreach ($table->getRecords() as $record) {
129 $record_value = $record->getRecordField($field->getId())->getExportValue();
130 // in case of a url-field
131 if (is_array($record_value) && !is_array($value)) {
132 $record_value = array_shift($record_value);
133 }
134 if ($record_value == $value) {
135 $record_id = $record->getId();
136 }
137 }
138
139 return $record_id;
140 }
static getFieldCache(int $field_id=0)

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

Referenced by getReferencesFromString(), and getValueFromExcel().

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

◆ getReferencesFromString()

ilDclReferenceRecordFieldModel::getReferencesFromString ( string  $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.

Returns
int[]

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

95 : array
96 {
97 $delimiter = strpos($stringValues, '; ') ? '; ' : ', ';
98 $slicedStrings = explode($delimiter, $stringValues);
99 $slicedReferences = [];
100 $resolved = 0;
101 for ($i = 0; $i < count($slicedStrings); $i++) {
102 //try to find a reference since the last resolved value separated by a comma.
103 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
104 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
105 if ($ref = $this->getReferenceFromValue($searchString)) {
106 $slicedReferences[] = $ref;
107 $resolved = $i;
108 continue;
109 }
110
111 //try to find a reference with the current index.
112 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
113 $searchString = $slicedStrings[$i];
114 if ($ref = $this->getReferenceFromValue($searchString)) {
115 $slicedReferences[] = $ref;
116 $resolved = $i;
117 }
118 }
119
120 return $slicedReferences;
121 }
$i
Definition: metadata.php:41

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 ( ilExcel  $excel,
int  $row,
int  $col 
)
Returns
int|string

Reimplemented from ilDclBaseRecordFieldModel.

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

68 {
69 $value = parent::getValueFromExcel($excel, $row, $col);
70 $old = $value;
71 if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
73 $has_value = count($value);
74 } else {
76 $has_value = $value;
77 }
78
79 if (!$has_value && $old) {
80 $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col + 1) . ") " . $this->lng->txt("dcl_no_such_reference") . " "
81 . $old;
82
83 return ['warning' => $warning];
84 }
85
86 return $value;
87 }
getReferencesFromString(string $stringValues)
This method tries to get as many valid references out of a string separated by commata.

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

+ Here is the call graph for this function:

Field Documentation

◆ $dcl_obj_id

int ilDclReferenceRecordFieldModel::$dcl_obj_id
protected

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


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