ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_once('./Modules/DataCollection/classes/Fields/Base/class.ilDclBaseRecordFieldModel.php');
6
16 public function parseValue($value) {
17 global $DIC;
18 if ($value == -1) //marked for deletion.
19 {
20 return 0;
21 }
22
23 $file = $value;
24
25 $has_save_confirmation = ($this->getRecord()->getTable()->getSaveConfirmation() && !isset($_GET['record_id']));
26 $is_confirmed = (bool) (isset($_POST['save_confirmed']));
27
28 if (is_array($file) && $file['tmp_name'] != "" && (!$has_save_confirmation || $is_confirmed)) {
29 $file_obj = new ilObjFile();
30 $file_obj->setType("file");
31 $file_obj->setTitle($file["name"]);
32 $file_obj->setFileName($file["name"]);
33 $file_obj->setFileType(ilMimeTypeUtil::getMimeType("", $file["name"], $file["type"]));
34 $file_obj->setFileSize($file["size"]);
35 $file_obj->setMode("object");
36 $file_obj->create();
37
38 if($has_save_confirmation) {
39 $move_file = ilDclPropertyFormGUI::getTempFilename($_POST['ilfilehash'], 'field_'.$this->getField()->getId(), $file["name"], $file["type"]);
40 $file_obj->storeUnzipedFile($move_file, $file["name"]);
41 } else {
42 $move_file = $file['tmp_name'];
43 $file_obj->getUploadFile($move_file, $file["name"]);
44 }
45
46 $file_id = $file_obj->getId();
47 $return = $file_id;
48 // handover for save-confirmation
49 } else if(is_array($file) && isset($file['tmp_name']) && $file['tmp_name'] != "") {
50 $return = $file;
51 } else {
52 $return = $this->getValue();
53 }
54
55 return $return;
56 }
57
61 public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation) {
62 if (is_array($this->getValue())) {
63 foreach($this->getValue() as $key=>$value) {
64 $confirmation->addHiddenItem('field_'.$this->field->getId().'['.$key.']', $value);
65 }
66 }
67 }
68
69
76 public function setValue($value, $omit_parsing = false) {
77 $this->loadValue();
78
79 if (! $omit_parsing) {
80 $tmp = $this->parseValue($value, $this);
82 //if parse value fails keep the old value
83 if ($tmp !== false) {
84 $this->value = $tmp;
85 //delete old file from filesystem
86 if ($old && $old != $tmp) {
87 $this->getRecord()->deleteFile($old);
88 }
89 }
90 } else {
91 $this->value = $value;
92 }
93 }
94
95
99 public function parseExportValue($value) {
100 if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
101 return;
102 }
103
104 $file = $value;
105 if ($file != "-") {
106 $file_obj = new ilObjFile($file, false);
107 $file_name = $file_obj->getFileName();
108
109 return $file_name;
110 }
111 return $file;
112 }
113
114
124 public function parseSortingValue($value, $link = true) {
125 if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
126 return '';
127 }
128 $file_obj = new ilObjFile($value, false);
129 return $file_obj->getTitle();
130 }
131
135 public function setValueFromForm($form) {
136 $value = $form->getInput("field_" . $this->getField()->getId());
137 if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
138 $value = - 1;
139 }
140 $this->setValue($value);
141 }
142
143
147 public function afterClone() {
151
152 if (!$record_field || !$record_field->getValue()) {
153 return;
154 }
155
156 $file_old = new ilObjFile($record_field->getValue(), false);
157 $file_new = $file_old->cloneObject(null, null, true);
158
159 $this->setValue($file_new->getId(), true);
160 $this->doUpdate();
161 }
162
163
164}
$_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.
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....
parseValue($value)
Function to parse incoming data from form input value $value.
static getTempFilename($a_hash, $a_field, $a_name, $a_type, $a_index=null, $a_sub_index=null)
return temp-filename
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
$old
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC