ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilDataCollectionNReferenceField Class Reference

Class ilDataCollectionNReferenceField. More...

+ Inheritance diagram for ilDataCollectionNReferenceField:
+ Collaboration diagram for ilDataCollectionNReferenceField:

Public Member Functions

 getMaxReferenceLength ()
 
 setMaxReferenceLength ($max_reference_length)
 
 doUpdate ()
 Update object in database. More...
 
 getValue ()
 
 getSingleHTML ($options=NULL)
 @description this funciton is used to in the viewdefinition of a single record. More...
 
 getLinkHTML ($link, $value)
 
 getHTML ()
 
 getValueFromExcel ($excel, $row, $col)
 
 getExportValue ()
 
- Public Member Functions inherited from ilDataCollectionReferenceField
 __construct (ilDataCollectionRecord $record, ilDataCollectionField $field)
 
 getExportValue ()
 
 getValueFromExcel ($excel, $row, $col)
 
 getReferenceFromValue ($value)
 
- Public Member Functions inherited from ilDataCollectionRecordField
 __construct (ilDataCollectionRecord $record, ilDataCollectionField $field)
 
 doUpdate ()
 Update object in database. More...
 
 delete ()
 Delete record field in database. More...
 
 getValue ()
 
 setValue ($value, $omit_parsing=false)
 Set value for record field. More...
 
 setValueFromForm (&$form)
 
 getValueFromExcel ($excel, $row, $col)
 
 fillFormInput (&$form)
 
 getExportValue ()
 
 fillExcelExport ($worksheet, &$row, &$col)
 
 getPlainText ()
 
 getHTML ($link=true)
 
 getSortingValue ($link=true)
 
 getSingleHTML ()
 
 getField ()
 
 getId ()
 
 getRecord ()
 

Protected Member Functions

 loadValueSorted ()
 
 loadValue ()
 Load the value. More...
 
 getReferencesFromString ($stringValues)
 This method tries to get as many valid references out of a string separated by commata. More...
 
 getLinkHTML ($link_name=NULL, $value)
 
- Protected Member Functions inherited from ilDataCollectionRecordField
 doRead ()
 Read object data from database. More...
 
 doCreate ()
 Creates an Id and a database entry. More...
 
 getFormInput ()
 
 loadValue ()
 Load the value. More...
 

Protected Attributes

 $max_reference_length = 20
 
- Protected Attributes inherited from ilDataCollectionReferenceField
 $dcl_obj_id
 
 $properties = array()
 
- Protected Attributes inherited from ilDataCollectionRecordField
 $id
 
 $field
 
 $record
 
 $value
 
 $user
 
 $ctrl
 
 $db
 
 $lng
 

Detailed Description

Member Function Documentation

◆ doUpdate()

ilDataCollectionNReferenceField::doUpdate ( )

Update object in database.

Reimplemented from ilDataCollectionRecordField.

Definition at line 35 of file class.ilDataCollectionNReferenceField.php.

35 {
36 global $ilDB;
37
38 $values = $this->getValue();
39 if (!is_array($values)) {
40 $values = array( $values );
41 }
42 $datatype = $this->field->getDatatype();
43
44 $query = "DELETE FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
45 . $ilDB->quote($this->id, "integer");
46 $ilDB->manipulate($query);
47
48 if (!count($values) || $values[0] == 0) {
49 return;
50 }
51
52 $query = "INSERT INTO il_dcl_stloc" . $datatype->getStorageLocation() . "_value (value, record_field_id, id) VALUES";
53 foreach ($values as $value) {
54 $next_id = $ilDB->nextId("il_dcl_stloc" . $datatype->getStorageLocation() . "_value");
55 $query .= " (" . $ilDB->quote($value, $datatype->getDbType()) . ", " . $ilDB->quote($this->getId(), "integer") . ", "
56 . $ilDB->quote($next_id, "integer") . "),";
57 }
58 $query = substr($query, 0, - 1);
59 $ilDB->manipulate($query);
60 }
global $ilDB

References $ilDB, $query, ilDataCollectionRecordField\$value, ilDataCollectionRecordField\getId(), and getValue().

Referenced by ilDataCollectionNReferenceFieldGUI\buildTemplate().

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

◆ getExportValue()

ilDataCollectionNReferenceField::getExportValue ( )
Returns
int|string

Reimplemented from ilDataCollectionReferenceField.

Definition at line 201 of file class.ilDataCollectionNReferenceField.php.

