From 2c9e68a9289147f7b8b61cb5e1ca40ccc976d3c4 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sat, 14 Apr 2012 18:36:50 +1200 Subject: [PATCH] MINOR: clean up of project. MINOR: removed versioned task. Out of date for usage. --- code/{editor => formfields}/FieldEditor.php | 0 .../SubmittedFormReportField.php | 0 code/migration/UserFormsMigrationTask.php | 217 ------------------ code/{ => model}/UserDefinedForm.php | 10 - .../formfields}/EditableCheckbox.php | 2 + .../EditableCheckboxGroupField.php | 0 .../EditableCountryDropdownField.php | 0 .../formfields}/EditableDateField.php | 10 +- .../formfields}/EditableDropdown.php | 3 +- .../formfields}/EditableEmailField.php | 0 .../formfields}/EditableFileField.php | 23 +- .../formfields}/EditableFormField.php | 12 +- .../formfields}/EditableFormHeading.php | 19 +- .../formfields}/EditableLiteralField.php | 10 +- .../formfields}/EditableMemberListField.php | 11 +- .../EditableMultipleOptionField.php | 45 ++-- .../formfields}/EditableOption.php | 0 .../formfields}/EditableRadioField.php | 1 - .../formfields}/EditableTextField.php | 23 +- code/model/submissions/SubmittedFileField.php | 44 ++++ .../{ => model}/submissions/SubmittedForm.php | 0 .../submissions/SubmittedFormField.php | 0 code/submissions/SubmittedFileField.php | 36 --- .../UserFormsVersionedTask.php | 0 tests/EditableFormFieldTest.php | 2 +- 25 files changed, 130 insertions(+), 338 deletions(-) rename code/{editor => formfields}/FieldEditor.php (100%) rename code/{submissions => formfields}/SubmittedFormReportField.php (100%) delete mode 100644 code/migration/UserFormsMigrationTask.php rename code/{ => model}/UserDefinedForm.php (99%) rename code/{editor => model/formfields}/EditableCheckbox.php (99%) rename code/{editor => model/formfields}/EditableCheckboxGroupField.php (100%) rename code/{editor => model/formfields}/EditableCountryDropdownField.php (100%) rename code/{editor => model/formfields}/EditableDateField.php (82%) rename code/{editor => model/formfields}/EditableDropdown.php (94%) rename code/{editor => model/formfields}/EditableEmailField.php (100%) rename code/{editor => model/formfields}/EditableFileField.php (57%) rename code/{editor => model/formfields}/EditableFormField.php (96%) rename code/{editor => model/formfields}/EditableFormHeading.php (70%) rename code/{editor => model/formfields}/EditableLiteralField.php (82%) rename code/{editor => model/formfields}/EditableMemberListField.php (82%) rename code/{editor => model/formfields}/EditableMultipleOptionField.php (72%) rename code/{editor => model/formfields}/EditableOption.php (100%) rename code/{editor => model/formfields}/EditableRadioField.php (99%) rename code/{editor => model/formfields}/EditableTextField.php (63%) create mode 100755 code/model/submissions/SubmittedFileField.php rename code/{ => model}/submissions/SubmittedForm.php (100%) rename code/{ => model}/submissions/SubmittedFormField.php (100%) delete mode 100755 code/submissions/SubmittedFileField.php rename code/{migration => tasks}/UserFormsVersionedTask.php (100%) diff --git a/code/editor/FieldEditor.php b/code/formfields/FieldEditor.php similarity index 100% rename from code/editor/FieldEditor.php rename to code/formfields/FieldEditor.php diff --git a/code/submissions/SubmittedFormReportField.php b/code/formfields/SubmittedFormReportField.php similarity index 100% rename from code/submissions/SubmittedFormReportField.php rename to code/formfields/SubmittedFormReportField.php diff --git a/code/migration/UserFormsMigrationTask.php b/code/migration/UserFormsMigrationTask.php deleted file mode 100644 index 11faeeb..0000000 --- a/code/migration/UserFormsMigrationTask.php +++ /dev/null @@ -1,217 +0,0 @@ -dryRun = (isset($_GET['dryRun'])) ? true : false; - - if($this->dryRun) { - echo "Will be running this test as a dry run. No data will be added or removed.
"; - } - - // if they want to import just 1 form - eg for testing - if(isset($_GET['formID'])) { - $id = Convert::raw2sql($_GET['formID']); - $forms->push(DataObject::get_by_id('UserDefinedForm', $id)); - } - - if(!$forms) { - echo "No UserForms Found on Database"; - return; - } - - echo "Proceeding to update ". $forms->Count() . " Forms
"; - - foreach($forms as $form) { - echo " -- Updating $form->URLSegment
"; - // easy step first port over email data from the structure - if($form->EmailOnSubmit && $form->EmailTo) { - // EmailTo can be a comma separated list so we need to explode that - $emails = explode(",", $form->EmailTo); - if($emails) { - foreach($emails as $email) { - $emailTo = new UserDefinedForm_EmailRecipient(); - $emailTo->EmailAddress = trim($email); - $emailTo->EmailSubject = ($form) ? $form->Title : _t('UserFormsMigrationTask.DEFAULTSUBMISSIONTITLE',"Submission Data"); - $emailTo->EmailFrom = Email::getAdminEmail(); - $emailTo->FormID = $form->ID; - echo " -- -- Created new Email Recipient $email
"; - if(!$this->dryRun) $emailTo->write(); - } - } - } - // now fix all the fields - if($form->Fields()) { - foreach($form->Fields() as $field) { - switch($field->ClassName) { - case 'EditableDropdown': - case 'EditableRadioField': - case 'EditableCheckboxGroupField': - $optionClass = "EditableDropdownOption"; - if($field->ClassName == "EditableRadioField") { - $optionClass = "EditableRadioOption"; - } - else if($field->ClassName == "EditableCheckboxGroupField") { - $optionClass = "EditableCheckboxOption"; - } - $query = DB::query("SELECT * FROM \"$optionClass\" WHERE \"ParentID\" = '$field->ID'"); - $result = $query->first(); - if($result) { - do { - $this->createOption($result, $optionClass); - } while($result = $query->next()); - } - - break; - - case 'EditableTextField': - $database = $this->findDatabaseTableName('EditableTextField'); - - // get the data from the table - $result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first(); - - if($result) { - $field->setSettings(array( - 'Size' => $result['Size'], - 'MinLength' => $result['MinLength'], - 'MaxLength' => $result['MaxLength'], - 'Rows' => $result['Rows'] - )); - } - - break; - - case 'EditableLiteralField': - if($field->Content) { - // find what table to use - $database = $this->findDatabaseTableName('EditableLiteralField'); - - // get the data from the table - $result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first(); - - if($result) { - $field->setSettings(array( - 'Content' => $result['Content'] - )); - } - } - break; - - case 'EditableMemberListField': - if($field->GroupID) { - // find what table to use - $database = $this->findDatabaseTableName('EditableMemberListField'); - - // get the data from the table - $result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first(); - - if($result) { - $field->setSettings(array( - 'GroupID' => $result['GroupID'] - )); - } - } - break; - - case 'EditableCheckbox': - if($field->Checked) { - // find what table to use - $database = $this->findDatabaseTableName('EditableCheckbox'); - - // get the data from the table - $result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first(); - - if($result) { - $field->setSettings(array( - 'Default' => $result['Checked'] - )); - } - } - break; - - case 'EditableEmailField': - $database = $this->findDatabaseTableName('EditableEmailField'); - $result = DB::query("SELECT * FROM \"$database\" WHERE \"ID\" = $field->ID")->first(); - if($result && isset($result['SendCopy']) && $result['SendCopy'] == true) { - // we do not store send copy on email field anymore. This has been wrapped into - // the email recipients - $emailTo = new UserDefinedForm_EmailRecipient(); - $emailTo->EmailSubject = ($form) ? $form->Title : _t('UserFormsMigrationTask.DEFAULTSUBMISSIONTITLE',"Submission Data"); - $emailTo->EmailFrom = Email::getAdminEmail(); - $emailTo->FormID = $form->ID; - $emailTo->SendEmailToFieldID = $field->ID; - $emailTo->EmailBody = $form->EmailMessageToSubmitter; - if(!$this->dryRun) $emailTo->write(); - } - break; - } - if(!$this->dryRun) $field->write(); - } - } - } - echo "

