ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $file_obj->storeUnzipedFile($move_file, $file["name"]);
40 } else {
41 $move_file = $file['tmp_name'];
45 $upload = $DIC->upload();
46
47 if (false === $upload->hasBeenProcessed()) {
48 $upload->process();
49 }
50
51 if (false === $upload->hasUploads()) {
52 throw new ilException($this->lng->txt('upload_error_file_not_found'));
53 }
54 $file_obj->getUploadFile($move_file, $file["name"]);
55 }
56
57 $file_obj->update();
58
59 $file_id = $file_obj->getId();
60 $return = $file_id;
61 // handover for save-confirmation
62 } else {
63 if (is_array($file) && isset($file['tmp_name']) && $file['tmp_name'] != "") {
64 $return = $file;
65 } else {
66 $return = $this->getValue();
67 }
68 }
69
70 return $return;
71 }
72
73
77 public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
78 {
79 if (is_array($this->getValue())) {
80 foreach ($this->getValue() as $key => $value) {
81 $confirmation->addHiddenItem('field_' . $this->field->getId() . '[' . $key . ']', $value);
82 }
83 }
84 }
85
86
93 public function setValue($value, $omit_parsing = false)
94 {
95 $this->loadValue();
96
97 if (!$omit_parsing) {
98 $tmp = $this->parseValue($value, $this);
99 $old = $this->value;
100 //if parse value fails keep the old value
101 if ($tmp !== false) {
102 $this->value = $tmp;
103 //delete old file from filesystem
104 if ($old && $old != $tmp) {
105 $this->getRecord()->deleteFile($old);
106 }
107 }
108 } else {
109 $this->value = $value;
110 }
111 }
112
113
117 public function parseExportValue($value)
118 {
119 if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
120 return;
121 }
122
123 $file = $value;
124 if ($file != "-") {
125 $file_obj = new ilObjFile($file, false);
126 $file_name = $file_obj->getFileName();
127
128 return $file_name;
129 }
130
131 return $file;
132 }
133
134
144 public function parseSortingValue($value, $link = true)
145 {
146 if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
147 return '';
148 }
149 $file_obj = new ilObjFile($value, false);
150
151 return $file_obj->getTitle();
152 }
153
154
158 public function setValueFromForm($form)
159 {
160 $value = $form->getInput("field_" . $this->getField()->getId());
161 if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
162 $value = -1;
163 }
164 $this->setValue($value);
165 }
166
167
171 public function afterClone()
172 {
176
177 if (!$record_field || !$record_field->getValue()) {
178 return;
179 }
180
181 $file_old = new ilObjFile($record_field->getValue(), false);
182 $file_new = $file_old->cloneObject(null, null, true);
183
184 $this->setValue($file_new->getId(), true);
185 $this->doUpdate();
186 }
187}
$_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
Base class for ILIAS Exception handling.
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
$DIC
Definition: xapitoken.php:46