201 {
202 $values = $this->getValue();
203 $names = array();
204 foreach ($values as $value) {
205 if ($value) {
207 $names[] = $ref_rec->getRecordField($this->getField()->getFieldRef())->getValue();
208 }
209 }
210 $string = "";
211 foreach ($names as $name) {
212 $string .= $name . ", ";
213 }
214 if (!count($names)) {
215 return "";
216 }
217 $string = substr($string, 0, - 2);
218
219 return $string;
220 }
static getRecordCache($record_id=0)

References ilDataCollectionRecordField\$value, ilDataCollectionRecordField\getField(), ilDataCollectionCache\getRecordCache(), and getValue().

+ Here is the call graph for this function:

◆ getHTML()

ilDataCollectionNReferenceField::getHTML ( )
Returns
array|mixed|string

Definition at line 179 of file class.ilDataCollectionNReferenceField.php.

179 {
180 $ilDataCollectionNReferenceFieldGUI = new ilDataCollectionNReferenceFieldGUI($this);
181 return $ilDataCollectionNReferenceFieldGUI->getHTML();
182 }

◆ getLinkHTML()

ilDataCollectionNReferenceField::getLinkHTML (   $link,
  $value 
)
Parameters
null$link
$value
Returns
string

Reimplemented from ilDataCollectionReferenceField.

Definition at line 167 of file class.ilDataCollectionNReferenceField.php.

167 {
168 if ($link == "[" . $this->getField()->getTitle() . "]") {
169 $link = NULL;
170 }
171
172 return parent::getLinkHTML($link, $value);
173 }

References ilDataCollectionRecordField\$value, and ilDataCollectionRecordField\getField().

Referenced by ilDataCollectionNReferenceFieldGUI\buildTemplate().

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

◆ getMaxReferenceLength()

ilDataCollectionNReferenceField::getMaxReferenceLength ( )

◆ getReferencesFromString()

ilDataCollectionNReferenceField::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 229 of file class.ilDataCollectionNReferenceField.php.

229 {
230 $slicedStrings = explode(", ", $stringValues);
231 $slicedReferences = array();
232 $resolved = 0;
233 for($i = 0; $i < count($slicedStrings); $i++) {
234 //try to find a reference since the last resolved value separated by a comma.
235 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "hello, world".
236 $searchString = implode(array_slice($slicedStrings, $resolved, $i - $resolved + 1));
237 if($ref = $this->getReferenceFromValue($searchString)){
238 $slicedReferences[] = $ref;
239 $resolved = $i;
240 continue;
241 }
242
243 //try to find a reference with the current index.
244 // $i = 1; $resolved = 0; $string = "hello, world, gaga" -> try to match "world".
245 $searchString = $slicedStrings[$i];
246 if($ref = $this->getReferenceFromValue($searchString)){
247 $slicedReferences[] = $ref;
248 $resolved = $i;
249 continue;
250 }
251 }
252 return $slicedReferences;
253 }

References ilDataCollectionReferenceField\getReferenceFromValue().

Referenced by getValueFromExcel().

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

◆ getSingleHTML()

ilDataCollectionNReferenceField::getSingleHTML (   $options = NULL)

@description this funciton is used to in the viewdefinition of a single record.

Returns
mixed

Definition at line 154 of file class.ilDataCollectionNReferenceField.php.

154 {
155 $ilDataCollectionNReferenceFieldGUI = new ilDataCollectionNReferenceFieldGUI($this);
156 return $ilDataCollectionNReferenceFieldGUI->getSingleHTML($options);
157 }
if(!is_array($argv)) $options

References $options.

◆ getValue()

ilDataCollectionNReferenceField::getValue ( )
Returns
string

Reimplemented from ilDataCollectionRecordField.

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

66 {
67 $this->loadValue();
68
69 return $this->value;
70 }

References ilDataCollectionRecordField\$value, and loadValue().

Referenced by doUpdate(), and getExportValue().

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

◆ getValueFromExcel()

ilDataCollectionNReferenceField::getValueFromExcel (   $excel,
  $row,
  $col 
)
Parameters
$excel
$row
$col
Returns
array|string

Reimplemented from ilDataCollectionReferenceField.

Definition at line 184 of file class.ilDataCollectionNReferenceField.php.

184 {
185 global $lng;
186 $stringValue = $excel->val($row, $col);
187 $this->getReferencesFromString($stringValue);
188 $referenceIds = $this->getReferencesFromString($stringValue);
189 if (!count($referenceIds)) {
190 $warning = "(" . $col . ", " . ilDataCollectionImporter::getExcelCharForInteger($col) . ") " . $lng->txt("dcl_no_such_reference") . " "
191 . $stringValue;
192 return array('warning' => $warning);
193 }
194
195 return $referenceIds;
196 }
getReferencesFromString($stringValues)
This method tries to get as many valid references out of a string separated by commata.

