ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilDclReferenceRecordFieldModel Class Reference
+ 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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

30  {
31  parent::__construct($record, $field);
32  $dclTable = ilDclCache::getTableCache($this->getField()->getTableId());
33  $this->dcl_obj_id = $dclTable->getObjId();
34  }
static getTableCache(?int $table_id=null)
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ afterClone()

ilDclReferenceRecordFieldModel::afterClone ( )

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

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.

141  : void
142  {
143  $field_clone = ilDclCache::getCloneOf((int) $this->getField()->getId(), ilDclCache::TYPE_FIELD);
144  $record_clone = ilDclCache::getCloneOf($this->getRecord()->getId(), ilDclCache::TYPE_RECORD);
145 
146  if ($field_clone && $record_clone) {
147  $record_field_clone = ilDclCache::getRecordFieldCache($record_clone, $field_clone);
148  $clone_references = $record_field_clone->getValue();
149  $value = [];
150  if (is_array($clone_references)) {
151 
152  foreach ($clone_references as $clone_reference) {
153  if (!is_null($temp_value = $this->getCloneRecordId($clone_reference))) {
154  $value[] = $temp_value;
155  }
156  }
157  } elseif (!is_null($temp_value = $this->getCloneRecordId($clone_references))) {
158  $value = $temp_value;
159  }
160 
161  $this->setValue($value, true); // reference fields store the id of the reference's record as their value
162  $this->doUpdate();
163  }
164  }
setValue($value, bool $omit_parsing=false)
Set value for record field.
doUpdate()
Update object in database.
static getCloneOf(int $id, string $type)
static getRecordFieldCache(object $record, object $field)
+ Here is the call graph for this function:

◆ getCloneRecordId()

ilDclReferenceRecordFieldModel::getCloneRecordId ( ?string  $clone_reference)
protected

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

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

Referenced by afterClone().

166  : ?string
167  {
168  $reference_record = ilDclCache::getCloneOf((int) $clone_reference, ilDclCache::TYPE_RECORD);
169  if ($reference_record) {
170  return (string) $reference_record->getId();
171  }
172  return null;
173  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getCloneOf(int $id, string $type)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExportValue()

ilDclReferenceRecordFieldModel::getExportValue ( )

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

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

Referenced by getReferenceFromValue().

36  : string
37  {
38  $value = $this->getValue();
39  if ($value) {
40  if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
41  $names = [];
42  if (!is_array($value)) {
43  $value = [$value];
44  }
45  foreach ($value as $val) {
46  if ($val) {
47  $ref_rec = ilDclCache::getRecordCache((int) $val);
48  $ref_record_field = $ref_rec->getRecordField((int) $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  }
56 
57  $ref_rec = ilDclCache::getRecordCache((int) $this->getValue());
58  $ref_record_field = $ref_rec->getRecordField((int) $this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
59  $exp_value = $ref_record_field->getExportValue();
60 
61  return (string) (is_array($exp_value) ? array_shift($exp_value) : $exp_value);
62  }
63  return "";
64  }
static getRecordCache(?int $record_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getReferenceFromValue()

ilDclReferenceRecordFieldModel::getReferenceFromValue (   $value)

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

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

Referenced by getReferencesFromString(), and getValueFromExcel().

122  : int
123  {
126  $record_id = 0;
127  foreach ($table->getRecords() as $record) {
128  $record_value = $record->getRecordField((int) $field->getId())->getExportValue();
129  // in case of a url-field
130  if (is_array($record_value) && !is_array($value)) {
131  $record_value = array_shift($record_value);
132  }
133  if ($record_value == $value) {
134  $record_id = $record->getId();
135  }
136  }
137 
138  return $record_id;
139  }
static getFieldCache(int $field_id=0)
static getTableCache(?int $table_id=null)
+ 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 94 of file class.ilDclReferenceRecordFieldModel.php.

References getReferenceFromValue().

Referenced by getValueFromExcel().

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

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

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

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

Field Documentation

◆ $dcl_obj_id

int ilDclReferenceRecordFieldModel::$dcl_obj_id
protected

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


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