mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-06-29 07:59:24 +02:00
MINOR: clean up of project. MINOR: removed versioned task. Out of date for usage.
This commit is contained in:
parent
c957af1c29
commit
2c9e68a928
|
@ -1,217 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Migration Task for older versions of userforms to the newer version of userforms.
|
||||
* This will handle the datamodel changes of the form page as well as the form fields.
|
||||
* Nothing is done with Submissions as the datamodel for that has not changed
|
||||
*
|
||||
* This has been designed to port 0.1 userforms to 0.2 userforms as this had major
|
||||
* api changes
|
||||
*
|
||||
* You can import 1 form at a time by entering the formID in the URL
|
||||
* - /dev/tasks/UserFormsMigrationTask/?formID=12
|
||||
*
|
||||
* You can also run this without writing anything to the database - by doing a dryrun
|
||||
* - /dev/tasks/UserFormsMigrationTask/?dryRun=1
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class UserFormsMigrationTask extends MigrationTask {
|
||||
|
||||
protected $title = "UserForms Database Migration";
|
||||
|
||||
protected $description = "Upgrades your current forms to the latest structure";
|
||||
|
||||
/**
|
||||
* Run the update.
|
||||
*
|
||||
* Things it needs to do:
|
||||
* - Port the Settings on Individual Fields
|
||||
* - Create the new class for multiple options
|
||||
* - Port Email To to New Email_Recipients
|
||||
*
|
||||
* @param HTTPRequest
|
||||
*/
|
||||
function run($request) {
|
||||
// load the forms
|
||||
$forms = DataObject::get('UserDefinedForm');
|
||||
if(!$forms) $forms = new DataObjectSet();
|
||||
|
||||
// set debugging / useful test
|
||||
$this->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.<br />";
|
||||
}
|
||||
|
||||
// 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<br />";
|
||||
|
||||
foreach($forms as $form) {
|
||||
echo " -- Updating $form->URLSegment <br />";
|
||||
// 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<br />";
|
||||
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 "<h3>Migration Complete</h3>";
|
||||
}
|
||||
/**
|
||||
* 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 '<strong>!! 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<br />";
|
||||
}
|
||||
}
|
|
@ -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
|
||||
*/
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
/**
|
||||
* EditableCheckbox
|
||||
*
|
||||
* A user modifiable checkbox on a UserDefinedForm
|
||||
*
|
||||
* @package userforms
|
||||
|
@ -15,6 +16,7 @@ class EditableCheckbox extends EditableFormField {
|
|||
public function getFieldConfiguration() {
|
||||
$options = parent::getFieldConfiguration();
|
||||
$options->push(new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default')));
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
|
@ -16,8 +16,7 @@ class EditableDropdown extends EditableMultipleOptionField {
|
|||
/**
|
||||
* @return DropdownField
|
||||
*/
|
||||
function getFormField() {
|
||||
|
||||
function getFormField() {
|
||||
$optionSet = $this->Options();
|
||||
$options = array();
|
||||
|
|
@ -1,33 +1,24 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Allows a user to add a field that can be used to upload a file
|
||||
* Allows a user to add a field that can be used to upload a file.
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableFileField extends EditableFormField {
|
||||
|
||||
/**
|
||||
* @see Upload->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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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')
|
||||
)
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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'));
|
||||
}
|
||||
}
|
|
@ -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() : "";
|
||||
}
|
||||
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Base class for multiple option fields such as dropdowns and
|
||||
* radio sets. Implemented as a class but you would not create
|
||||
* one of these directly, rather you would instantiate a subclass
|
||||
* such as {@link EditableDropdownField}
|
||||
* Base class for multiple option fields such as {@link EditableDropdownField}
|
||||
* and radio sets.
|
||||
*
|
||||
* Implemented as a class but should be viewed as abstract, you should
|
||||
* instantiate a subclass such as {@link EditableDropdownField}
|
||||
*
|
||||
* @see EditableCheckboxGroupField
|
||||
* @see EditableDropdownField
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class EditableMultipleOptionField extends EditableFormField {
|
||||
|
||||
static $db = array();
|
||||
|
||||
static $has_one = array();
|
||||
|
||||
static $has_many = array(
|
||||
"Options" => "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
|
||||
*/
|
|
@ -13,7 +13,6 @@ class EditableRadioField extends EditableMultipleOptionField {
|
|||
|
||||
static $plural_name = 'Radio fields';
|
||||
|
||||
|
||||
function getFormField() {
|
||||
$optionSet = $this->Options();
|
||||
$options = array();
|
|
@ -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;
|
||||
}
|
44
code/model/submissions/SubmittedFileField.php
Executable file
44
code/model/submissions/SubmittedFileField.php
Executable file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A file uploaded on a {@link UserDefinedForm} and attached to a single
|
||||
* {@link SubmittedForm}
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class SubmittedFileField extends SubmittedFormField {
|
||||
|
||||
static $has_one = array(
|
||||
"UploadedFile" => "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('<a href="%s">%s</a>', $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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* A file uploaded on a UserDefinedForm field
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
|
||||
class SubmittedFileField extends SubmittedFormField {
|
||||
|
||||
static $has_one = array(
|
||||
"UploadedFile" => "File"
|
||||
);
|
||||
|
||||
/**
|
||||
* Return the Value of this Field
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
function getFormattedValue() {
|
||||
$link = $this->getLink();
|
||||
return (!empty($link)) ? '<a href="'.$link.'">'. _t('SubmittedFileField.DOWNLOADFILE', 'Download File') .'</a>' : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 '';
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user