2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
2012-04-14 08:36:50 +02:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
/**
|
2012-04-14 08:36:50 +02:00
|
|
|
* Allows a user to add a field that can be used to upload a file.
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-12-07 03:04:20 +01:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
class EditableFileField extends EditableFormField {
|
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = 'File Upload Field';
|
2013-03-04 22:45:54 +01:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $plural_names = 'File Fields';
|
2013-12-20 09:07:35 +01:00
|
|
|
|
|
|
|
public function getFieldConfiguration() {
|
|
|
|
$field = parent::getFieldConfiguration();
|
|
|
|
$folder = ($this->getSetting('Folder')) ? $this->getSetting('Folder') : null;
|
|
|
|
|
|
|
|
$tree = UserformsTreeDropdownField::create(
|
|
|
|
$this->getSettingName("Folder"),
|
|
|
|
_t('EditableUploadField.SELECTUPLOADFOLDER', 'Select upload folder'),
|
|
|
|
"Folder"
|
|
|
|
);
|
|
|
|
|
|
|
|
$tree->setValue($folder);
|
|
|
|
|
|
|
|
$field->push($tree);
|
|
|
|
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
2009-04-27 06:32:47 +02:00
|
|
|
public function getFormField() {
|
2012-04-14 08:36:50 +02:00
|
|
|
$field = new FileField($this->Name, $this->Title);
|
|
|
|
|
2013-12-20 09:07:35 +01:00
|
|
|
if($this->getSetting('Folder')) {
|
|
|
|
$folder = Folder::get()->byId($this->getSetting('Folder'));
|
|
|
|
|
|
|
|
if($folder) {
|
|
|
|
$field->setFolderName(
|
|
|
|
preg_replace("/^assets\//","", $folder->Filename)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-14 08:36:50 +02:00
|
|
|
return $field;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2009-04-28 04:03:13 +02:00
|
|
|
|
2012-04-14 08:36:50 +02:00
|
|
|
|
2014-04-25 15:53:45 +02:00
|
|
|
/**
|
|
|
|
* Return the value for the database, link to the file is stored as a
|
|
|
|
* relation so value for the field can be null.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getValueFromData() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-02-14 08:53:16 +01:00
|
|
|
public function getSubmittedFormField() {
|
|
|
|
return new SubmittedFileField();
|
2012-04-14 08:36:50 +02:00
|
|
|
}
|
2013-12-20 09:07:35 +01:00
|
|
|
}
|