/**
  * test for replacing a edge using replace()
  */
 public function testReplaceEdge()
 {
     $connection = $this->connection;
     $edgeHandler = new EdgeHandler($connection);
     $edgeCollection = $this->edgeCollection;
     $document1 = new Document();
     $document2 = new Document();
     $documentHandler = new DocumentHandler($connection);
     $edgeDocument = new Edge();
     $document1->someAttribute = 'someValue1';
     $document2->someAttribute = 'someValue2';
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document1);
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document2);
     $documentHandle1 = $document1->getHandle();
     $documentHandle2 = $document2->getHandle();
     $edgeDocument->set('label', null);
     $edgeDocument->set('labelt', "as");
     $edgeId = $edgeHandler->saveEdge($edgeCollection->getName(), $documentHandle1, $documentHandle2, $edgeDocument);
     $this->assertTrue(is_numeric($edgeId), 'Did not return an id!');
     $edgePutDocument = new Edge();
     $edgePutDocument->set('_id', $edgeDocument->getHandle());
     $edgePutDocument->set('_rev', $edgeDocument->getRevision());
     $edgePutDocument->set('labels', "as");
     $result = $edgeHandler->replace($edgePutDocument);
     $this->assertTrue($result);
     $resultingEdge = $edgeHandler->get($edgeCollection->getId(), $edgeId);
     $this->assertObjectHasAttribute('_id', $resultingEdge, '_id field should exist, empty or with an id');
     $this->assertTrue($resultingEdge->label == null, 'Should be :null, is: ' . $resultingEdge->label);
     $this->assertTrue($resultingEdge->labelt == null, 'Should be :null, is: ' . $resultingEdge->labelt);
     $this->assertTrue($resultingEdge->labels == "as");
     $response = $edgeHandler->delete($resultingEdge);
     $this->assertTrue($response, 'Delete should return true!');
 }
 public function testHasDocumentReturnsTrueIfDocumentExists()
 {
     $connection = $this->connection;
     $collection = $this->collection;
     $documentHandler = new DocumentHandler($connection);
     // create doc first
     $document = new Document();
     $document->someAttribute = 'someValue';
     $documentId = $documentHandler->add($collection->getId(), $document);
     $this->assertTrue($this->collectionHandler->has($collection->getId(), $documentId));
 }
Exemplo n.º 3
0
 /**
  * Method view()
  */
 public function archive()
 {
     try {
         header('Content-type: application/xml');
         $xml = $this->xml->saveXML();
         $name = $this->getFileName() . '.xml';
         $date = date('Y-m-d H:i:s');
         $document = new stdClass();
         $document->pid = $this->pid;
         $document->eid = $this->eid;
         $document->uid = $_SESSION['user']['id'];
         $document->docType = 'C-CDA';
         $document->name = $name;
         $document->date = $date;
         $document->note = '';
         $document->title = 'C-CDA';
         $document->encrypted = 0;
         $document->document = base64_encode($xml);
         include_once ROOT . '/dataProvider/DocumentHandler.php';
         $DocumentHandler = new DocumentHandler();
         $DocumentHandler->addPatientDocument($document);
         unset($DocumentHandler, $document, $name, $date);
         print $xml;
     } catch (Exception $e) {
         print $e->getMessage();
     }
 }
