diff --git a/code/UserDefinedForm.php b/code/UserDefinedForm.php index 56bcf11..9847406 100755 --- a/code/UserDefinedForm.php +++ b/code/UserDefinedForm.php @@ -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; - } -} - ?> diff --git a/code/editor/EditableCheckbox.php b/code/editor/EditableCheckbox.php index 1526b2d..11d1c32 100755 --- a/code/editor/EditableCheckbox.php +++ b/code/editor/EditableCheckbox.php @@ -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')); } } ?> \ No newline at end of file diff --git a/code/editor/EditableCheckboxGroupField.php b/code/editor/EditableCheckboxGroupField.php index 2fa851f..cc66aab 100755 --- a/code/editor/EditableCheckboxGroupField.php +++ b/code/editor/EditableCheckboxGroupField.php @@ -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; } } diff --git a/code/editor/EditableDateField.php b/code/editor/EditableDateField.php index 4e9e8af..cab9a53 100755 --- a/code/editor/EditableDateField.php +++ b/code/editor/EditableDateField.php @@ -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-'; diff --git a/code/editor/EditableDropdown.php b/code/editor/EditableDropdown.php index 0f25f2b..efe03d2 100755 --- a/code/editor/EditableDropdown.php +++ b/code/editor/EditableDropdown.php @@ -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); } } diff --git a/code/editor/EditableEmailField.php b/code/editor/EditableEmailField.php index 427ec3e..5bd3fca 100755 --- a/code/editor/EditableEmailField.php +++ b/code/editor/EditableEmailField.php @@ -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 diff --git a/code/editor/EditableFormField.php b/code/editor/EditableFormField.php index 8e189eb..aa4a2df 100755 --- a/code/editor/EditableFormField.php +++ b/code/editor/EditableFormField.php @@ -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; } diff --git a/code/editor/EditableMemberListField.php b/code/editor/EditableMemberListField.php index e6c4f88..0576055 100644 --- a/code/editor/EditableMemberListField.php +++ b/code/editor/EditableMemberListField.php @@ -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; } diff --git a/code/editor/EditableMultipleOptionField.php b/code/editor/EditableMultipleOptionField.php index 11ef976..f432577 100644 --- a/code/editor/EditableMultipleOptionField.php +++ b/code/editor/EditableMultipleOptionField.php @@ -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 "ParentID}][Default]\" value=\"{$this->ID}\"".$disabled.$default." />"; + return user_error('Please implement getFormField() on '. $this->class, E_USER_ERROR); } } ?> \ No newline at end of file diff --git a/code/editor/EditableRadioField.php b/code/editor/EditableRadioField.php index bc26925..1f14fae 100755 --- a/code/editor/EditableRadioField.php +++ b/code/editor/EditableRadioField.php @@ -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); } } ?> diff --git a/code/editor/EditableTextField.php b/code/editor/EditableTextField.php index 0ac4f82..e1f4909 100755 --- a/code/editor/EditableTextField.php +++ b/code/editor/EditableTextField.php @@ -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 '