10952 filter record relations should not be resolved
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 1 Apr 2015 15:13:58 +0000 (17:13 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 1 Apr 2015 15:45:49 +0000 (17:45 +0200)
* and fixed function signature for get() in Sales_Controller_Contract

https://forge.tine20.org/view.php?id=10952

Change-Id: I949c63e50ef2f553d5774096e8dfa918ca778655
Reviewed-on: http://gerrit.tine20.com/customers/1787
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Tinebase/Frontend/Json/PersistentFilterTest.php
tine20/Sales/Controller/Contract.php
tine20/Tinebase/Model/Filter/ExplicitRelatedRecord.php
tine20/Tinebase/Model/Filter/Id.php
tine20/Tinebase/Record/Abstract.php

index 7f09fcd..80d8a75 100644 (file)
@@ -5,7 +5,7 @@
  * Test class for Tinebase_Frontend_Json_PersistentFilter
  * 
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
- * @copyright   Copyright (c) 2009-2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2009-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Cornelius Weiss <c.weiss@metaways.de>
  * 
  */
@@ -374,4 +374,61 @@ class Tinebase_Frontend_Json_PersistentFilterTest extends TestCase
         
         $this->testOverwriteExistingFilter();
     }
+
+    /**
+     * testFilterResolving
+     * 
+     * -> relations should not be resolved here!
+     */
+    public function testFilterResolving()
+    {
+        $contact1 = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'test heini')));
+        $contactWithRelations = array(
+            'n_family' => 'test typ',
+            'relations' => array(array(
+                'own_model'              => 'Addressbook_Model_Contact',
+                'own_backend'            => 'Sql',
+                'own_id'                 => 0,
+                'own_degree'             => Tinebase_Model_Relation::DEGREE_SIBLING,
+                'type'                   => '',
+                'related_backend'        => 'Sql',
+                'related_id'             => $contact1->getId(),
+                'related_model'          => 'Addressbook_Model_Contact',
+                'remark'                 => NULL,
+            ),
+            )
+        );
+        $contact2 = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact($contactWithRelations));
+        $exampleFilterData = self::getPersistentFilterData();
+        $exampleFilterData['filters'] = array(
+            array('field' => 'foreignRecord', 'operator' => 'AND', 'value' => array(
+                'appName' => 'Addressbook',
+                'modelName' => 'Contact',
+                'linkType' => 'relation',
+                'filters' => array
+                (
+                    array
+                    (
+                        'field' => ':id',
+                        'operator' => 'equals',
+                        'value' => $contact2->getId()
+                    )
+                )
+            ))
+        );
+        $savedFilterData = $this->_uit->savePersistentFilter($exampleFilterData);
+        
+        $filterData = array(
+            array('field' => 'model',   'operator' => 'equals', 'value' => 'Tasks_Model_TaskFilter'),
+            array('field' => 'id',      'operator' => 'equals', 'value' => $savedFilterData['id'])
+        );
+        
+        $searchResult = $this->_uit->searchPersistentFilter($filterData, NULL);
+        
+        $this->assertEquals(1, $searchResult['totalcount']);
+        
+        $this->assertTrue(isset($searchResult['results'][0]['filters'][0]['value']['filters'][0]['value']));
+        $filterContact = $searchResult['results'][0]['filters'][0]['value']['filters'][0]['value'];
+        $this->assertTrue(! isset($filterContact['relations']), 'relations should not be resolved:' . print_r($filterContact, true));
+    }
 }
index 1c9fd92..11cac7c 100644 (file)
@@ -56,12 +56,15 @@ class Sales_Controller_Contract extends Tinebase_Controller_Record_Abstract
      * get by id
      *
      * @param string $_id
+     * @param int $_containerId
+     * @param bool         $_getRelatedData
      * @return Tinebase_Record_RecordSet
      */
-    public function get($_id)
+    public function get($_id, $_containerId = NULL, $_getRelatedData = TRUE)
     {
-        $sharedContracts = $this->getSharedContractsContainer();
-        return parent::get($_id, $sharedContracts->getId());
+        $containerId = $_containerId !== null ? $_containerId : $this->getSharedContractsContainer();
+        
+        return parent::get($_id, $containerId, $_getRelatedData);
     }
     
     /**
index 437c09e..0f16e13 100644 (file)
@@ -75,7 +75,7 @@ class Tinebase_Model_Filter_ExplicitRelatedRecord extends Tinebase_Model_Filter_
             if ($filter['field'] == ':id' && $filter['operator'] == 'equals' && is_string($filter['value']) && strlen($filter['value']) == 40) {
                 $split = explode('_Model_', $this->_options['related_model']);
                 $cname = $split[0] . '_Controller_' . $split[1];
-                $fr = $cname::getInstance()->get($filter['value']);
+                $fr = $cname::getInstance()->get($filter['value'], /* $_containerId = */ null, /* $_getRelatedData = */ false);
                 $fr->relations = null;
                 $filter['value'] = $fr->toArray();
             }
index a52e9fb..b558ba8 100644 (file)
@@ -212,7 +212,7 @@ class Tinebase_Model_Filter_Id extends Tinebase_Model_Filter_Abstract
         
         try {
             if (method_exists($controller, 'get')) {
-                $recordArray = $controller->get($value)->toArray();
+                $recordArray = $controller->get($value, /* $_containerId = */ null, /* $_getRelatedData = */ false)->toArray();
             } else {
                 Tinebase_Core::getLogger()->NOTICE(__METHOD__ . '::' . __LINE__ . ' Controller ' . get_class($controller) . ' has no get method');
                 return $value;
index cb96adf..fb2f275 100644 (file)
@@ -482,15 +482,6 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
      */
     public function toArray($_recursive = TRUE)
     {
-        /*
-        foreach ($this->_properties as $key => $value) {
-            if ($value instanceof DateTime) {
-                $date = new Tinebase_DateTime($value->get(Tinebase_Record_Abstract::ISO8601LONG));
-                $date->setTimezone($value->getTimezone());
-                $this->_properties[$key] = $date;
-            }
-        }
-        */
         $recordArray = $this->_properties;
         if ($this->convertDates === true) {
             if (! is_string($this->dateConversionFormat)) {