Exemplo n.º 4
0
 /**
  * @param $params
  * @return array
  */
 public function UploadPatientDocument($params)
 {
     $this->constructor($params);
     if (!$this->isAuth()) {
         return ['Success' => false, 'Error' => 'Error: HTTP 403 Access Forbidden'];
     }
     if (!$this->isPatientValid()) {
         return ['Success' => false, 'Error' => 'Error: No Valid Patient Found'];
     }
     if (!$this->isProviderValid()) {
         return ['Success' => false, 'Error' => 'Error: No Valid Provider Found'];
     }
     $document = new stdClass();
     $document->eid = 0;
     $document->pid = $this->patient->pid;
     $document->uid = $this->provider->id;
     $document->name = 'SoapUpload.pdf';
     $document->date = $params->Document->Date;
     $document->title = $params->Document->Title;
     $document->document = $params->Document->Base64Document;
     $document->docType = isset($params->Document->Category) ? $params->Document->Category : 'General';
     $document->note = isset($params->Document->Notes) ? $params->Document->Notes : '';
     $document->encrypted = isset($params->Document->Encrypted) ? $params->Document->Encrypted : false;
     require_once ROOT . '/dataProvider/DocumentHandler.php';
     $DocumentHandler = new DocumentHandler();
     $result = $DocumentHandler->addPatientDocument($document);
     unset($DocumentHandler);
     return ['Success' => isset($result['data']->id)];
 }
 public function testCreateMixedBatchWithPartIds()
 {
     $edgeCollection = $this->edgeCollection;
     $batch = new Batch($this->connection);
     $this->assertInstanceOf('\\triagens\\ArangoDb\\Batch', $batch);
     // Create collection
     $connection = $this->connection;
     $collection = new Collection();
     $collectionHandler = new CollectionHandler($connection);
     $name = 'ArangoDB_PHP_TestSuite_TestCollection_02';
     $collection->setName($name);
     $batch->nextBatchPartId('testCollection1');
     $response = $collectionHandler->add($collection);
     $this->assertTrue(is_numeric($response), 'Did not return a fake numeric id!');
     $batch->process();
     $resultingCollectionId = $batch->getProcessedPartResponse('testCollection1');
     $testCollection1Part = $batch->getPart('testCollection1');
     $this->assertTrue($testCollection1Part->getHttpCode() == 200, 'Did not return an HttpCode 200!');
     $resultingCollection = $collectionHandler->get($batch->getProcessedPartResponse('testCollection1'));
     $resultingAttribute = $resultingCollection->getName();
     $this->assertTrue($name === $resultingAttribute, 'The created collection name and resulting collection name do not match!');
     $this->assertEquals(Collection::getDefaultType(), $resultingCollection->getType());
     $batch = new Batch($this->connection);
     // Create documents
     $documentHandler = $this->documentHandler;
     $batch->nextBatchPartId('doc1');
     $document = Document::createFromArray(array('someAttribute' => 'someValue', 'someOtherAttribute' => 'someOtherValue'));
     $documentId = $documentHandler->add($resultingCollectionId, $document);
     $this->assertTrue(is_numeric($documentId), 'Did not return a fake numeric id!');
     for ($i = 0; $i <= 10; ++$i) {
         $document = Document::createFromArray(array('someAttribute' => 'someValue' . $i, 'someOtherAttribute' => 'someOtherValue2' . $i));
         $documentId = $documentHandler->add($resultingCollectionId, $document);
     }
     $this->assertTrue(is_numeric($documentId), 'Did not return a fake numeric id!');
     $batch->process();
     // try getting processed response through batchpart
     $testDocument1PartResponse = $batch->getPart('doc1')->getProcessedResponse();
     // try getting it from batch
     $testDocument2PartResponse = $batch->getProcessedPartResponse(1);
     $batch = new Batch($this->connection);
     $docId1 = explode('/', $testDocument1PartResponse);
     $docId2 = explode('/', $testDocument2PartResponse);
     $documentHandler->getById($resultingCollectionId, $docId1[1]);
     $documentHandler->getById($resultingCollectionId, $docId2[1]);
     $batch->process();
     $document1 = $batch->getProcessedPartResponse(0);
     $document2 = $batch->getProcessedPartResponse(1);
     $batch = new Batch($this->connection);
     // test edge creation
     $edgeDocument = new Edge();
     $edgeDocumentHandler = new EdgeHandler($connection);
     $edgeDocument->set('label', 'knows');
     $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $document1->getHandle(), $document2->getHandle(), $edgeDocument);
     $batch->process();
     $edge = $batch->getProcessedPartResponse(0);
     $this->assertFalse(is_a($edge, 'triagens\\ArangoDb\\HttpResponse'), 'Edge batch creation did return an error: ' . print_r($edge, true));
     $this->assertTrue($edge == !'', 'Edge batch creation did return empty string: ' . print_r($edge, true));
     $batch = new Batch($this->connection);
     $document = new Document();
     $documentHandler = new DocumentHandler($connection);
     $document->someAttribute = 'someValue';
     $documentHandler->add($resultingCollection->getId(), $document);
     // set the next batchpart id
     $batch->nextBatchPartId('myBatchPart');
     // set cursor options for the next batchpart
     $batch->nextBatchPartCursorOptions(array("sanitize" => true));
     // set batchsize to 10, so we can test if an additional http request is done when we getAll() a bit later
     $statement = new Statement($connection, array("query" => '', "count" => true, "batchSize" => 10, "sanitize" => true));
     $statement->setQuery('FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_02` RETURN a');
     $statement->execute();
     $documentHandler->removeById($resultingCollectionId, $docId1[1]);
     $documentHandler->removeById($resultingCollectionId, $docId2[1]);
     $batch->nextBatchPartId('docsAfterRemoval');
     $collectionHandler->getAllIds($resultingCollectionId);
     $batch->process();
     $stmtCursor = $batch->getProcessedPartResponse('myBatchPart');
     $this->assertTrue(count($stmtCursor->getAll()) == 13, 'At the time of statement execution there should be 13 documents found! Found: ' . count($stmtCursor->getAll()));
     // This fails but we'll just make a note because such a query is not needed to be batched.
     // $docsAfterRemoval=$batch->getProcessedPartResponse('docsAfterRemoval');
     // $this->assertTrue(count($docsAfterRemoval) == 1, 'At the time of statement execution there should be 3 documents found! Found: '.count($stmtCursor->getAll()));
     // Get previously created collection and delete it, from inside a batch
     $batch = new Batch($this->connection);
     $collectionHandler->delete($resultingCollectionId);
     $batch->process();
 }
 public function testBindReservedName()
 {
     $connection = $this->connection;
     $collection = $this->collection;
     $documentHandler = new DocumentHandler($connection);
     $document = new Document();
     $document->test = 'file';
     $documentHandler->add($collection->getId(), $document);
     $statement = new Statement($connection, array("query" => 'FOR a IN `ArangoDB_PHP_TestSuite_TestCollection_01` FILTER a.test == @test RETURN a.test', "bindVars" => array("test" => "file"), "_sanitize" => true));
     $cursor = $statement->execute();
     $rows = $cursor->getAll();
     $this->assertEquals("file", $rows[0]);
 }
