BUGFIX: Abstracted out submitted form field classes to make it easier to extend submitted form class type to save data into. PATCH via jam13 #5071

This commit is contained in:
Will Rossiter 2010-02-14 07:53:16 +00:00
parent 10bf22cb00
commit 6f720fd30d
4 changed files with 15 additions and 26 deletions

View File

@ -505,7 +505,7 @@ JS
// don't show fields that shouldn't be shown
if(!$field->showInReports()) continue;
$submittedField = new SubmittedFormField();
$submittedField = $field->getSubmittedFormField();
$submittedField->ParentID = $submittedForm->ID;
$submittedField->Name = $field->Name;
$submittedField->Title = $field->Title;
@ -518,11 +518,7 @@ JS
}
if(!empty($data[$field->Name])){
/**
* @todo this should be on the EditableFile class. Just need to sort out
* attachments array
*/
if($field->ClassName == "EditableFileField"){
if(in_array("EditableFileField", $field->getClassAncestry())) {
if(isset($_FILES[$field->Name])) {
// create the file from post data
@ -537,13 +533,6 @@ JS
if($file->getAbsoluteSize() < 1024*1024*1){
$attachments[] = $file;
}
// Always provide the link if present.
if($file->ID) {
$submittedField->Value = "<a href=\"". $file->getFilename() ."\" title=\"". $file->getFilename() . "\">". $file->Title . "</a>";
} else {
$submittedField->Value = "";
}
}
}
}

View File

@ -7,11 +7,6 @@
class EditableFileField extends EditableFormField {
// this needs to be moved.
static $has_one = array(
"UploadedFile" => "File"
);
/**
* @see Upload->allowedMaxFileSize
* @var int
@ -32,11 +27,7 @@ class EditableFileField extends EditableFormField {
return new FileField($this->Name, $this->Title);
}
/**
* Workaround to handle uploads on the UserFormPage
*/
public function getValueFromData($data) {
return "";
}
public function getSubmittedFormField() {
return new SubmittedFileField();
}
}

View File

@ -333,6 +333,15 @@ class EditableFormField extends DataObject {
user_error("Please implement a getFormField() on your EditableFormClass ". $this->ClassName, E_USER_ERROR);
}
/**
* Return the instance of the submission field class
*
* @return SubmittedFormField
*/
public function getSubmittedFormField() {
return new SubmittedFormField();
}
function showInReports() {
return true;
}

View File

@ -17,7 +17,7 @@ class SubmittedFileField extends SubmittedFormField {
* @return String
*/
function getValue() {
return ($this->UploadedFile()) ? $this->UploadedFile()->Title : "";
return '<a href="'.$this->getLink().'">'. _t('SubmittedFileField.DOWNLOADFILE', 'Download File') .'</a>';
}
/**