ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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...
 
- 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 
)
Parameters
ilDclBaseRecordModel$record
ilDclBaseFieldModel$field

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

References ilDclBaseRecordFieldModel\getField(), and ilDclCache\getTableCache().

34  {
35  parent::__construct($record, $field);
36  $dclTable = ilDclCache::getTableCache($this->getField()->getTableId());
37  $this->dcl_obj_id = $dclTable->getObjId();
38  }
static getTableCache($table_id=0)
+ Here is the call graph for this function:

Member Function Documentation

◆ afterClone()

ilDclReferenceRecordFieldModel::afterClone ( )

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

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

172  {
173  $field_clone = ilDclCache::getCloneOf($this->getField()->getId(), ilDclCache::TYPE_FIELD);
174  $record_clone = ilDclCache::getCloneOf($this->getRecord()->getId(), ilDclCache::TYPE_RECORD);
175 
176  if ($field_clone && $record_clone) {
177  $record_field_clone = ilDclCache::getRecordFieldCache($record_clone, $field_clone);
178  $clone_reference = $record_field_clone->getValue();
179  $reference_record = ilDclCache::getCloneOf($clone_reference, ilDclCache::TYPE_RECORD);
180  if ($reference_record) {
181  $this->setValue($reference_record->getId()); // reference fields store the id of the reference's record as their value
182  $this->doUpdate();
183  }
184  }
185  }
static getCloneOf($id, $type)
setValue($value, $omit_parsing=false)
Set value for record field.
doUpdate()
Update object in database.
static getRecordFieldCache($record, $field)
+ Here is the call graph for this function:

◆ getExportValue()

ilDclReferenceRecordFieldModel::getExportValue ( )
Returns
int|string

Definition at line 44 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().

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

◆ getReferenceFromValue()

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

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

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

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

152  {
154  $table = ilDclCache::getTableCache($field->getTableId());
155  $record_id = 0;
156  foreach ($table->getRecords() as $record) {
157  $record_value = $record->getRecordField($field->getId())->getExportValue();
158  // in case of a url-field
159  if (is_array($record_value) && !is_array($value)) {
160  $record_value = array_shift($record_value);
161  }
162  if ($record_value == $value) {
163  $record_id = $record->getId();
164  }
165  }
166 
167  return $record_id;
168  }
static getFieldCache($field_id=0)
static getTableCache($table_id=0)
if(empty($password)) $table
Definition: pwgen.php:24
+ 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[]

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

References $delimiter, $i, and getReferenceFromValue().

Referenced by getValueFromExcel().

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

◆ getValueFromExcel()

ilDclReferenceRecordFieldModel::getValueFromExcel (   $excel,
  $row,
  $col 
)

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

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

82  {
83  global $DIC;
84  $lng = $DIC['lng'];
85  $value = parent::getValueFromExcel($excel, $row, $col);
86  $old = $value;
87  if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
89  $has_value = count($value);
90  } else {
92  $has_value = $value;
93  }
94 
95  if (!$has_value && $old) {
96  $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col + 1) . ") " . $lng->txt("dcl_no_such_reference") . " "
97  . $old;
98 
99  return array('warning' => $warning);
100  }
101 
102  return $value;
103  }
global $DIC
Definition: saml.php:7
getReferencesFromString($stringValues)
This method tries to get as many valid references out of a string separated by commata.
$warning
Definition: X509warning.php:13
$row
+ Here is the call graph for this function:

Field Documentation

◆ $dcl_obj_id

ilDclReferenceRecordFieldModel::$dcl_obj_id
protected

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


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