<?php

namespace triagens\ArangoDb;

require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
try {
    $connection = new Connection($connectionOptions);
    $collectionHandler = new CollectionHandler($connection);
    $documentHandler = new DocumentHandler($connection);
    $edgeHandler = new EdgeHandler($connection);
    // set up two document collections
    $collection = new Collection("employees");
    try {
        $collectionHandler->add($collection);
    } catch (\Exception $e) {
        // collection may already exist - ignore this error for now
    }
    $collection = new Collection("departments");
    try {
        $collectionHandler->add($collection);
    } catch (\Exception $e) {
        // collection may already exist - ignore this error for now
    }
    // set up an edge collection to link the two previous collections
    $collection = new Collection("worksFor");
    $collection->setType(3);
    try {
        $collectionHandler->add($collection);
    } catch (\Exception $e) {
        // collection may already exist - ignore this error for now
    }
<?php

namespace triagens\ArangoDb;

require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php';
try {
    $connection = new Connection($connectionOptions);
    $collectionHandler = new CollectionHandler($connection);
    $handler = new DocumentHandler($connection);
    // set up a document collection "users"
    $collection = new Collection("users");
    try {
        $collectionHandler->add($collection);
    } catch (\Exception $e) {
        // collection may already exist - ignore this error for now
    }
    // create a new document
    $user = new Document();
    $user->set("name", "John");
    $user->age = 19;
    $id = $handler->save("users", $user);
    // get documents by example
    $cursor = $collectionHandler->byExample("users", array("name" => "John", "age" => 19));
    var_dump($cursor->getAll());
    // get the ids of all documents in the collection
    $result = $handler->getAllIds("users");
    var_dump($result);
    // create another new document
    $user = new Document();
    $user->set("name", "j-lo");
    $user->level = 1;
 /**
  * Test outEdges method
  */
 public function testEdgesOut()
 {
     $connection = $this->connection;
     $edgeCollection = $this->edgeCollection;
     $document1 = new Document();
     $document2 = new Document();
     $documentHandler = new DocumentHandler($connection);
     $edgeDocumentHandler = new EdgeHandler($connection);
     $document1->someAttribute = 'someValue1';
     $document2->someAttribute = 'someValue2';
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document1);
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document2);
     $documentHandle1 = $document1->getHandle();
     $documentHandle2 = $document2->getHandle();
     $edgeDocument1 = $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $documentHandle1, $documentHandle2, array('value' => 1));
     $edgeDocument2 = $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $documentHandle2, $documentHandle1, array('value' => 2));
     $edgeDocument3 = $edgeDocumentHandler->saveEdge($edgeCollection->getName(), $documentHandle1, $documentHandle2, array('value' => 3));
     $edgesQueryResult = $edgeDocumentHandler->outEdges($edgeCollection->getName(), $documentHandle1);
     $this->assertEquals(2, count($edgesQueryResult));
     foreach ($edgesQueryResult as $edge) {
         $this->assertInstanceOf('triagens\\ArangoDb\\Edge', $edge);
         if ($edge->value === 1) {
             $this->assertEquals($documentHandle1, $edge->getFrom());
             $this->assertEquals($documentHandle2, $edge->getTo());
             $this->assertEquals($edgeDocument1, $edge->getId());
         } else {
             $this->assertEquals($documentHandle1, $edge->getFrom());
             $this->assertEquals($documentHandle2, $edge->getTo());
             $this->assertEquals($edgeDocument3, $edge->getId());
         }
     }
     // test empty result
     $edgesQueryResult = $edgeDocumentHandler->outEdges($edgeCollection->getName(), "ArangoDBPHPTestSuiteTestCollection01/foobar");
     $this->assertEquals(0, count($edgesQueryResult));
 }
Exemplo n.º 10
0
 /**
  * Try to create, head and delete a edge
  */
 public function testCreateHeadAndDeleteEdgeWithRevision()
 {
     $connection = $this->connection;
     $edgeHandler = new EdgeHandler($connection);
     $edgeCollection = $this->edgeCollection;
     $document1 = new Document();
     $document2 = new Document();
     $documentHandler = new DocumentHandler($connection);
     $edgeDocument = new Edge();
     $document1->someAttribute = 'someValue1';
     $document2->someAttribute = 'someValue2';
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document1);
     $documentHandler->add('ArangoDBPHPTestSuiteTestCollection01', $document2);
     $documentHandle1 = $document1->getHandle();
     $documentHandle2 = $document2->getHandle();
     $edgeDocument->set('label', 'knows');
     $edgeId = $edgeHandler->saveEdge($edgeCollection->getName(), $documentHandle1, $documentHandle2, $edgeDocument);
     try {
         $edgeHandler->getHead($edgeCollection->getId(), $edgeId, "12345", true);
     } catch (\Exception $e412) {
     }
     $this->assertEquals($e412->getCode(), 412);
     try {
         $edgeHandler->getHead($edgeCollection->getId(), "notExisting");
     } catch (\Exception $e404) {
     }
     $this->assertEquals($e404->getCode(), 404);
     $result304 = $edgeHandler->getHead($edgeCollection->getId(), $edgeId, $edgeDocument->getRevision(), false);
     $this->assertEquals($result304["etag"], '"' . $edgeDocument->getRevision() . '"');
     $this->assertEquals($result304["content-length"], 0);
     $this->assertEquals($result304["httpCode"], 304);
     $result200 = $edgeHandler->getHead($edgeCollection->getId(), $edgeId, $edgeDocument->getRevision(), true);
     $this->assertEquals($result200["etag"], '"' . $edgeDocument->getRevision() . '"');
     $this->assertNotEquals($result200["content-length"], 0);
     $this->assertEquals($result200["httpCode"], 200);
     $documentHandler->delete($document1);
     $documentHandler->delete($document2);
     $edgeHandler->deleteById($edgeCollection->getName(), $edgeId);
 }
