ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 32 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 161 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.

162  {
163  $field_clone = ilDclCache::getCloneOf($this->getField()->getId(), ilDclCache::TYPE_FIELD);
164  $record_clone = ilDclCache::getCloneOf($this->getRecord()->getId(), ilDclCache::TYPE_RECORD);
165 
166  if ($field_clone && $record_clone) {
167  $record_field_clone = ilDclCache::getRecordFieldCache($record_clone, $field_clone);
168  $clone_reference = $record_field_clone->getValue();
169  $reference_record = ilDclCache::getCloneOf($clone_reference, ilDclCache::TYPE_RECORD);
170  if ($reference_record) {
171  $this->setValue($reference_record->getId()); // reference fields store the id of the reference's record as their value
172  $this->doUpdate();
173  }
174  }
175  }
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.

Referenced by getReferenceFromValue().

43  {
44  $value = $this->getValue();
45  if ($value) {
46  if ($this->getField()->getProperty(ilDclBaseFieldModel::PROP_N_REFERENCE)) {
47  if (!is_array($value)) {
48  $value = array($value);
49  }
50  foreach ($value as $val) {
51  if ($val) {
52  $ref_rec = ilDclCache::getRecordCache($val);
53  $ref_record_field = $ref_rec->getRecordField($this->getField()->getProperty(ilDclBaseFieldModel::PROP_REFERENCE));
54  if ($ref_record_field) {
55  $exp_value = $ref_record_field->getExportValue();
56  $names[] = is_array($exp_value) ? array_shift($exp_value) : $exp_value;
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:
+ Here is the caller graph for this function:

◆ getReferenceFromValue()

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

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

142  {
144  $table = ilDclCache::getTableCache($field->getTableId());
145  $record_id = 0;
146  foreach ($table->getRecords() as $record) {
147  $record_value = $record->getRecordField($field->getId())->getExportValue();
148  // in case of a url-field
149  if (is_array($record_value) && !is_array($value)) {
150  $record_value = array_shift($record_value);
151  }
152  if ($record_value == $value) {
153  $record_id = $record->getId();
154  }
155  }
156 
157  return $record_id;
158  }
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 107 of file class.ilDclReferenceRecordFieldModel.php.

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

Referenced by getValueFromExcel().

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

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

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  return array('warning' => $warning);
95  }
96 
97  return $value;
98  }
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
$old
Create styles array
The data for the language used.
+ 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: