Andrew Tch преди 13 години
родител
ревизия
d4150b40cf
променени са 1 файла, в които са добавени 13 реда и са изтрити 1 реда
  1. 13 1
      Filter/AbstractDateFilter.php

+ 13 - 1
Filter/AbstractDateFilter.php

@@ -43,6 +43,12 @@ abstract class AbstractDateFilter extends Filter
                 return;
                 return;
             }
             }
 
 
+            //transform types
+            if ($this->getOption('input_type') == 'timestamp') {
+                $data['value']['start'] = $data['value']['start'] instanceof \DateTime ? $data['value']['start']->getTimestamp() : 0;
+                $data['value']['end'] = $data['value']['end'] instanceof \DateTime ? $data['value']['end']->getTimestamp() : 0;
+            }
+
             //default type for range filter
             //default type for range filter
             $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ?  DateRangeType::TYPE_BETWEEN : $data['type'];
             $data['type'] = !isset($data['type']) || !is_numeric($data['type']) ?  DateRangeType::TYPE_BETWEEN : $data['type'];
 
 
@@ -70,6 +76,11 @@ abstract class AbstractDateFilter extends Filter
             //just find an operator and apply query
             //just find an operator and apply query
             $operator = $this->getOperator($data['type']);
             $operator = $this->getOperator($data['type']);
 
 
+            //transform types
+            if ($this->getOption('input_type') == 'timestamp') {
+                $data['value'] = $data['value'] instanceof \DateTime ? $data['value']->getTimestamp() : 0;
+            }
+
             //null / not null only check for col
             //null / not null only check for col
             if (in_array($operator, array('NULL', 'NOT NULL'))) {
             if (in_array($operator, array('NULL', 'NOT NULL'))) {
                 $this->applyWhere($queryBuilder, sprintf('%s.%s IS %s ', $alias, $field, $operator));
                 $this->applyWhere($queryBuilder, sprintf('%s.%s IS %s ', $alias, $field, $operator));
@@ -132,7 +143,8 @@ abstract class AbstractDateFilter extends Filter
         return array($name, array(
         return array($name, array(
             'field_type'    => $this->getFieldType(),
             'field_type'    => $this->getFieldType(),
             'field_options' => $this->getFieldOptions(),
             'field_options' => $this->getFieldOptions(),
-            'label'         => $this->getLabel()
+            'label'         => $this->getLabel(),
+            'input_type'    => 'datetime'
         ));
         ));
     }
     }
 }
 }