0011448: support empty datetime filter
authorCornelius Weiß <c.weiss@metaways.de>
Thu, 19 Nov 2015 17:04:46 +0000 (18:04 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 20 Nov 2015 20:53:55 +0000 (21:53 +0100)
Change-Id: I68432431ef2a675fcb5b3510723b430dd6bb5f39
Reviewed-on: http://gerrit.tine20.com/customers/2400
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Sales/JsonTest.php
tine20/Calendar/Model/PeriodFilter.php
tine20/Tinebase/Model/Filter/Date.php
tine20/Tinebase/Model/Filter/DateTime.php

index 60f0e79..1c92c97 100644 (file)
@@ -256,6 +256,21 @@ class Sales_JsonTest extends TestCase
         $this->assertEquals(1, $search['totalcount']);
     }
 
+    public function testSearchEmptyDateTimeFilter()
+    {
+        // create
+        $contract = $this->_getContract();
+        $contractData = $this->_instance->saveContract($contract->toArray());
+
+        $filter = $this->_getFilter();
+        $filter[] = array('field' => 'end_date', 'operator' => 'equals', 'value' => '');
+
+        $result = $this->_instance->searchContracts($filter, $this->_getPaging());
+
+        $this->assertEquals(1, $result['totalcount']);
+        $this->assertEquals('', $result['filter'][1]['value']);
+    }
+
     /**
      * try to get a customer
      */
index c2dee6b..b7d0adc 100644 (file)
@@ -126,7 +126,7 @@ class Calendar_Model_PeriodFilter extends Tinebase_Model_Filter_Abstract
                 )),
             ))
         ), Tinebase_Model_Filter_FilterGroup::CONDITION_OR);
-        
+
         Tinebase_Backend_Sql_Filter_FilterGroup::appendFilters($_select, $filter, $_backend);
     }
 
index 585211a..bd07526 100644 (file)
@@ -70,10 +70,14 @@ class Tinebase_Model_Filter_Date extends Tinebase_Model_Filter_Abstract
         if ($this->_operator === 'equals' && empty($this->_value)) {
             // @see 0009362: allow to filter for empty datetimes
             $operator = 'isnull';
-            $value[0] = $this->_value;
+            $value = array($this->_value);
         } else {
             $operator = $this->_operator;
-            $value = (array)$this->_getDateValues($operator, $this->_value);
+            $value = $this->_getDateValues($operator, $this->_value);
+            if (! is_array($value)) {
+                // NOTE: (array) null is an empty array
+                $value = array($value);
+            }
         }
         
         // quote field identifier
index db1a5e7..d5da408 100644 (file)
@@ -31,7 +31,7 @@ class Tinebase_Model_Filter_DateTime extends Tinebase_Model_Filter_Date
     {
         $result = parent::toArray($_valueToJson);
        
-        if ($this->_operator != 'within' && $_valueToJson == true) {
+        if ($this->_operator != 'within' && $_valueToJson == true && $result['value']) {
             $date = new Tinebase_DateTime($result['value']);
             $date->setTimezone(Tinebase_Core::getUserTimezone());
             $result['value'] = $date->toString(Tinebase_Record_Abstract::ISO8601LONG);
@@ -47,7 +47,7 @@ class Tinebase_Model_Filter_DateTime extends Tinebase_Model_Filter_Date
      */
     public function setValue($_value)
     {
-        if ($this->_operator != 'within') {
+        if ($this->_operator != 'within' && $_value) {
             $_value = $this->_convertStringToUTC($_value);
         }