mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
MINOR: removed all filter form calls as filter form has not and will not work
This commit is contained in:
parent
df26613d8b
commit
6e3f9668c0
@ -89,93 +89,7 @@ class UserDefinedForm extends Page {
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the Submissions page form
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
public function FilterForm() {
|
||||
|
||||
$fields = new FieldSet();
|
||||
$required = array();
|
||||
|
||||
foreach($this->Fields() as $field) {
|
||||
$fields->push($field->getFilterField());
|
||||
}
|
||||
|
||||
$actions = new FieldSet(
|
||||
new FormAction("filter", _t('UserDefinedForm.SUBMIT', 'Submit'))
|
||||
);
|
||||
|
||||
return new Form( $this, "Form", $fields, $actions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the submissions by the given criteria
|
||||
*
|
||||
* @param Array the filter data
|
||||
* @param Form the form used
|
||||
* @return Array|String
|
||||
*/
|
||||
public function filter( $data, $form ) {
|
||||
|
||||
$filterClause = array( "`SubmittedForm`.`ParentID` = '{$this->ID}'" );
|
||||
$keywords = preg_split( '/\s+/', $data['FilterKeyword'] );
|
||||
$keywordClauses = array();
|
||||
|
||||
// combine all keywords into one clause
|
||||
foreach($keywords as $keyword) {
|
||||
|
||||
// escape %, \ and _ in the keyword. These have special meanings in a LIKE string
|
||||
$keyword = preg_replace( '/([%_])/', '\\\\1', addslashes( $keyword ) );
|
||||
$keywordClauses[] = "`Value` LIKE '%$keyword%'";
|
||||
}
|
||||
|
||||
if(count($keywordClauses) > 0) {
|
||||
$filterClause[] = "( " . implode( ' OR ', $keywordClauses ) . ")";
|
||||
$searchQuery = 'keywords \'' . implode( "', '", $keywords ) . '\' ';
|
||||
}
|
||||
|
||||
$fromDate = addslashes( $data['FilterFromDate'] );
|
||||
$toDate = addslashes( $data['FilterToDate'] );
|
||||
|
||||
// use date objects to convert date to value expected by database
|
||||
if( ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $fromDate, $parts) )
|
||||
$fromDate = $parts[3] . '-' . $parts[2] . '-' . $parts[1];
|
||||
|
||||
if( ereg('^([0-9]+)/([0-9]+)/([0-9]+)$', $toDate, $parts) )
|
||||
$toDate = $parts[3] . '-' . $parts[2] . '-' . $parts[1];
|
||||
|
||||
if( $fromDate ) {
|
||||
$filterClause[] = "`SubmittedForm`.`Created` >= '$fromDate'";
|
||||
$searchQuery .= 'from ' . $fromDate . ' ';
|
||||
}
|
||||
|
||||
if( $toDate ) {
|
||||
$filterClause[] = "`SubmittedForm`.`Created` <= '$toDate'";
|
||||
$searchQuery .= 'to ' . $toDate;
|
||||
}
|
||||
|
||||
$submittedValues = DataObject::get( 'SubmittedFormField', implode( ' AND ', $filterClause ), "", "INNER JOIN `SubmittedForm` ON `SubmittedFormField`.`ParentID`=`SubmittedForm`.`ID`" );
|
||||
|
||||
if( !$submittedValues || $submittedValues->Count() == 0 )
|
||||
return _t('UserDefinedForm.NORESULTS', 'No matching results found');
|
||||
|
||||
$submissions = $submittedValues->groupWithParents( 'ParentID', 'SubmittedForm' );
|
||||
|
||||
if( !$submissions || $submissions->Count() == 0 )
|
||||
return _t('UserDefinedForm.NORESULTS', 'No matching results found');
|
||||
|
||||
return $submissions->customise(
|
||||
array( 'Submissions' => $submissions )
|
||||
)->renderWith( 'SubmittedFormReportField_Reports' );
|
||||
}
|
||||
|
||||
function ReportFilterForm() {
|
||||
return new SubmittedFormReportField_FilterForm( $this, 'ReportFilterForm' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on before delete remove all the fields from the database
|
||||
*/
|
||||
@ -263,11 +177,7 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
'Form' => $this->Form
|
||||
);
|
||||
}
|
||||
|
||||
function ReportFilterForm() {
|
||||
return new SubmittedFormReportField_FilterForm( $this, 'ReportFilterForm' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* User Defined Form. Feature of the user defined form is if you want the
|
||||
* form to appear in a custom location on the page you can use $UserDefinedForm
|
||||
@ -629,28 +539,4 @@ class UserDefinedForm_SubmittedFormEmail extends Email {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Email that gets sent to submitter when a submission is made.
|
||||
*
|
||||
* @package userforms
|
||||
*/
|
||||
class UserDefinedForm_SubmittedFormEmailToSubmitter extends Email {
|
||||
protected $ss_template = "SubmittedFormEmailToSubmitter";
|
||||
protected $from = '$Sender.Email';
|
||||
protected $to = '$Recipient.Email';
|
||||
protected $subject = 'Submission of form';
|
||||
protected $data;
|
||||
|
||||
function __construct($values = null) {
|
||||
$this->subject = _t('UserDefinedForm_SubmittedFormEmail.EMAILSUBJECT', 'Submission of form');
|
||||
|
||||
parent::__construct();
|
||||
$this->data = $values;
|
||||
}
|
||||
|
||||
function Data() {
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -11,23 +11,17 @@ class EditableCheckbox extends EditableFormField {
|
||||
|
||||
static $plural_name = 'Checkboxes';
|
||||
|
||||
function ExtraOptions() {
|
||||
|
||||
public function ExtraOptions() {
|
||||
$fields = new FieldSet(
|
||||
new CheckboxField("Fields[$this->ID][CustomSettings][Default]", _t('EditableFormField.CHECKEDBYDEFAULT', 'Checked by Default?'), $this->getSetting('Default'))
|
||||
);
|
||||
$fields->merge(parent::ExtraOptions());
|
||||
return $fields;
|
||||
}
|
||||
function getFormField() {
|
||||
return new CheckboxField( $this->Name, $this->Title, $this->getSetting('Default'));
|
||||
}
|
||||
|
||||
function getFilterField() {
|
||||
return new OptionsetField( $this->Name, $this->Title,
|
||||
array( '-1' => '('._t('EditableCheckbox.ANY', 'Any').')',
|
||||
'on' => _t('EditableCheckbox.SELECTED', 'Selected'),
|
||||
'0' => _t('EditableCheckbox.NOTSELECTED', 'Not selected') )
|
||||
);
|
||||
public function getFormField() {
|
||||
return new CheckboxField( $this->Name, $this->Title, $this->getSetting('Default'));
|
||||
}
|
||||
}
|
||||
?>
|
@ -11,50 +11,32 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField {
|
||||
static $singular_name = "Checkbox group";
|
||||
|
||||
static $plural_name = "Checkbox groups";
|
||||
|
||||
function DefaultOption() {
|
||||
$defaultOption = 0;
|
||||
|
||||
foreach( $this->Options() as $option ) {
|
||||
if( $option->getField('Default') )
|
||||
return $defaultOption;
|
||||
else
|
||||
$defaultOption++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
function createField($asFilter = false) {
|
||||
function getFormField() {
|
||||
$optionSet = $this->Options();
|
||||
$options = array();
|
||||
|
||||
$optionMap = ($optionSet) ? $optionSet->map('ID', 'Title') : array();
|
||||
$optionMap = ($optionSet) ? $optionSet->map('Title', 'Title') : array();
|
||||
|
||||
return new CheckboxSetField($this->Name, $this->Title, $optionMap);
|
||||
}
|
||||
|
||||
function getValueFromData($data) {
|
||||
if(empty($data[$this->Name])) {
|
||||
return "";
|
||||
}
|
||||
|
||||
$result = '';
|
||||
$entries = $data[$this->Name];
|
||||
|
||||
if(!is_array($data[$this->Name])) {
|
||||
$entries = array($data[$this->Name]);
|
||||
}
|
||||
|
||||
$selectedOptions = DataObject::get('EditableOption', "ParentID={$this->ID} AND ID IN (" . implode(',', $entries) . ")");
|
||||
foreach($selectedOptions as $selected) {
|
||||
if(!$result) {
|
||||
$result = $selected->Title;
|
||||
} else {
|
||||
$result .= "," . $selected->Title;
|
||||
if($entries) {
|
||||
foreach($entries as $selected => $value) {
|
||||
if(!$result) {
|
||||
$result = $value;
|
||||
} else {
|
||||
$result .= ", " . $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -12,15 +12,6 @@ class EditableDateField extends EditableFormField {
|
||||
|
||||
static $plural_name = 'Date fields';
|
||||
|
||||
function DefaultField() {
|
||||
$dmyField = new CalendarDateField( "Fields[{$this->ID}][Default]", "", $this->getField('Default') );
|
||||
|
||||
if( $this->readonly )
|
||||
$dmyField = $dmyField->performReadonlyTransformation();
|
||||
|
||||
return $dmyField;
|
||||
}
|
||||
|
||||
function populateFromPostData($data) {
|
||||
$fieldPrefix = 'Default-';
|
||||
|
||||
|
@ -13,21 +13,15 @@ class EditableDropdown extends EditableMultipleOptionField {
|
||||
static $plural_name = 'Dropdowns';
|
||||
|
||||
|
||||
function createField($asFilter = false) {
|
||||
function getFormField($asFilter = false) {
|
||||
$optionSet = $this->Options();
|
||||
$options = array();
|
||||
|
||||
if($asFilter) {
|
||||
$options['-1'] = "(Any)";
|
||||
if($optionSet) {
|
||||
foreach( $optionSet as $option ) {
|
||||
$options[$option->Title] = $option->Title;
|
||||
}
|
||||
}
|
||||
$defaultOption = '-1';
|
||||
|
||||
foreach( $optionSet as $option ) {
|
||||
$options[$option->Title] = $option->Title;
|
||||
if($option->getField('Default') && !$asFilter) $defaultOption = $option->Title;
|
||||
}
|
||||
|
||||
return new DropdownField( $this->Name, $this->Title, $options, $defaultOption );
|
||||
return new DropdownField( $this->Name, $this->Title, $options);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,10 +16,6 @@ class EditableEmailField extends EditableFormField {
|
||||
return new EmailField($this->Name, $this->Title);
|
||||
}
|
||||
|
||||
function getFilterField() {
|
||||
return $this->createField(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the validation information related to this field. This is
|
||||
* interrupted as a JSON object for validate plugin and used in the
|
||||
|
@ -315,24 +315,6 @@ class EditableFormField extends DataObject {
|
||||
user_error("Please implement a getFormField() on your EditableFormClass ". $this->ClassName, E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the form field to appear on the filter form
|
||||
* in the cms view
|
||||
*
|
||||
* @return FormField
|
||||
*/
|
||||
public function getFilterField() {
|
||||
user_error("Please implement a getFilterField() on your EditableFormClass ". $this->ClassName, E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an evaluation appropriate for a filter clause
|
||||
* @todo: escape the string
|
||||
*/
|
||||
function filterClause( $value ) {
|
||||
return ($value == '-1') ? "" : "`{$this->name}` = '$value'";
|
||||
}
|
||||
|
||||
function showInReports() {
|
||||
return true;
|
||||
}
|
||||
|
@ -10,16 +10,6 @@ class EditableMemberListField extends EditableFormField {
|
||||
|
||||
static $plural_name = 'Member list fields';
|
||||
|
||||
public function DefaultField() {
|
||||
|
||||
$groups = DataObject::get('Group');
|
||||
|
||||
foreach( $groups as $group )
|
||||
$groupArray[$group->ID] = $group->Title;
|
||||
|
||||
return new DropdownField( "Fields[{$this->ID}][CustomSetting][GroupID]", 'Group', $groupArray, $this->getSetting('GroupID'));
|
||||
}
|
||||
|
||||
function getFormField() {
|
||||
return ($this->getSetting($this->GroupID)) ? new DropdownField( $this->Name, $this->Title, Member::mapInGroups($this->getSetting($this->GroupID))) : false;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* one of these directly, rather you would instantiate a subclass
|
||||
* such as EditableDropdownField
|
||||
*
|
||||
* @todo Make it would make more sense to have dropdownfield and
|
||||
* @todo Maybe it would make more sense to have dropdownfield and
|
||||
* checkboxset just transformations on this class
|
||||
*
|
||||
* @package userforms
|
||||
@ -117,44 +117,7 @@ class EditableMultipleOptionField extends EditableFormField {
|
||||
* @return FormField
|
||||
*/
|
||||
public function getFormField() {
|
||||
return $this->createField();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the form field as a field suitable for insertion
|
||||
* into the filter form
|
||||
*
|
||||
* @return FormField
|
||||
*/
|
||||
public function getFilterField() {
|
||||
return $this->createField(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the correct form field for this object. Note this
|
||||
* does a transformation between being a field on the form and
|
||||
* a field in the filter search form
|
||||
*
|
||||
* This should be extended on your subclass
|
||||
*
|
||||
* @param bool - Filter Field?
|
||||
* @return UserError - You should implement it on your subclass
|
||||
*/
|
||||
public function createField($filter = false) {
|
||||
return user_error('Please implement createField() on '. $this->class, E_USER_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checkbox to show if this option is the default option selected
|
||||
* in the form
|
||||
*
|
||||
* @return HTML
|
||||
*/
|
||||
public function DefaultSelect() {
|
||||
$disabled = ($this->readonly) ? " disabled=\"disabled\"" : '';
|
||||
$default = ($this->Parent()->getField('Default') == $this->ID) ? " checked=\"checked\"" : '';
|
||||
|
||||
return "<input class=\"radio\" type=\"radio\" name=\"Fields[{$this->ParentID}][Default]\" value=\"{$this->ID}\"".$disabled.$default." />";
|
||||
return user_error('Please implement getFormField() on '. $this->class, E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
?>
|
@ -12,36 +12,18 @@ class EditableRadioField extends EditableMultipleOptionField {
|
||||
|
||||
static $plural_name = 'Radio fields';
|
||||
|
||||
function DefaultOption() {
|
||||
$defaultOption = 0;
|
||||
|
||||
foreach( $this->Options() as $option ) {
|
||||
if( $option->getField('Default') )
|
||||
return $defaultOption;
|
||||
else
|
||||
$defaultOption++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
function createField( $asFilter = false ) {
|
||||
|
||||
function getFormField() {
|
||||
$optionSet = $this->Options();
|
||||
$options = array();
|
||||
$defaultOption = '';
|
||||
|
||||
if( $asFilter )
|
||||
$options['-1'] = '(Any)';
|
||||
|
||||
// $defaultOption = '-1';
|
||||
|
||||
foreach( $optionSet as $option ) {
|
||||
$options[$option->Title] = $option->Title;
|
||||
if( $option->getField('Default') && !$asFilter ) $defaultOption = $option->Title;
|
||||
if($optionSet) {
|
||||
foreach( $optionSet as $option ) {
|
||||
$options[$option->Title] = $option->Title;
|
||||
}
|
||||
}
|
||||
|
||||
// return radiofields
|
||||
return new OptionsetField($this->Name, $this->Title, $options, $defaultOption);
|
||||
return new OptionsetField($this->Name, $this->Title, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -7,92 +7,40 @@
|
||||
* @package userforms
|
||||
*/
|
||||
class EditableTextField extends EditableFormField {
|
||||
|
||||
public static $db = array(
|
||||
"Size" => "Int",
|
||||
"MinLength" => "Int",
|
||||
"MaxLength" => "Int",
|
||||
"Rows" => "Int"
|
||||
);
|
||||
|
||||
public static $size = 32;
|
||||
|
||||
public static $min_length = 1;
|
||||
|
||||
public static $max_length = 32;
|
||||
|
||||
public static $rows = 1;
|
||||
|
||||
static $singular_name = 'Text field';
|
||||
|
||||
static $plural_name = 'Text fields';
|
||||
|
||||
function __construct( $record = null, $isSingleton = false ) {
|
||||
$this->Size = self::$size;
|
||||
$this->MinLength = self::$min_length;
|
||||
$this->MaxLength = self::$max_length;
|
||||
$this->Rows = self::$rows;
|
||||
parent::__construct( $record, $isSingleton );
|
||||
}
|
||||
|
||||
function ExtraOptions() {
|
||||
|
||||
// eventually replace hard-coded "Fields"?
|
||||
$baseName = "Fields[$this->ID]";
|
||||
|
||||
$size = ($this->getSetting('Size')) ? $this->getSetting('Size') : '32';
|
||||
$minLength = ($this->getSetting('MinLength')) ? $this->getSetting('MinLength') : '0';
|
||||
$maxLength = ($this->getSetting('MaxLength')) ? $this->getSetting('MaxLength') : '32';
|
||||
$rows = ($this->getSetting('Rows')) ? $this->getSetting('Rows') : '1';
|
||||
|
||||
$extraFields = new FieldSet(
|
||||
new TextField($baseName . "[Size]", _t('EditableTextField.TEXTBOXLENGTH', 'Length of text box'), (string)$this->Size),
|
||||
new TextField($baseName . "[CustomSettings][Size]", _t('EditableTextField.TEXTBOXLENGTH', 'Length of text box'), $size),
|
||||
new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'),
|
||||
new TextField($baseName . "[MinLength]", "", (string)$this->MinLength),
|
||||
new TextField($baseName . "[MaxLength]", " - ", (string)$this->MaxLength)
|
||||
new TextField($baseName . "[CustomSettings][MinLength]", "", $minLength),
|
||||
new TextField($baseName . "[CustomSettings][MaxLength]", " - ", $maxLength)
|
||||
),
|
||||
new TextField($baseName . "[Rows]", _t('EditableTextField.NUMBERROWS', 'Number of rows'), (string)$this->Rows)
|
||||
new TextField($baseName . "[CustomSettings][Rows]", _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows)
|
||||
);
|
||||
|
||||
foreach( parent::ExtraOptions() as $extraField )
|
||||
$extraFields->push( $extraField );
|
||||
|
||||
if( $this->readonly )
|
||||
$extraFields = $extraFields->makeReadonly();
|
||||
|
||||
$extraFields->merge(parent::ExtraOptions());
|
||||
return $extraFields;
|
||||
}
|
||||
|
||||
function populateFromPostData( $data ) {
|
||||
|
||||
$this->Size = !empty( $data['Size'] ) ? $data['Size'] : self::$size;
|
||||
$this->MinLength = !empty( $data['MinLength'] ) ? $data['MinLength'] : self::$min_length;
|
||||
$this->MaxLength = !empty( $data['MaxLength'] ) ? $data['MaxLength'] : self::$max_length;
|
||||
$this->Rows = !empty( $data['Rows'] ) ? $data['Rows'] : self::$rows;
|
||||
parent::populateFromPostData( $data );
|
||||
}
|
||||
|
||||
function getFormField() {
|
||||
return $this->createField();
|
||||
}
|
||||
|
||||
function getFilterField() {
|
||||
return $this->createField( true );
|
||||
}
|
||||
|
||||
|
||||
function createField( $asFilter = false ) {
|
||||
if( $this->Rows == 1 )
|
||||
return new TextField( $this->Name, $this->Title, ( $asFilter ) ? "" : $this->getField('Default'), $this->MaxLength);
|
||||
else
|
||||
return new TextareaField( $this->Name, $this->Title, $this->Rows, $this->MaxLength, ( $asFilter ) ? "" : $this->getField('Default') );
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the default fields.
|
||||
*/
|
||||
function DefaultField() {
|
||||
$disabled = ($this->readonly) ? " disabled=\"disabled\"" : '';
|
||||
|
||||
if($this->Rows == 1){
|
||||
return '<div class="field text"><label class="left">'._t('EditableTextField.DEFAULTTEXT', 'Default Text').' </label> <input class="defaultText" name="Fields['.Convert::raw2att( $this->ID ).'][Default]" type="text" value="'.Convert::raw2att( $this->getField('Default') ).'"'.$disabled.' /></div>';
|
||||
}else{
|
||||
return '<div class="field text"><label class="left">'._t('EditableTextField.DEFAULTTEXT', 'Default Text').' </label> <textarea class="defaultText" name="Fields['.Convert::raw2att( $this->ID ).'][Default]"'.$disabled.'>'.Convert::raw2att( $this->getField('Default') ).'</textarea></div>';
|
||||
if($this->getSetting('Rows') && $this->getSetting('Rows') <= 1) {
|
||||
return new TextField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
|
||||
}
|
||||
else {
|
||||
return new TextareaField($this->Name, $this->Title, $this->getSetting('Rows'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,8 +54,8 @@ class EditableTextField extends EditableFormField {
|
||||
*/
|
||||
public function getValidation() {
|
||||
$options = array();
|
||||
if($this->MinLength) $options['minlength'] = $this->MinLength;
|
||||
if($this->MaxLength) $options['maxlength'] = $this->MinLength;
|
||||
if($this->getSetting('MinLength')) $options['minlength'] = $this->getSetting('MinLength');
|
||||
if($this->getSetting('MaxLength')) $options['maxlength'] = $this->getSetting('MaxLength');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
<li>
|
||||
<img class="handle" src="sapphire/images/drag.gif" alt="<% _t('DRAG', 'Drag to rearrange order of options') %>" />
|
||||
$DefaultSelect
|
||||
<input type="text" name="$Name.Attr[Title]" value="$Title" />
|
||||
<input type="hidden" class="sortOptionHidden hidden" name="$Name[Sort]" value="$Sort" />
|
||||
|
||||
|
@ -1,6 +1,3 @@
|
||||
<div class="reportfilter">
|
||||
$FilterForm
|
||||
</div>
|
||||
<div class="reports" id="FormSubmissions">
|
||||
|
||||
<% if Submissions %>
|
||||
|
Loading…
Reference in New Issue
Block a user