Migration Complete

"; - } - /** - * Find if this table is obsolete or used - * - */ - function findDatabaseTableName($tableName) { - $exist = DB::tableList(); - if(!empty($exist)) { - if(array_search($tableName, $exist) !== false) return $tableName; - $tableName = "_obsolete_$tableName"; - if(array_search($tableName, $exist) !== false) return $tableName; - } - echo '!! Could Not Find '.$tableName; - return; - } - - /** - * Create a EditableOption from a whatever type of multi - * form field it is coming from - */ - function createOption($option, $class) { - - $editableOption = new EditableOption(); - $editableOption->ParentID = $option['ParentID']; - if(!$this->dryRun) $editableOption->populateFromPostData($option); - // log - echo " -- -- Created new option $editableOption->Title
"; - } -} \ No newline at end of file diff --git a/code/UserDefinedForm.php b/code/model/UserDefinedForm.php similarity index 99% rename from code/UserDefinedForm.php rename to code/model/UserDefinedForm.php index 06f26e5..513f6f1 100755 --- a/code/UserDefinedForm.php +++ b/code/model/UserDefinedForm.php @@ -11,16 +11,6 @@ class UserDefinedForm extends Page { - /** - * @var String Icon for the User Defined Form in the CMS. Without the extension - */ - static $icon = "cms/images/treeicons/task"; - - /** - * @var String What level permission is needed to edit / add - */ - static $need_permission = array('ADMIN'); - /** * @var String Required Identifier */ diff --git a/code/editor/EditableCheckbox.php b/code/model/formfields/EditableCheckbox.php similarity index 99% rename from code/editor/EditableCheckbox.php rename to code/model/formfields/EditableCheckbox.php index 67c316b..61023ff 100755 --- a/code/editor/EditableCheckbox.php +++ b/code/model/formfields/EditableCheckbox.php @@ -1,6 +1,7 @@ push(new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default'))); + return $options; } diff --git a/code/editor/EditableCheckboxGroupField.php b/code/model/formfields/EditableCheckboxGroupField.php similarity index 100% rename from code/editor/EditableCheckboxGroupField.php rename to code/model/formfields/EditableCheckboxGroupField.php diff --git a/code/editor/EditableCountryDropdownField.php b/code/model/formfields/EditableCountryDropdownField.php similarity index 100% rename from code/editor/EditableCountryDropdownField.php rename to code/model/formfields/EditableCountryDropdownField.php diff --git a/code/editor/EditableDateField.php b/code/model/formfields/EditableDateField.php similarity index 82% rename from code/editor/EditableDateField.php rename to code/model/formfields/EditableDateField.php index c321ace..0dd36de 100755 --- a/code/editor/EditableDateField.php +++ b/code/model/formfields/EditableDateField.php @@ -2,10 +2,7 @@ /** * EditableDateField * - * Allows a user to add a date field to the Field Editor - * - * @todo Localization, Time Field / Date time field combinations. Set ranges of dates, - * set default date + * Allows a user to add a date field. * * @package userforms */ @@ -17,10 +14,11 @@ class EditableDateField extends EditableFormField { static $plural_name = 'Date Fields'; function getFieldConfiguration() { - $defaultToToday = ($this->getSetting('DefaultToToday')) ? $this->getSetting('DefaultToToday') : false; + $default = ($this->getSetting('DefaultToToday')) ? $this->getSetting('DefaultToToday') : false; + $label = _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?'); return new FieldSet( - new CheckboxField("Fields[$this->ID][CustomSettings][DefaultToToday]", _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?'), $defaultToToday) + new CheckboxField($this->getSettingName("DefaultToToday"), $label, $default) ); } diff --git a/code/editor/EditableDropdown.php b/code/model/formfields/EditableDropdown.php similarity index 94% rename from code/editor/EditableDropdown.php rename to code/model/formfields/EditableDropdown.php index b0b0cb8..7bc0515 100755 --- a/code/editor/EditableDropdown.php +++ b/code/model/formfields/EditableDropdown.php @@ -16,8 +16,7 @@ class EditableDropdown extends EditableMultipleOptionField { /** * @return DropdownField */ - function getFormField() { - + function getFormField() { $optionSet = $this->Options(); $options = array(); diff --git a/code/editor/EditableEmailField.php b/code/model/formfields/EditableEmailField.php similarity index 100% rename from code/editor/EditableEmailField.php rename to code/model/formfields/EditableEmailField.php diff --git a/code/editor/EditableFileField.php b/code/model/formfields/EditableFileField.php similarity index 57% rename from code/editor/EditableFileField.php rename to code/model/formfields/EditableFileField.php index 88e4521..2591469 100755 --- a/code/editor/EditableFileField.php +++ b/code/model/formfields/EditableFileField.php @@ -1,33 +1,24 @@ allowedMaxFileSize - * @var int - */ - public static $allowed_max_file_size; - - /** - * @see Upload->allowedExtensions - * @var array - */ - public static $allowed_extensions = array(); - static $singular_name = 'File Upload Field'; - static $plural_names = 'File Fields'; public function getFormField() { - return new FileField($this->Name, $this->Title); + $field = new FileField($this->Name, $this->Title); + + return $field; } + public function getSubmittedFormField() { return new SubmittedFileField(); - } + } } \ No newline at end of file diff --git a/code/editor/EditableFormField.php b/code/model/formfields/EditableFormField.php similarity index 96% rename from code/editor/EditableFormField.php rename to code/model/formfields/EditableFormField.php index 13b209e..f61503a 100755 --- a/code/editor/EditableFormField.php +++ b/code/model/formfields/EditableFormField.php @@ -191,8 +191,7 @@ class EditableFormField extends DataObject { } /** - * Return the Custom Validation fields for this - * field for the CMS + * Return the custom validation fields for this field for the CMS * * @return array */ @@ -242,8 +241,9 @@ class EditableFormField extends DataObject { * @return TextField */ function TitleField() { - //do not XML escape the title field here, because that would result in a recursive escaping of the escaped text on every save - $field = new TextField('Title', _t('EditableFormField.ENTERQUESTION', 'Enter Question'), $this->getField('Title')); + $label = _t('EditableFormField.ENTERQUESTION', 'Enter Question'); + + $field = new TextField('Title', $label, $this->getField('Title')); $field->setName($this->getFieldName('Title')); if(!$this->canEdit()) { @@ -276,7 +276,7 @@ class EditableFormField extends DataObject { * @param String name of the setting * @return String */ - public function getSettingFieldName($field) { + public function getSettingName($field) { $name = $this->getFieldName('CustomSettings'); return $name . '[' . $field .']'; @@ -344,7 +344,7 @@ class EditableFormField extends DataObject { public function getFieldConfiguration() { return new FieldSet( new TextField( - $this->getSettingFieldName('RightTitle'), + $this->getSettingName('RightTitle'), _t('EditableFormField.RIGHTTITLE', 'Right Title'), $this->getSetting('RightTitle') ) diff --git a/code/editor/EditableFormHeading.php b/code/model/formfields/EditableFormHeading.php similarity index 70% rename from code/editor/EditableFormHeading.php rename to code/model/formfields/EditableFormHeading.php index 0e2e14f..4b791ac 100755 --- a/code/editor/EditableFormHeading.php +++ b/code/model/formfields/EditableFormHeading.php @@ -2,7 +2,7 @@ /** * Allows an editor to insert a generic heading into a field * - * @subpackage userforms + * @package userforms */ class EditableFormHeading extends EditableFormField { @@ -12,15 +12,28 @@ class EditableFormHeading extends EditableFormField { static $plural_name = 'Headings'; function getFieldConfiguration() { - $levels = array('1' => '1','2' => '2','3' => '3','4' => '4','5' => '5','6' => '6'); + $levels = array( + '1' => '1', + '2' => '2', + '3' => '3', + '4' => '4', + '5' => '5', + '6' => '6' + ); + $level = ($this->getSetting('Level')) ? $this->getSetting('Level') : 3; + $label = _t('EditableFormHeading.LEVEL', 'Select Heading Level'); $options = parent::getFieldConfiguration(); - $options->push(new DropdownField("Fields[$this->ID][CustomSettings][Level]", _t('EditableFormHeading.LEVEL', 'Select Heading Level'), $levels, $level)); + + $options->push( + new DropdownField($this->getSettingName("Level"), $label, $levels, $level) + ); if($this->readonly) { $extraFields = $options->makeReadonly(); } + return $options; } diff --git a/code/editor/EditableLiteralField.php b/code/model/formfields/EditableLiteralField.php similarity index 82% rename from code/editor/EditableLiteralField.php rename to code/model/formfields/EditableLiteralField.php index b7a50f0..6436183 100644 --- a/code/editor/EditableLiteralField.php +++ b/code/model/formfields/EditableLiteralField.php @@ -16,11 +16,11 @@ class EditableLiteralField extends EditableFormField { function getFieldConfiguration() { return new FieldSet( new TextareaField( - "Fields[$this->ID][CustomSettings][Content]", + $this->getSettingName('Content'), "HTML", 4, 20, $this->getSetting('Content') ), new CheckboxField( - "Fields[$this->ID][CustomSettings][HideFromReports]", + $this->getSettingName('HideFromReports'), _t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?'), $this->getSetting('HideFromReports') ) @@ -37,10 +37,6 @@ class EditableLiteralField extends EditableFormField { } function showInReports() { - if($this->getSetting('HideFromReports')) { - return false; - } - - return true; + return (!$this->getSetting('HideFromReports')); } } \ No newline at end of file diff --git a/code/editor/EditableMemberListField.php b/code/model/formfields/EditableMemberListField.php similarity index 82% rename from code/editor/EditableMemberListField.php rename to code/model/formfields/EditableMemberListField.php index d7eb725..2a738f8 100644 --- a/code/editor/EditableMemberListField.php +++ b/code/model/formfields/EditableMemberListField.php @@ -14,7 +14,9 @@ class EditableMemberListField extends EditableFormField { function getFieldConfiguration() { $groupID = ($this->getSetting('GroupID')) ? $this->getSetting('GroupID') : 0; $groups = DataObject::get("Group"); + if($groups) $groups = $groups->toDropdownMap('ID', 'Title'); + $fields = new FieldSet( new DropdownField("Fields[$this->ID][CustomSettings][GroupID]", _t('EditableFormField.GROUP', 'Group'), $groups, $groupID) ); @@ -23,7 +25,13 @@ class EditableMemberListField extends EditableFormField { } function getFormField() { - return ($this->getSetting('GroupID')) ? new DropdownField( $this->Name, $this->Title, Member::mapInGroups($this->getSetting('GroupID'))) : false; + if ($this->getSetting('GroupID')) { + $members = Member::mapInGroups($this->getSetting('GroupID')); + + return new DropdownField($this->Name, $this->Title, $members); + } + + return false; } function getValueFromData($data) { @@ -31,6 +39,7 @@ class EditableMemberListField extends EditableFormField { $value = Convert::raw2sql($data[$this->Name]); $member = DataObject::get_one('Member', "Member.ID = {$value}"); + return ($member) ? $member->getName() : ""; } diff --git a/code/editor/EditableMultipleOptionField.php b/code/model/formfields/EditableMultipleOptionField.php similarity index 72% rename from code/editor/EditableMultipleOptionField.php rename to code/model/formfields/EditableMultipleOptionField.php index 61109fa..6058e82 100644 --- a/code/editor/EditableMultipleOptionField.php +++ b/code/model/formfields/EditableMultipleOptionField.php @@ -1,20 +1,20 @@ "EditableOption" ); @@ -35,6 +35,7 @@ class EditableMultipleOptionField extends EditableFormField { $option->delete(); } } + if($this->Options()) { foreach($this->Options() as $option) { $option->publish($fromStage, $toStage, $createNewVersion); @@ -62,27 +63,28 @@ class EditableMultipleOptionField extends EditableFormField { } /** - * Deletes all the options attached to this field before - * deleting the field. Keeps stray options from floating - * around + * Deletes all the options attached to this field before deleting the + * field. Keeps stray options from floating around * * @return void */ public function delete() { $options = $this->Options(); + if($options) { foreach($options as $option) { $option->delete(); } } + parent::delete(); } /** - * Duplicate a pages content. We need to make sure all - * the fields attached to that page go with it + * Duplicate a pages content. We need to make sure all the fields attached + * to that page go with it * - * @return DataObject a Clone of this node + * @return DataObject */ public function duplicate() { $clonedNode = parent::duplicate(); @@ -94,15 +96,15 @@ class EditableMultipleOptionField extends EditableFormField { $newField->write(); } } + return $clonedNode; } /** - * On before saving this object we need to go through and keep - * an eye on all our option fields that are related to this - * field in the form + * On before saving this object we need to go through and keep an eye on + * all our option fields that are related to this field in the form * - * @param Array Data + * @param ArrayData */ public function populateFromPostData($data) { parent::populateFromPostData($data); @@ -122,8 +124,8 @@ class EditableMultipleOptionField extends EditableFormField { } /** - * Return whether or not this field has addable options - * such as a dropdown field or radio set + * Return whether or not this field has addable options such as a + * {@link EditableDropdownField} or {@link EditableRadioField} * * @return bool */ @@ -132,8 +134,7 @@ class EditableMultipleOptionField extends EditableFormField { } /** - * Return the form field for this object in the front - * end form view + * Return the form field for this object in the front end form view * * @return FormField */ diff --git a/code/editor/EditableOption.php b/code/model/formfields/EditableOption.php similarity index 100% rename from code/editor/EditableOption.php rename to code/model/formfields/EditableOption.php diff --git a/code/editor/EditableRadioField.php b/code/model/formfields/EditableRadioField.php similarity index 99% rename from code/editor/EditableRadioField.php rename to code/model/formfields/EditableRadioField.php index 43970c5..317c301 100755 --- a/code/editor/EditableRadioField.php +++ b/code/model/formfields/EditableRadioField.php @@ -13,7 +13,6 @@ class EditableRadioField extends EditableMultipleOptionField { static $plural_name = 'Radio fields'; - function getFormField() { $optionSet = $this->Options(); $options = array(); diff --git a/code/editor/EditableTextField.php b/code/model/formfields/EditableTextField.php similarity index 63% rename from code/editor/EditableTextField.php rename to code/model/formfields/EditableTextField.php index 849fa89..57c86f0 100755 --- a/code/editor/EditableTextField.php +++ b/code/model/formfields/EditableTextField.php @@ -16,22 +16,21 @@ class EditableTextField extends EditableFormField { function getFieldConfiguration() { $fields = parent::getFieldConfiguration(); - // eventually replace hard-coded "Fields"? - $baseName = "Fields[$this->ID]"; + $min = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : ''; + $max = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : ''; - $minLength = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : ''; - $maxLength = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : ''; $rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1'; $extraFields = new FieldSet( new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'), - new TextField($baseName . "[CustomSettings][MinLength]", "", $minLength), - new TextField($baseName . "[CustomSettings][MaxLength]", " - ", $maxLength) + new TextField($this->getSettingName('MinLength'), "", $min), + new TextField($this->getSettingName('MaxLength'), " - ", $max) ), - new TextField($baseName . "[CustomSettings][Rows]", _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows) + new TextField($this->getSettingName('Rows'), _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows) ); $fields->merge($extraFields); + return $fields; } @@ -53,12 +52,16 @@ class EditableTextField extends EditableFormField { * PHP. * * @see http://docs.jquery.com/Plugins/Validation/Methods - * @return Array + * @return array */ public function getValidation() { $options = array(); - if($this->getSetting('MinLength')) $options['minlength'] = $this->getSetting('MinLength'); - if($this->getSetting('MaxLength')) $options['maxlength'] = $this->getSetting('MaxLength'); + + if($this->getSetting('MinLength')) + $options['minlength'] = $this->getSetting('MinLength'); + + if($this->getSetting('MaxLength')) + $options['maxlength'] = $this->getSetting('MaxLength'); return $options; } diff --git a/code/model/submissions/SubmittedFileField.php b/code/model/submissions/SubmittedFileField.php new file mode 100755 index 0000000..14c4043 --- /dev/null +++ b/code/model/submissions/SubmittedFileField.php @@ -0,0 +1,44 @@ + "File" + ); + + /** + * Return the value of this field for inclusion into things such as reports + * + * @return string + */ + function getFormattedValue() { + $link = $this->getLink(); + $title = _t('SubmittedFileField.DOWNLOADFILE', 'Download File'); + + if(!$link) { + return sprintf('%s', $link, $title); + } + + return false; + } + + /** + * Return the link for the file attached to this submitted form field + * + * @return string + */ + function getLink() { + if($file = $this->UploadedFile()) { + if(trim($file->getFilename(), '/') != trim(ASSETS_DIR,'/')) { + return $this->UploadedFile()->URL; + } + } + } +} \ No newline at end of file diff --git a/code/submissions/SubmittedForm.php b/code/model/submissions/SubmittedForm.php similarity index 100% rename from code/submissions/SubmittedForm.php rename to code/model/submissions/SubmittedForm.php diff --git a/code/submissions/SubmittedFormField.php b/code/model/submissions/SubmittedFormField.php similarity index 100% rename from code/submissions/SubmittedFormField.php rename to code/model/submissions/SubmittedFormField.php diff --git a/code/submissions/SubmittedFileField.php b/code/submissions/SubmittedFileField.php deleted file mode 100755 index dbec4e2..0000000 --- a/code/submissions/SubmittedFileField.php +++ /dev/null @@ -1,36 +0,0 @@ - "File" - ); - - /** - * Return the Value of this Field - * - * @return String - */ - function getFormattedValue() { - $link = $this->getLink(); - return (!empty($link)) ? ''. _t('SubmittedFileField.DOWNLOADFILE', 'Download File') .'' : ''; - } - - /** - * Return the Link object for this field - * - * @return String - */ - function getLink() { - if ($this->UploadedFile()){ - // Test if there is a filename, not only a filepath to the assets folder - return ($this->UploadedFile()->getFilename() != ASSETS_DIR.'/') ? $this->UploadedFile()->URL : ''; - } - return ''; - } -} \ No newline at end of file diff --git a/code/migration/UserFormsVersionedTask.php b/code/tasks/UserFormsVersionedTask.php similarity index 100% rename from code/migration/UserFormsVersionedTask.php rename to code/tasks/UserFormsVersionedTask.php diff --git a/tests/EditableFormFieldTest.php b/tests/EditableFormFieldTest.php index 8cdf9df..27e0000 100644 --- a/tests/EditableFormFieldTest.php +++ b/tests/EditableFormFieldTest.php @@ -241,7 +241,7 @@ class EditableFormFieldTest extends FunctionalTest { $this->assertEquals($text->getFieldName(), "Fields[". $text->ID ."]"); $this->assertEquals($text->getFieldName('Setting'), "Fields[". $text->ID ."][Setting]"); - $this->assertEquals($text->getSettingFieldName('Foo'), "Fields[". $text->ID ."][CustomSettings][Foo]"); + $this->assertEquals($text->getSettingName('Foo'), "Fields[". $text->ID ."][CustomSettings][Foo]"); } function testMultipleOptionDuplication() {