ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclFileuploadRecordFieldModel.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
14{
15 public function parseValue($value)
16 {
17 global $DIC;
18 if ($value == -1) { //marked for deletion.
19 return 0;
20 }
21
22 $file = $value;
23
24 $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !isset($_GET['record_id']));
25 $is_confirmed = (bool) (isset($_POST['save_confirmed']));
26
27 if (is_array($file) && $file['tmp_name'] != "" && (!$has_save_confirmation || $is_confirmed)) {
28 $file_obj = new ilObjFile();
29 $file_obj->setType("file");
30 $file_obj->setTitle($file["name"]);
31 $file_obj->setFileName($file["name"]);
32 $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"]));
33 $file_obj->setFileSize($file["size"]);
34 $file_obj->setMode("object");
35 $file_obj->create();
36
37 if ($has_save_confirmation) {
38 $move_file = ilDclPropertyFormGUI::getTempFilename($_POST['ilfilehash'], 'field_' . $this->getField()->getId(), $file["name"], $file["type"]);
39
40 $file_obj->appendStream(
41 \ILIAS\Filesystem\Stream\Streams::ofResource(fopen($move_file, 'rb')),
42 $file_obj->getTitle()
43 );
44
45 $file_obj->setFileName($file["name"]);
46 } else {
47 $move_file = $file['tmp_name'];
51 $upload = $DIC->upload();
52
53 if (false === $upload->hasBeenProcessed()) {
54 $upload->process();
55 }
56
57 if (false === $upload->hasUploads()) {
58 throw new ilException($this->lng->txt('upload_error_file_not_found'));
59 }
60 $file_obj->getUploadFile($move_file, $file["name"]);
61 }
62
63 $file_obj->update();
64
65 $file_id = $file_obj->getId();
66 $return = $file_id;
67 // handover for save-confirmation
68 } else {
69 if (is_array($file) && isset($file['tmp_name']) && $file['tmp_name'] != "") {
70 $return = $file;
71 } else {
72 $return = $this->getValue();
73 }
74 }
75
76 return $return;
77 }
78
79
83 public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
84 {
85 if (is_array($this->getValue())) {
86 foreach ($this->getValue() as $key => $value) {
87 $confirmation->addHiddenItem('field_' . $this->field->getId() . '[' . $key . ']', $value);
88 }
89 }
90 }
91
92
99 public function setValue($value, $omit_parsing = false)
100 {
101 $this->loadValue();
102
103 if (!$omit_parsing) {
104 $tmp = $this->parseValue($value, $this);
105 $old = $this->value;
106 //if parse value fails keep the old value
107 if ($tmp !== false) {
108 $this->value = $tmp;
109 //delete old file from filesystem
110 if ($old && $old != $tmp) {
111 $this->getRecord()->deleteFile($old);
112 }
113 }
114 } else {
115 $this->value = $value;
116 }
117 }
118
119
123 public function parseExportValue($value)
124 {
125 if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
126 return;
127 }
128
129 $file = $value;
130 if ($file != "-") {
131 $file_obj = new ilObjFile($file, false);
132 $file_name = $file_obj->getFileName();
133
134 return $file_name;
135 }
136
137 return $file;
138 }
139
140
150 public function parseSortingValue($value, $link = true)
151 {
152 if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
153 return '';
154 }
155 $file_obj = new ilObjFile($value, false);
156
157 return $file_obj->getTitle();
158 }
159
160
164 public function setValueFromForm($form)
165 {
166 $value = $form->getInput("field_" . $this->getField()->getId());
167 if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
168 $value = -1;
169 }
170 $this->setValue($value);
171 }
172
173
177 public function afterClone()
178 {
182
183 if (!$record_field || !$record_field->getValue()) {
184 return;
185 }
186
187 $file_old = new ilObjFile($record_field->getValue(), false);
188 $file_new = $file_old->cloneObject(null, null, true);
189
190 $this->setValue($file_new->getId(), true);
191 $this->doUpdate();
192 }
193}
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
addHiddenItem($a_post_var, $a_value)
Add hidden item.
parseValue($value)
Function to parse incoming data from form input value $value.
static getRecordFieldCache($record, $field)
static getCloneOf($id, $type)
parseSortingValue($value, $link=true)
Returns sortable value for the specific field-types.
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
setValue($value, $omit_parsing=false)
Set value for record field.
parseExportValue($value)
Function to parse incoming data from form input value $value.returns the string/number/etc....
static getTempFilename($a_hash, $a_field, $a_name, $a_type, $a_index=null, $a_sub_index=null)
return temp-filename
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getMimeType($a_file='', $a_filename='', $a_mime='')
Class ilObjFile.
static _lookupType($a_id, $a_reference=false)
lookup object type
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
global $DIC
Definition: goto.php:24
Class FlySystemFileAccessTest \Provider\FlySystem @runTestsInSeparateProcesses @preserveGlobalState d...
Class ChatMainBarProvider \MainMenu\Provider.