ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilDclFileuploadRecordFieldModel Class Reference
+ Inheritance diagram for ilDclFileuploadRecordFieldModel:
+ Collaboration diagram for ilDclFileuploadRecordFieldModel:

Public Member Functions

 __construct (ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
 
 parseValue ($value)
 
 addHiddenItemsToConfirmation (ilConfirmationGUI $confirmation)
 
 setValue ($value, bool $omit_parsing=false)
 Set value for record field. More...
 
 parseExportValue ($value)
 
 parseSortingValue ($value, bool $link=true)
 Returns sortable value for the specific field-types. More...
 
 setValueFromForm (ilPropertyFormGUI $form)
 
 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)
 

Private Attributes

ILIAS FileUpload FileUpload $upload
 

Additional Inherited Members

- Protected Member Functions inherited from ilDclBaseRecordFieldModel
 doRead ()
 Read object data from database. More...
 
 loadValue ()
 Load the value. More...
 
- 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 22 of file class.ilDclFileuploadRecordFieldModel.php.

Constructor & Destructor Documentation

◆ __construct()

ilDclFileuploadRecordFieldModel::__construct ( ilDclBaseRecordModel  $record,
ilDclBaseFieldModel  $field 
)

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

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), and ILIAS\Repository\upload().

27  {
28  parent::__construct($record, $field);
29  global $DIC;
30  $this->upload = $DIC->upload();
31  }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ addHiddenItemsToConfirmation()

ilDclFileuploadRecordFieldModel::addHiddenItemsToConfirmation ( ilConfirmationGUI  $confirmation)

Definition at line 111 of file class.ilDclFileuploadRecordFieldModel.php.

References ILIAS\LTI\ToolProvider\$key, ilDclBaseRecordFieldModel\$value, ilConfirmationGUI\addHiddenItem(), and ilDclBaseRecordFieldModel\getValue().

111  : void
112  {
113  if (is_array($this->getValue())) {
114  foreach ($this->getValue() as $key => $value) {
115  $confirmation->addHiddenItem('field_' . $this->field->getId() . '[' . $key . ']', $value);
116  }
117  }
118  }
addHiddenItem(string $a_post_var, string $a_value)
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the call graph for this function:

◆ afterClone()

ilDclFileuploadRecordFieldModel::afterClone ( )

Definition at line 194 of file class.ilDclFileuploadRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$field, ilDclBaseRecordFieldModel\$record, ilObject2\cloneObject(), ilDclBaseRecordFieldModel\doUpdate(), ilDclCache\getCloneOf(), ilDclBaseRecordFieldModel\getField(), ilObject\getId(), ilDclBaseRecordFieldModel\getId(), ilDclBaseRecordFieldModel\getRecord(), ilDclCache\getRecordFieldCache(), setValue(), ilDclCache\TYPE_FIELD, and ilDclCache\TYPE_RECORD.

194  : void
195  {
199 
200  if (!$record_field || !$record_field->getValue()) {
201  return;
202  }
203 
204  $file_old = new ilObjFile($record_field->getValue(), false);
205  $file_new = $file_old->cloneObject(0, 0, true);
206 
207  $this->setValue($file_new->getId(), true);
208  $this->doUpdate();
209  }
doUpdate()
Update object in database.
setValue($value, bool $omit_parsing=false)
Set value for record field.
Class ilObjFile.
cloneObject(int $target_id, int $copy_id=0, bool $omit_tree=false)
static getCloneOf(int $id, string $type)
static getRecordFieldCache(object $record, object $field)
+ Here is the call graph for this function:

◆ parseExportValue()

ilDclFileuploadRecordFieldModel::parseExportValue (   $value)
Parameters
string$value

Definition at line 148 of file class.ilDclFileuploadRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$value, ilObject\_exists(), and ilObject\_lookupType().

148  : ?string
149  {
151  return null;
152  }
153 
154  $file = $value;
155  if ($file != "-") {
156  $file_obj = new ilObjFile($file, false);
157  $file_name = $file_obj->getFileName();
158 
159  return $file_name;
160  }
161 
162  return $file;
163  }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
Class ilObjFile.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ parseSortingValue()

ilDclFileuploadRecordFieldModel::parseSortingValue (   $value,
bool  $link = true 
)

Returns sortable value for the specific field-types.

Parameters
int$value

Definition at line 169 of file class.ilDclFileuploadRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$value, ilObject\_exists(), and ilObject\_lookupType().

169  : string
170  {
172  return '';
173  }
174  $file_obj = new ilObjFile($value, false);
175 
176  return $file_obj->getTitle();
177  }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
Class ilObjFile.
static _lookupType(int $id, bool $reference=false)
+ Here is the call graph for this function:

◆ parseValue()

ilDclFileuploadRecordFieldModel::parseValue (   $value)
Parameters
null | array | int$value

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

References ilDclBaseRecordFieldModel\$value, ilDclBaseRecordFieldModel\getField(), ilDclBaseRecordFieldModel\getId(), ilDclBaseRecordFieldModel\getRecord(), ilDclPropertyFormGUI\getTempFilename(), ilDclBaseRecordFieldModel\getValue(), ILIAS\FileDelivery\http(), ILIAS\Repository\lng(), ilObjFile\MODE_OBJECT, ILIAS\Filesystem\Stream\Streams\ofResource(), ILIAS\Repository\refinery(), and ILIAS\Repository\upload().

Referenced by setValue().

37  {
38  if ($value === -1) { //marked for deletion.
39  return null;
40  }
41 
42  $file = $value;
43 
44  $has_record_id = $this->http->wrapper()->query()->has('record_id');
45  $is_confirmed = $this->http->wrapper()->post()->has('save_confirmed');
46  $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !$has_record_id);
47 
48  if (
49  is_array($file)
50  && isset($file['tmp_name'])
51  && $file['tmp_name'] !== ""
52  && (!$has_save_confirmation || $is_confirmed)
53  ) {
54  if ($has_save_confirmation) {
55  $ilfilehash = $this->http->wrapper()->post()->retrieve(
56  'ilfilehash',
57  $this->refinery->kindlyTo()->string()
58  );
59 
61  $ilfilehash,
62  'field_' . $this->getField()->getId(),
63  $file["name"],
64  $file["type"]
65  );
66 
67  $file_stream = ILIAS\Filesystem\Stream\Streams::ofResource(fopen($move_file, 'rb'));
68  } else {
69  $move_file = $file['tmp_name'];
70 
71  if (false === $this->upload->hasBeenProcessed()) {
72  $this->upload->process();
73  }
74 
75  if (false === $this->upload->hasUploads()) {
76  throw new ilException($this->lng->txt('upload_error_file_not_found'));
77  }
78 
79  $file_stream = Streams::ofResource(fopen($move_file, 'rb'));
80  }
81 
82  $file_title = $file["name"] ?? basename($move_file);
83 
84  $file_obj = new ilObjFile();
85  $file_obj->setType("file");
86  $file_obj->setTitle($file_title);
87  $file_obj->setFileName($file_title);
88  $file_obj->setMode(ilObjFile::MODE_OBJECT);
89  $file_obj->create();
90 
91  $file_obj->appendStream($file_stream, $file_title);
92  $file_obj->setTitle($file_title);
93  $file_obj->setFileName($file_title);
94 
95  $file_obj->update();
96 
97  $file_id = $file_obj->getId();
98  $return = $file_id;
99  // handover for save-confirmation
100  } else {
101  if (is_array($file) && isset($file['tmp_name']) && $file['tmp_name'] != "") {
102  $return = $file;
103  } else {
104  $return = $this->getValue();
105  }
106  }
107 
108  return $return;
109  }
static ofResource($resource)
Wraps an already created resource with the stream abstraction.
Definition: Streams.php:65
static http()
Fetches the global http state from ILIAS.
Class ilObjFile.
const MODE_OBJECT
static getTempFilename(string $a_hash, string $a_field, string $a_name, string $a_type, ?string $a_index=null, ?string $a_sub_index=null)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setValue()

ilDclFileuploadRecordFieldModel::setValue (   $value,
bool  $omit_parsing = false 
)

Set value for record field.

Parameters
string | int$value
bool$omit_parsingIf true, does not parse the value and stores it in the given format

Definition at line 125 of file class.ilDclFileuploadRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$value, ilDclBaseRecordFieldModel\getRecord(), ilDclBaseRecordFieldModel\loadValue(), and parseValue().

Referenced by afterClone(), and setValueFromForm().

125  : void
126  {
127  $this->loadValue();
128 
129  if (!$omit_parsing) {
130  $tmp = $this->parseValue($value);
131  $old = $this->value;
132  //if parse value fails keep the old value
133  if ($tmp !== false) {
134  $this->value = $tmp;
135  //delete old file from filesystem
136  if ($old && $old != $tmp) {
137  $this->getRecord()->deleteFile($old);
138  }
139  }
140  } else {
141  $this->value = $value;
142  }
143  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setValueFromForm()

ilDclFileuploadRecordFieldModel::setValueFromForm ( ilPropertyFormGUI  $form)

Definition at line 182 of file class.ilDclFileuploadRecordFieldModel.php.

References ilDclBaseRecordFieldModel\$value, ilDclBaseRecordFieldModel\getField(), ilDclBaseRecordFieldModel\getId(), ilPropertyFormGUI\getInput(), ilPropertyFormGUI\getItemByPostVar(), and setValue().

182  : void
183  {
184  $value = $form->getInput("field_" . $this->getField()->getId());
185  if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
186  $value = -1;
187  }
188  $this->setValue($value);
189  }
getItemByPostVar(string $a_post_var)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
setValue($value, bool $omit_parsing=false)
Set value for record field.
+ Here is the call graph for this function:

Field Documentation

◆ $upload

ILIAS FileUpload FileUpload ilDclFileuploadRecordFieldModel::$upload
private

Definition at line 24 of file class.ilDclFileuploadRecordFieldModel.php.


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