ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 
15 {
16  public function parseValue($value)
17  {
18  global $DIC;
19  if ($value == -1) { //marked for deletion.
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_obj->update();
47 
48  $file_id = $file_obj->getId();
49  $return = $file_id;
50  // handover for save-confirmation
51  } elseif (is_array($file) && isset($file['tmp_name']) && $file['tmp_name'] != "") {
52  $return = $file;
53  } else {
54  $return = $this->getValue();
55  }
56 
57  return $return;
58  }
59 
63  public function addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
64  {
65  if (is_array($this->getValue())) {
66  foreach ($this->getValue() as $key=>$value) {
67  $confirmation->addHiddenItem('field_' . $this->field->getId() . '[' . $key . ']', $value);
68  }
69  }
70  }
71 
72 
79  public function setValue($value, $omit_parsing = false)
80  {
81  $this->loadValue();
82 
83  if (!$omit_parsing) {
84  $tmp = $this->parseValue($value, $this);
86  //if parse value fails keep the old value
87  if ($tmp !== false) {
88  $this->value = $tmp;
89  //delete old file from filesystem
90  if ($old && $old != $tmp) {
91  $this->getRecord()->deleteFile($old);
92  }
93  }
94  } else {
95  $this->value = $value;
96  }
97  }
98 
99 
103  public function parseExportValue($value)
104  {
105  if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
106  return;
107  }
108 
109  $file = $value;
110  if ($file != "-") {
111  $file_obj = new ilObjFile($file, false);
112  $file_name = $file_obj->getFileName();
113 
114  return $file_name;
115  }
116  return $file;
117  }
118 
119 
129  public function parseSortingValue($value, $link = true)
130  {
131  if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
132  return '';
133  }
134  $file_obj = new ilObjFile($value, false);
135  return $file_obj->getTitle();
136  }
137 
141  public function setValueFromForm($form)
142  {
143  $value = $form->getInput("field_" . $this->getField()->getId());
144  if ($form->getItemByPostVar("field_" . $this->getField()->getId())->getDeletionFlag()) {
145  $value = -1;
146  }
147  $this->setValue($value);
148  }
149 
150 
154  public function afterClone()
155  {
159 
160  if (!$record_field || !$record_field->getValue()) {
161  return;
162  }
163 
164  $file_old = new ilObjFile($record_field->getValue(), false);
165  $file_new = $file_old->cloneObject(null, null, true);
166 
167  $this->setValue($file_new->getId(), true);
168  $this->doUpdate();
169  }
170 }
static getCloneOf($id, $type)
addHiddenItem($a_post_var, $a_value)
Add hidden item.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
addHiddenItemsToConfirmation(ilConfirmationGUI &$confirmation)
setValue($value, $omit_parsing=false)
Set value for record field.
static getMimeType($a_file='', $a_filename='', $a_mime='')
if(isset($_POST['submit'])) $form
doUpdate()
Update object in database.
parseSortingValue($value, $link=true)
Returns sortable value for the specific field-types.
$old
static getRecordFieldCache($record, $field)
static _lookupType($a_id, $a_reference=false)
static _exists($a_id, $a_reference=false, $a_type=null)
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
$key
Definition: croninfo.php:18
$_POST["username"]
Confirmation screen class.
static getTempFilename($a_hash, $a_field, $a_name, $a_type, $a_index=null, $a_sub_index=null)
return temp-filename