/**
  * Get the batch part identified by the array key (0...n) or its id (if it was set with nextBatchPartId($id) )
  *
  * @throws ClientException
  * @return mixed $partId
  */
 public function getProcessedResponse()
 {
     $response = $this->getResponse();
     switch ($this->_type) {
         case 'getdocument':
             $json = $response->getJson();
             $options = $this->getCursorOptions();
             $options['isNew'] = false;
             $response = Document::createFromArray($json, $options);
             break;
         case 'document':
             $json = $response->getJson();
             if ($json['error'] === false) {
                 $id = $json[Document::ENTRY_ID];
                 $response = $id;
             }
             break;
         case 'getedge':
             $json = $response->getJson();
             $options = $this->getCursorOptions();
             $options['isNew'] = false;
             $response = Edge::createFromArray($json, $options);
             break;
         case 'edge':
             $json = $response->getJson();
             if ($json['error'] === false) {
                 $id = $json[Edge::ENTRY_ID];
                 $response = $id;
             }
             break;
         case 'getcollection':
             $json = $response->getJson();
             $options = $this->getCursorOptions();
             $options['isNew'] = false;
             $response = Collection::createFromArray($json, $options);
             break;
         case 'collection':
             $json = $response->getJson();
             if ($json['error'] === false) {
                 $id = $json[Collection::ENTRY_ID];
                 $response = $id;
             }
             break;
         case 'cursor':
             $options = $this->getCursorOptions();
             $options['isNew'] = false;
             $response = new Cursor($this->_batch->getConnection(), $response->getJson(), $options);
             break;
         default:
             throw new ClientException('Could not determine response data type.');
             break;
     }
     return $response;
 }
 /**
  * Get properties of a collection
  *
  * This will throw if the collection cannot be fetched from the server
  *
  * @throws Exception
  *
  * @param mixed $collectionId - collection id as a string or number
  *
  * @return Collection - the collection fetched from the server
  */
 public function getProperties($collectionId)
 {
     $url = UrlHelper::buildUrl(Urls::URL_COLLECTION, array($collectionId, self::OPTION_PROPERTIES));
     $response = $this->getConnection()->get($url);
     $data = $response->getJson();
     return Collection::createFromArray($data);
 }
 /**
  * test bulk document lookups
  */
 public function testLookupByKeys()
 {
     $documentHandler = $this->documentHandler;
     $collectionHandler = $this->collectionHandler;
     $collection = Collection::createFromArray(array('name' => 'ArangoDB_PHP_TestSuite_TestCollection_01', 'waitForSync' => false));
     $collectionHandler->add($collection);
     $document = Document::createFromArray(array('someAttribute' => 'someValue1', 'someOtherAttribute' => 'someOtherValue'));
     $documentId = $documentHandler->add($collection->getId(), $document);
     $document2 = Document::createFromArray(array('someAttribute' => 'someValue2', 'someOtherAttribute' => 'someOtherValue2'));
     $documentId2 = $documentHandler->add($collection->getId(), $document2);
     $document3 = Document::createFromArray(array('someAttribute' => 'someValue3', 'someOtherAttribute' => 'someOtherValue'));
     $documentId3 = $documentHandler->add($collection->getId(), $document3);
     $this->assertTrue(is_numeric($documentId), 'Did not return an id!');
     $this->assertTrue(is_numeric($documentId2), 'Did not return an id!');
     $this->assertTrue(is_numeric($documentId3), 'Did not return an id!');
     $keys = array($documentId, $documentId2, $documentId3);
     $result = $collectionHandler->lookupByKeys($collection->getId(), $keys);
     $this->assertEquals(3, count($result));
     $document = $result[0];
     $this->assertInstanceOf('\\triagens\\ArangoDb\\Document', $document, "Object was not a Document!");
     $this->assertEquals($documentId, $document->getId());
     $this->assertEquals("someValue1", $document->someAttribute);
     $this->assertEquals("someOtherValue", $document->someOtherAttribute);
     $document = $result[1];
     $this->assertInstanceOf('\\triagens\\ArangoDb\\Document', $document, "Object was not a Document!");
     $this->assertEquals($documentId2, $document->getId());
     $this->assertEquals("someValue2", $document->someAttribute);
     $this->assertEquals("someOtherValue2", $document->someOtherAttribute);
     $document = $result[2];
     $this->assertInstanceOf('\\triagens\\ArangoDb\\Document', $document, "Object was not a Document!");
     $this->assertEquals($documentId3, $document->getId());
     $this->assertEquals("someValue3", $document->someAttribute);
     $this->assertEquals("someOtherValue", $document->someOtherAttribute);
 }
 /**
  * test for fulltext queries
  */
 public function testFulltextQuery()
 {
     $this->collectionHandler = new CollectionHandler($this->connection);
     $documentHandler = $this->documentHandler;
     $collectionHandler = $this->collectionHandler;
     $collection = Collection::createFromArray(array('name' => 'ArangoDB_PHP_TestSuite_TestCollection_01', 'waitForSync' => true));
     $collectionHandler->add($collection);
     $document = Document::createFromArray(array('someAttribute' => 'someValue1', 'someOtherAttribute' => 'someOtherValue'));
     $documentId = $documentHandler->add($collection->getId(), $document);
     $document2 = Document::createFromArray(array('someAttribute' => 'someValue2', 'someOtherAttribute' => 'someOtherValue2'));
     $documentId2 = $documentHandler->add($collection->getId(), $document2);
     $document3 = Document::createFromArray(array('someAttribute' => 'someValue3', 'someOtherAttribute' => 'someOtherValue'));
     $documentId3 = $documentHandler->add($collection->getId(), $document3);
     // First we test without a fulltext index and expect a 400
     try {
         $result = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue");
     } catch (Exception $e) {
     }
     $this->assertTrue($e->getCode() === 400);
     // Now we create an index
     $fulltextIndexId = $collectionHandler->createFulltextIndex($collection->getId(), array("someOtherAttribute"));
     $fulltextIndexId = $fulltextIndexId["id"];
     $cursor = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue", array("index" => $fulltextIndexId));
     $m = $cursor->getMetadata();
     $this->assertTrue($m["count"] == 2);
     $this->assertTrue($m["hasMore"] == false);
     // Now we pass some options
     $cursor = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue", array("index" => $fulltextIndexId, "skip" => 1));
     $m = $cursor->getMetadata();
     $this->assertTrue($m["count"] == 1);
     $this->assertTrue($m["hasMore"] == false);
     $cursor = $collectionHandler->fulltext($collection->getId(), "someOtherAttribute", "someOtherValue", array("batchSize" => 1));
     $m = $cursor->getMetadata();
     $this->assertTrue($m["count"] == 2);
     $this->assertTrue(count($m["result"]) == 1);
     $this->assertTrue($m["hasMore"] == true);
 }