Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

NEW Filter submissions by created date

  • Loading branch information...
commit c4c547321ce30fa9d4162def10e81004fcdc0b33 1 parent 8e252c8
@wilr wilr authored
Showing with 36 additions and 6 deletions.
  1. +36 −6 code/UserFormsGridFieldFilterHeader.php
View
42 code/UserFormsGridFieldFilterHeader.php
@@ -17,7 +17,9 @@ public function handleAction(GridField $gridField, $actionName, $arguments, $dat
if($actionName === 'filter') {
$gridField->State->UserFormsGridField = array(
'filter' => isset($data['FieldNameFilter']) ? $data['FieldNameFilter'] : null,
- 'value' => isset($data['FieldValue']) ? $data['FieldValue'] : null
+ 'value' => isset($data['FieldValue']) ? $data['FieldValue'] : null,
+ 'start' => isset($data['StartFilter']) ? $data['StartFilter'] : null,
+ 'end' => isset($data['EndFilter']) ? $data['EndFilter'] : null
);
}
}
@@ -30,8 +32,6 @@ public function getHTMLFragments($gridField) {
$selectedField = $state->filter;
$selectedValue = $state->value;
- // get the state of the grid field and populate the default values.
-
// retrieve a list of all the available form fields that have been
// submitted in this form.
$formFields = SubmittedFormField::get()
@@ -65,8 +65,26 @@ public function getHTMLFragments($gridField) {
_t('UserFormsGridFieldFilterHeader.WHEREVALUEIS', 'where value is..'
));
- $fields->push($columnField);
- $fields->push($valueField);
+ $fields->push(new FieldGroup(new CompositeField(
+ $columnField,
+ $valueField
+ )));
+
+ $fields->push(new FieldGroup(new CompositeField(
+ $start = new DateField('StartFilter', 'From'),
+ $end = new DateField('EndFilter', 'Till')
+ )));
+
+ foreach(array($start, $end) as $date) {
+ $date->setConfig('showcalendar', true);
+ $date->setConfig('dateformat', 'y-mm-dd');
+ $date->setConfig('datavalueformat', 'y-mm-dd');
+ $date->addExtraClass('no-change-track');
+ }
+
+ $end->setValue($state->end);
+ $start->setValue($state->start);
+
$fields->push($actions = new FieldGroup(
GridField_FormAction::create($gridField, 'filter', false, 'filter', null)
@@ -97,7 +115,7 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList) {
$state = $gridField->State;
if($filter = $state->UserFormsGridField->toArray()) {
- if(isset($filter['filter']) && isset($filter['value'])) {
+ if(isset($filter['filter']) && $filter['filter'] && isset($filter['value']) && $filter['value']) {
$dataList = $dataList->where(sprintf("
SELECT COUNT(*) FROM SubmittedFormField
WHERE (
@@ -110,6 +128,18 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList) {
Convert::raw2sql($filter['value'])
));
}
+
+ if(isset($filter['start']) && $filter['start']) {
+ $dataList = $dataList->filter(array(
+ 'Created:GreaterThan' => $filter['start']
+ ));
+ }
+
+ if(isset($filter['end']) && $filter['end']) {
+ $dataList = $dataList->filter(array(
+ 'Created:LessThan' => $filter['end']
+ ));
+ }
}
return $dataList;
Please sign in to comment.
Something went wrong with that request. Please try again.