finalize Calendar_Frontend_Json::searchAttendee
authorPaul Mehrer <p.mehrer@metaways.de>
Wed, 7 Jun 2017 14:12:45 +0000 (16:12 +0200)
committerPaul Mehrer <p.mehrer@metaways.de>
Mon, 12 Jun 2017 08:08:55 +0000 (10:08 +0200)
Change-Id: I165d3a86e032ae5242db3945a269403fdf5fd58a
Reviewed-on: http://gerrit.tine20.com/customers/4842
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
Tested-by: Paul Mehrer <p.mehrer@metaways.de>
tests/tine20/Calendar/JsonTests.php
tine20/Calendar/Frontend/Json.php

index a4487c0..89cc6f5 100644 (file)
@@ -2013,7 +2013,7 @@ class Calendar_JsonTests extends Calendar_TestCase
         $this->assertEquals(0, count($fbinfo));
     }
 
-    public function testSearchAllAttendeeTypes()
+    public function testSearchAttendee()
     {
         $event = $this->_getEvent();
         $event->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(
@@ -2031,16 +2031,28 @@ class Calendar_JsonTests extends Calendar_TestCase
             ),
         ));
 
-        $filter = array(array('field' => 'name', 'operator' => 'contains', 'value' => 'l'));
-        $paging = array('sort' => 'name', 'dir' => 'ASC', 'start' => 0, 'limit' => 10);
+        $filter = array(array('field' => 'query', 'operator' => 'contains', 'value' => 'l'));
+        $paging = array('sort' => 'name', 'dir' => 'ASC', 'start' => 0, 'limit' => 50);
 
-        $result = $this->_uit->searchAllAttendeeTypes($filter, $paging, $period, array());
+        $result = $this->_uit->searchAttendee($filter, $paging, $period, array());
         $this->assertTrue(
             isset($result[Calendar_Model_Attender::USERTYPE_USER]) &&
             count($result[Calendar_Model_Attender::USERTYPE_USER]) === 3 &&
+            count($result[Calendar_Model_Attender::USERTYPE_USER]['results']) > 4 &&
             isset($result[Calendar_Model_Attender::USERTYPE_GROUP]) &&
             isset($result[Calendar_Model_Attender::USERTYPE_RESOURCE]) &&
             isset($result['freeBusyInfo']) &&
             count($result['freeBusyInfo']) === 2, print_r($result, true));
+
+        $filter[] = array('field' => 'type', 'value' => array(Calendar_Model_Attender::USERTYPE_RESOURCE));
+        $result = $this->_uit->searchAttendee($filter, $paging, $period, array());
+        $this->assertTrue(
+            !isset($result[Calendar_Model_Attender::USERTYPE_USER]) &&
+            !isset($result[Calendar_Model_Attender::USERTYPE_GROUP]) &&
+            isset($result[Calendar_Model_Attender::USERTYPE_RESOURCE]) &&
+            count($result[Calendar_Model_Attender::USERTYPE_RESOURCE]) === 3 &&
+            count($result[Calendar_Model_Attender::USERTYPE_RESOURCE]['results']) === 0 &&
+            isset($result['freeBusyInfo']) &&
+            count($result['freeBusyInfo']) === 0, print_r($result, true));
     }
 }
index 050657d..635c689 100644 (file)
@@ -485,23 +485,55 @@ class Calendar_Frontend_Json extends Tinebase_Frontend_Json_Abstract
      * @param array $_ignoreUIDs
      * @return array
      */
-    public function searchAllAttendeeTypes($_filter, $_paging, $_periods, $_ignoreUIDs)
+    public function searchAttendee($_filter, $_paging, $_periods, $_ignoreUIDs)
     {
+        $filters = array();
+        foreach($_filter as $filter) {
+            switch($filter['field']) {
+                case 'query':
+                    $filters['query'] = $filter;
+                    break;
+                default:
+                    $filters[$filter['field']] = $filter['value'];
+                    break;
+            }
+        }
+
+        $result = array();
         $addressBookFE = new Addressbook_Frontend_Json();
-        $contactFilter = array(array('condition' => 'OR', 'filters' => array(
-            $_filter[0],
-            array('field' => 'path', 'operator' => 'contains', 'value' => $_filter[0]['value'])
-        )));
-        $groupFilter = $contactFilter;
-        $groupFilter[] = array('field' => 'type', 'operator' => 'contains', 'value' => 'group');
-        $contactPaging = $_paging;
-        $contactPaging['sort'] = 'type';
 
-        $result = array(
-            Calendar_Model_Attender::USERTYPE_USER => $addressBookFE->searchContacts($contactFilter, $contactPaging),
-            Calendar_Model_Attender::USERTYPE_GROUP => $addressBookFE->searchLists($groupFilter, $_paging),
-            Calendar_Model_Attender::USERTYPE_RESOURCE => $this->searchResources($_filter, $_paging)
-        );
+        if (!isset($filters['type']) || in_array(Calendar_Model_Attender::USERTYPE_USER, $filters['type'])) {
+            $contactFilter = array(array('condition' => 'OR', 'filters' => array(
+                $filters['query'],
+                array('field' => 'path', 'operator' => 'contains', 'value' => $filters['query']['value'])
+            )));
+            if (isset($filters['userFilter'])) {
+                $contactFilter[] = $filters['userFilter'];
+            }
+            $contactPaging = $_paging;
+            $contactPaging['sort'] = 'type';
+            $result[Calendar_Model_Attender::USERTYPE_USER] = $addressBookFE->searchContacts($contactFilter, $contactPaging);
+        }
+
+        if (!isset($filters['type']) || in_array(Calendar_Model_Attender::USERTYPE_GROUP, $filters['type'])) {
+            $groupFilter = array(array('condition' => 'OR', 'filters' => array(
+                $filters['query'],
+                array('field' => 'path', 'operator' => 'contains', 'value' => $filters['query']['value'])
+            )));
+            if (isset($filters['groupFilter'])) {
+                $groupFilter[] = $filters['groupFilter'];
+            }
+            $groupFilter[] = array('field' => 'type', 'operator' => 'contains', 'value' => 'group');
+            $result[Calendar_Model_Attender::USERTYPE_GROUP] = $addressBookFE->searchLists($groupFilter, $_paging);
+        }
+
+        if (!isset($filters['type']) || in_array(Calendar_Model_Attender::USERTYPE_RESOURCE, $filters['type'])) {
+            $resourceFilter = array($filters['query']);
+            if (isset($filters['resourceFilter'])) {
+                $resourceFilter[] = $filters['resourceFilter'];
+            }
+            $result[Calendar_Model_Attender::USERTYPE_RESOURCE] = $this->searchResources($resourceFilter, $_paging);
+        }
 
         $attendee = array();
         foreach ($result as $type => $res) {