function new_vertex($documents, $id, $nv) { $v = new Document(); $v->set("name", $id + 1); $v->set("component", $id); $v->set("distance", -1); $v->set("pr", 1.0 / $nv); $documents->add("vertices", $v); return $v->getHandle(); }
function save(&$data) { $repo = $this->requireRepository(); $user = $this->getConnectedUser(); $this->data['Document']['repository_id'] = $repo['Repository']['id']; $this->data['Document']['user_id'] = $user['User']['id']; $this->data['Document']['kit_id'] = $repo['Repository']['kit_id']; $this->Document->set($this->data); // errors if (empty($this->data['Document']['tags'])) { $this->Session->setFlash('You must include at least one tag'); } else { if (!$this->Document->validates()) { $errors = $this->Document->invalidFields(); $this->Session->setFlash($errors, 'flash_errors'); } else { if (!$this->Document->saveWithTags($this->data)) { $this->Session->setFlash('There was an error trying to save the document. Please try again later'); } else { $this->Session->setFlash('Document saved successfuly'); $this->_clean_session(); $this->redirect(array('controller' => 'repositories', 'action' => 'index', $repo['Repository']['url'])); } } } }
public function setView($view_name, $map_reduce_ar) { if (!isset($this->data['views'])) { $this->data['views'] = array(); } $views = $this->data['views']; $views[$view_name] = $map_reduce_ar; parent::set('views', $views); }
public function create() { $d = new Document(); /* loop variables and set to Document */ foreach ($this->post as $key => $value) { $d->set($key, $value); } /* save document in collection */ $id = $this->documentHandler->save(COLLECTION_NAME, $d); echo json_encode(["result" => $id]); }
/** * Try to create a document with invalid keys */ public function testCreateDocumentWithInvalidKeys() { $connection = $this->connection; $collection = $this->collection; $documentHandler = new DocumentHandler($connection); $keys = array("", " ", " bar", "bar ", "/", "?", "abcdef gh", "abcxde&", "mötörhead", "this-key-will-be-too-long-to-be-processed-successfully-would-you-agree-with-me-sure-you-will-because-there-is-a-limit-of-254-characters-per-key-which-this-string-will-not-conform-to-if-you-are-still-reading-this-you-should-probably-do-something-else-right-now-REALLY", "#", "|", "ü", "~", "<>", "µµ"); foreach ($keys as $key) { $document = new Document(); $document->someAttribute = 'someValue'; $caught = false; try { $document->set('_key', $key); } catch (\triagens\ArangoDb\ClientException $exception) { $caught = true; } $this->assertTrue($caught, "expecting exception to be thrown for key " . $key); } }
/** * Test getting the last documents in a collection */ public function testLasttWithCountAndTHreeDocuments() { // set up collections and documents $collectionHandler = $this->collectionHandler; $documentHandler = $this->documentHandler; $collection = Collection::createFromArray(array('name' => 'ArangoDB_PHP_TestSuite_TestCollection_Any')); $collectionHandler->add($collection); $document1 = new Document(); $document1->set('message', 'message1'); $documentHandler->save($collection->getId(), $document1); $document2 = new Document(); $document2->set('message', 'message2'); $documentHandler->save($collection->getId(), $document2); $document3 = new Document(); $document3->set('message', 'message3'); $documentHandler->save($collection->getId(), $document3); //Now, let's try to query any document $documents = $collectionHandler->last($collection->getName(), 2); $this->assertTrue(count($documents) == 2); //Let's try another random document $documents = $collectionHandler->last($collection->getName()); $this->assertTrue(count($documents) == 1); $collectionHandler->delete($collection->getName()); }
public function set($value) { $this->document->set($this->var, $value); }
<?php require_once 'lib/db.php'; require_once 'lib/template.php'; $doc = new Document('base'); $doc->title = "Banned"; $ban_doc = new Document('banned'); if ($user->banned == User::BANNED_BY_USER_ID) { $ban = queryGetRow("select u1.ban_date as ban_date, u2.name as banned_by, u1.ban_reason as ban_reason\r\n from {$table['user']} u1, {$table['user']} u2\r\n where u1.id = ? and u2.id = u1.banned_by", $user->id); $ban_doc->set('ban', "User <b>{$user->name}</b> is banned until <b>{$ban['ban_date']}</b> by <b>{$ban['banned_by']}</b>."); $ban_doc->set('logout', "<a href='logout.php'><button>Log out</button></a>"); } else { $ban = queryGetRow("select t1.ban_date as ban_date, u2.name as banned_by, t1.ban_reason as ban_reason\r\n from {$table['ip_data']} t1, {$table['user']} u2\r\n where t1.ip = ? and u2.id = t1.banned_by", $user->ip); $ban_doc->set('ban', "Your ip address <b>{$user->ip}</b> is banned until <b>{$ban['ban_date']}</b> by <b>{$ban['banned_by']}</b>."); } $ban_doc->set('reason', $ban['ban_reason']); $doc->content = $ban_doc->render(); echo $doc->render();
/** * Test for correct exception codes if nonexistent objects are tried to be gotten, replaced, updated or removed */ public function testStoreNewDocumentThenReplace() { //Setup $document = new Document(); $document->set('data', 'this is some test data'); //Check that the document is new $this->assertTrue($document->getIsNew(), 'Document is not marked as new when it is a new document.'); $documentHandler = $this->documentHandler; //Store the document $id = $documentHandler->store($document, $this->collection->getId()); $rev = $document->getRevision(); $this->assertTrue($id == $document->getId(), 'Returned ID does not match the one in the document'); $this->assertTrue($document->get('data') == 'this is some test data', 'Data has been modified for some reason.'); //Check that the document is not new $this->assertTrue(!$document->getIsNew(), 'Document is marked as new when it is not.'); //Update the document and save again $document->set('data', 'this is some different data'); $document->set('favorite_sport', 'hockey'); $documentHandler->store($document); //Check that the id remains the same $this->assertTrue($document->getId() == $id, 'ID of updated document does not match the initial ID.'); //Retrieve a copy of the document from the server $document = $documentHandler->get($this->collection->getId(), $id); //Assert that it is not new $this->assertTrue(!$document->getIsNew(), 'Document is marked as new when it is not.'); //Assert the id is the same $this->assertTrue($document->getId() == $id, 'ID of retrieved document does not match expected ID'); //Assert new data has been saved $this->assertTrue($document->get('favorite_sport') == 'hockey', 'Retrieved data does not match.'); $this->assertTrue($document->getRevision() != $rev, 'Revision matches when it is not suppose to.'); }
function testDocumentLength() { $d = new Document(3); $d->set(array('pricecode' => 'this should be only t', 'youtube' => 'youtube is required to be 16 chars, max')); $d = new Document(3); $this->assertEquals('t', $d->pricecode()); $this->assertEquals(16, strlen($d->youtube())); }
// 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; $user->vists = array(1, 2, 3); $id = $handler->save("users", $user); var_dump("CREATED A NEW DOCUMENT WITH ID: ", $id); // get this document from the server $userFromServer = $handler->getById("users", $id); var_dump($userFromServer); // update this document $userFromServer->nonsense = "hihi"; unset($userFromServer->name); $result = $handler->update($userFromServer); var_dump($result); // get the updated document back $result = $handler->get("users", $id); var_dump($result);
/** * Set a graph attribute * * The key (attribute name) must be a string. * This will validate the value of the attribute and might throw an * exception if the value is invalid. * * @throws ClientException * * @param string $key - attribute name * @param mixed $value - value for attribute * * @return void */ public function set($key, $value) { if ($key === self::ENTRY_EDGE_DEFINITIONS) { if ($this->_doValidate) { ValueValidator::validate($value); } foreach ($value as $ed) { $edgeDefinition = new EdgeDefinition(); foreach ($ed[self::ENTRY_FROM] as $from) { $edgeDefinition->addFromCollection($from); } foreach ($ed[self::ENTRY_TO] as $to) { $edgeDefinition->addToCollection($to); } $edgeDefinition->setRelation($ed[self::ENTRY_COLLECTION]); $this->addEdgeDefinition($edgeDefinition); } } else { if ($key === self::ENTRY_ORPHAN_COLLECTIONS) { if ($this->_doValidate) { ValueValidator::validate($value); } foreach ($value as $o) { $this->addOrphanCollection($o); } } else { parent::set($key, $value); } } }