References ilDataCollectionRecordField\$lng, $row, ilDataCollectionImporter\getExcelCharForInteger(), and getReferencesFromString().

+ Here is the call graph for this function:

◆ loadValue()

ilDataCollectionNReferenceField::loadValue ( )
protected

Load the value.

Reimplemented from ilDataCollectionRecordField.

Definition at line 134 of file class.ilDataCollectionNReferenceField.php.

134 {
135 if ($this->value === NULL) {
136 global $ilDB;
137 $datatype = $this->field->getDatatype();
138 $query = "SELECT * FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value WHERE record_field_id = "
139 . $ilDB->quote($this->id, "integer");
140 $set = $ilDB->query($query);
141 $this->value = array();
142 while ($rec = $ilDB->fetchAssoc($set)) {
143 $this->value[] = $rec['value'];
144 }
145 }
146 }

References $ilDB, and $query.

Referenced by getValue().

+ Here is the caller graph for this function:

◆ loadValueSorted()

ilDataCollectionNReferenceField::loadValueSorted ( )
protected

Definition at line 73 of file class.ilDataCollectionNReferenceField.php.

73 {
74 if ($this->value === NULL) {
75
76 global $ilDB;
77 $datatype = $this->field->getDatatype();
78 $refField = ilDataCollectionCache::getFieldCache($this->getField()->getFieldRef());
79
80 $supported_internal_types = array(
84 );
85
86 $supported_types = array_merge(array(
90 ), $supported_internal_types);
91 $datatypeId = $refField->getDatatypeId();
92 if (in_array($datatypeId, $supported_types)) {
93 if (in_array($datatypeId, $supported_internal_types)) {
94 $query = "SELECT stlocOrig.value AS value, ilias_object.title AS value_ref ";
95 } else {
96 $query = "SELECT stlocOrig.value AS value, stlocRef.value AS value_ref ";
97 }
98 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
99
100 $query .= " INNER JOIN il_dcl_record_field AS refField ON stlocOrig.value = refField.record_id AND refField.field_id = "
101 . $ilDB->quote($refField->getId(), "integer");
102 $query .= " INNER JOIN il_dcl_stloc" . $refField->getStorageLocation()
103 . "_value AS stlocRef ON stlocRef.record_field_id = refField.id ";
104 } else {
105 $query = "SELECT stlocOrig.value AS value ";
106 $query .= "FROM il_dcl_stloc" . $datatype->getStorageLocation() . "_value AS stlocOrig ";
107 }
108
109 switch ($datatypeId) {
111 $query .= " INNER JOIN object_reference AS ilias_ref ON ilias_ref.ref_id = stlocRef.value ";
112 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = ilias_ref.obj_id ";
113 break;
116 $query .= " INNER JOIN object_data AS ilias_object ON ilias_object.obj_id = stlocRef.value ";
117 break;
118 }
119 $query .= " WHERE stlocOrig.record_field_id = " . $ilDB->quote($this->id, "integer");
120 if (in_array($datatypeId, $supported_types)) {
121 $query .= " ORDER BY value_ref ASC";
122 }
123
124 $set = $ilDB->query($query);
125
126 $this->value = array();
127 while ($rec = $ilDB->fetchAssoc($set)) {
128 $this->value[] = $rec['value'];
129 }
130 }
131 }

References $ilDB, $query, ilDataCollectionRecordField\getField(), ilDataCollectionCache\getFieldCache(), ilDataCollectionDatatype\INPUTFORMAT_BOOLEAN, ilDataCollectionDatatype\INPUTFORMAT_FILE, ilDataCollectionDatatype\INPUTFORMAT_ILIAS_REF, ilDataCollectionDatatype\INPUTFORMAT_MOB, ilDataCollectionDatatype\INPUTFORMAT_NUMBER, and ilDataCollectionDatatype\INPUTFORMAT_TEXT.

+ Here is the call graph for this function:

◆ setMaxReferenceLength()

ilDataCollectionNReferenceField::setMaxReferenceLength (   $max_reference_length)
Parameters
int$max_reference_length

Definition at line 28 of file class.ilDataCollectionNReferenceField.php.

28 {
29 $this->max_reference_length = $max_reference_length;
30 }

References $max_reference_length.

Field Documentation

◆ $max_reference_length

ilDataCollectionNReferenceField::$max_reference_length = 20
protected

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