function createAttachedDocumentsPdf($product)
{
    $attachedDocuments = $product->get_all_linked_attachments();
    //	trigger_error("Started to convert products to PDF!", E_USER_NOTICE);
    if (empty($attachedDocuments)) {
        return null;
    }
    $docHandler = null;
    $catArgs = array();
    $filenameArgs = array();
    $filenames = array();
    $attachArgs = array();
    $ids = range('A', chr(ord('A') + count($attachedDocuments) - 1));
    foreach ($attachedDocuments as $attachment_id) {
        $revision_id = $attachment_id;
        $revision_check = new DocumentRevision();
        if (!$revision_check->retrieve($attachment_id)) {
            $document = new Document();
            if ($document->retrieve($attachment_id)) {
                $revision_id = $document->document_revision_id;
                $purpose = $document->document_purpose_c;
            }
        } else {
            $document = new Document();
            if ($document->retrieve($revision_check->document_id)) {
                $purpose = $document->document_purpose_c;
            }
        }
        if ($purpose == 'Catalog') {
            //1.7.6 include only documents marked For Product Catalog
            $revision = new DocumentRevision();
            if ($revision->retrieve($revision_id)) {
                if ($revision->file_ext != 'pdf') {
                    //SugarCE determines file type unreliably, so only extension is used
                    if (!$docHandler) {
                        $docHandler = new DocumentHandler();
                    }
                    $filename = getDocumentFilename($revision_id);
                    // skuria failo varda su nuoroda
                    // we need a descriptive filename for word macros and pdf attachments
                    $realFilenameWithExtension = getRealFilename($revision);
                    copy($filename, $realFilenameWithExtension);
                    $filenames[] = $realFilenameWithExtension;
                    $attachmentFilename = $docHandler->convertToPdf($realFilenameWithExtension);
                    if ($attachmentFilename) {
                        $catArgs[] = current($ids);
                        $filenameArgs[] = current($ids) . '=' . $attachmentFilename;
                        $filenames[] = $attachmentFilename;
                        next($ids);
                    } else {
                        // file was not possible to convert
                        $attachArgs[] = $realFilenameWithExtension;
                        $GLOBALS['log']->fatal('OQC DocumentHandler: file ' . $realFilenameWithExtension . ' is not possible to convert to pdf!');
                        continue;
                    }
                } else {
                    $attachmentFilename = getDocumentFilename($revision_id);
                    $catArgs[] = current($ids);
                    $filenameArgs[] = current($ids) . '=' . $attachmentFilename;
                    next($ids);
                }
            }
        }
    }
    $testPdfFiles = implode('', $catArgs);
    //test if there are any pdf file available for pdftk
    //$GLOBALS['log']->error('OQC pdf testfiles'.$testPdfFiles);
    $testAttachFiles = implode('', $attachArgs);
    //test if there are attachement files
    if (empty($testPdfFiles)) {
        foreach ($filenames as $attachfile) {
            unlink($attachfile);
        }
        return null;
    }
    $outputFilename = tempnam(TMP_DIR, '');
    $finalFilename = tempnam(TMP_DIR, '');
    $contractFilename = tempnam(TMP_DIR, '');
    if (!empty($testPdfFiles)) {
        // merge files
        $pdfTkArgs = implode(' ', $filenameArgs) . ' cat ' . implode(' ', $catArgs) . " output {$outputFilename} keep_first_id";
        if (execute(PDFTK, $pdfTkArgs) == 0) {
            copy($outputFilename, $contractFilename);
            //owerwrite source file
        } else {
            $GLOBALS['log']->error('Failed to merge PDF files!');
            //cleanup of temporary files
            unlink($finalFilename);
            unlink($outputFilename);
            unlink($contractFilename);
            foreach ($filenames as $attachfile) {
                unlink($attachfile);
            }
            return null;
        }
    }
    if (!empty($testAttachFiles) && !empty($testPdfFiles)) {
        $pdfTkArgs = "{$contractFilename} attach_files " . implode(' ', $attachArgs) . " output {$finalFilename}";
        if (execute(PDFTK, $pdfTkArgs) == 0) {
            copy($finalFilename, $contractFilename);
        } else {
            $GLOBALS['log']->error('Failed to attach documents to final PDF!');
        }
    }
    //cleanup of temporary files
    unlink($finalFilename);
    unlink($outputFilename);
    foreach ($filenames as $attachfile) {
        unlink($attachfile);
    }
    $contractFilenamePdf = str_replace("\\", "/", dirname($contractFilename) . DIRECTORY_SEPARATOR . basename($contractFilename, '.tmp') . '.pdf');
    rename($contractFilename, $contractFilenamePdf);
    //$GLOBALS['log']->error('OQC: Attachment filename is '.$contractFilenamePdf);
    //return str_replace("\\","/",$contractFilename.'.pdf');
    return $contractFilenamePdf;
}