ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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)
 
 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().

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

Member Function Documentation

◆ afterClone()

ilDclReferenceRecordFieldModel::afterClone ( )

Definition at line 157 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.

157  {
158  $field_clone = ilDclCache::getCloneOf($this->getField()->getId(), ilDclCache::TYPE_FIELD);
159  $record_clone = ilDclCache::getCloneOf($this->getRecord()->getId(), ilDclCache::TYPE_RECORD);
160 
161  if ($field_clone && $record_clone) {
162  $record_field_clone = ilDclCache::getRecordFieldCache($record_clone, $field_clone);
163  $clone_reference = $record_field_clone->getValue();
164  $reference_record = ilDclCache::getCloneOf($clone_reference, ilDclCache::TYPE_RECORD);
165  if ($reference_record) {
166  $this->setValue($reference_record->getId()); // reference fields store the id of the reference's record as their value
167  $this->doUpdate();
168  }
169  }
170  }
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 42 of file class.ilDclReferenceRecordFieldModel.php.

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

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

◆ getReferenceFromValue()

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

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

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

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

138  {
140  $table = ilDclCache::getTableCache($field->getTableId());
141  $record_id = 0;
142  foreach ($table->getRecords() as $record) {
143  $record_value = $record->getRecordField($field->getId())->getValue();
144  // in case of a url-field
145  if (is_array($record_value) && !is_array($value)) {
146  $record_value = array_shift($record_value);
147  }
148  if ($record_value == $value) {
149  $record_id = $record->getId();
150  }
151  }
152 
153  return $record_id;
154  }
static getFieldCache($field_id=0)
static getTableCache($table_id=0)
+ 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 106 of file class.ilDclReferenceRecordFieldModel.php.

References array, and getReferenceFromValue().

Referenced by getValueFromExcel().

106  {
107  $slicedStrings = explode(", ", $stringValues);
108  $slicedReferences = array();
109  $resolved = 0;
110  for($i = 0; $i < count($slicedStrings); $i++) {
111  //try to find a reference since the last resolved value separated by a comma.
112  // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
113  $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
114  if($ref = $this->getReferenceFromValue($searchString)){
115  $slicedReferences[] = $ref;
116  $resolved = $i;
117  continue;
118  }
119 
120  //try to find a reference with the current index.
121  // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
122  $searchString = $slicedStrings[$i];
123  if($ref = $this->getReferenceFromValue($searchString)){
124  $slicedReferences[] = $ref;
125  $resolved = $i;
126  continue;
127  }
128  }
129  return $slicedReferences;
130  }
Create styles array
The data for the language used.
+ 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 77 of file class.ilDclReferenceRecordFieldModel.php.

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

77  {
78  global $DIC;
79  $lng = $DIC['lng'];
80  $value = parent::getValueFromExcel($excel, $row, $col);
81  $old = $value;
82  if ($this->getField()->hasProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
84  $has_value = count($value);
85  } else {
87  $has_value = $value;
88  }
89 
90  if (!$has_value && $old) {
91  $warning = "(" . $row . ", " . ilDataCollectionImporter::getExcelCharForInteger($col+1) . ") " . $lng->txt("dcl_no_such_reference") . " "
92  . $old;
93  return array('warning' => $warning);
94  }
95 
96  return $value;
97  }
getReferencesFromString($stringValues)
This method tries to get as many valid references out of a string separated by commata.
$old
Create styles array
The data for the language used.
global $DIC
+ Here is the call graph for this function:

Field Documentation

◆ $dcl_obj_id

ilDclReferenceRecordFieldModel::$dcl_obj_id
protected

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


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