public function addRelationship(Relationship $relationship)
 {
     $this->relationships[$relationship->getId()] = $relationship;
 }
Esempio n. 2
0
 /**
  * @param \Neoxygen\NeoClient\Formatter\Relationship $relationship
  */
 public function addOutboundRelationship(Relationship $relationship)
 {
     $this->outboundRelationships[$relationship->getId()] = $relationship;
 }
 public function testImplicitBatch_StartBatch_CloseBatch_ExpectedBatchRequest()
 {
     $startNode = new Node($this->client);
     $endNode = new Node($this->client);
     $endNode->setId(456)->useLazyLoad(false);
     $rel = new Relationship($this->client);
     $rel->setType('TEST')->setStartNode($startNode)->setEndNode($endNode);
     $deleteNode = new Node($this->client);
     $deleteNode->setId(987);
     $deleteRel = new Relationship($this->client);
     $deleteRel->setId(321);
     $addIndexNode = new Node($this->client);
     $addIndexNode->setId(654);
     $removeIndexNode = new Node($this->client);
     $removeIndexNode->setId(209);
     $index = new Index($this->client, Index::TypeNode, 'indexname');
     $request = array(array('id' => 0, 'method' => 'POST', 'to' => '/node', 'body' => null), array('id' => 1, 'method' => 'PUT', 'to' => '/node/456/properties', 'body' => array()), array('id' => 2, 'method' => 'POST', 'to' => '{0}/relationships', 'body' => array('to' => $this->endpoint . '/node/456', 'type' => 'TEST')), array('id' => 3, 'method' => 'DELETE', 'to' => '/node/987'), array('id' => 4, 'method' => 'DELETE', 'to' => '/relationship/321'), array('id' => 5, 'method' => 'POST', 'to' => '/index/node/indexname', 'body' => array('key' => 'addkey', 'value' => 'addvalue', 'uri' => $this->endpoint . '/node/654')), array('id' => 6, 'method' => 'DELETE', 'to' => '/index/node/indexname/removekey/removevalue/209'));
     $return = array('code' => 200, 'data' => array(array('id' => 0, 'location' => 'http://foo:1234/db/data/node/123'), array('id' => 1), array('id' => 2, 'location' => 'http://foo:1234/db/data/relationship/789'), array('id' => 3), array('id' => 4), array('id' => 5), array('id' => 6)));
     $this->setupTransportExpectation($request, $this->returnValue($return));
     $batch = $this->client->startBatch();
     $this->assertInstanceOf('Sgpatil\\Orientphp\\Batch', $batch);
     $startNode->save();
     $endNode->save();
     $rel->save();
     $deleteNode->delete();
     $deleteRel->delete();
     $index->add($addIndexNode, 'addkey', 'addvalue');
     $index->remove($removeIndexNode, 'removekey', 'removevalue');
     $this->assertTrue($this->client->commitBatch());
     $this->assertEquals(789, $rel->getId());
     $this->assertEquals(123, $startNode->getId());
 }
Esempio n. 4
0
 /**
  * Load the given relationship with data from the server
  *
  * @param Relationship $rel
  * @return boolean
  */
 public function loadRelationship(Relationship $rel)
 {
     $cached = $this->getEntityCache()->getCachedEntity($rel->getId(), 'relationship');
     if ($cached) {
         $rel->setProperties($cached->getProperties());
         return true;
     }
     return $this->runCommand(new Command\GetRelationship($this, $rel));
 }
 public function execute()
 {
     if (!$this->safeToRun('uk-mp-candidates')) {
         $this->printDebug('Script already running');
         die;
     }
     // Get (or create) the UK local Network
     $uk = Doctrine::getTable('LsList')->findOneByName('United Kingdom');
     if (!$uk) {
         $uk = new LsList();
         $uk->name = 'United Kingdom';
         $uk->is_network = 1;
         $uk->description = 'People and organizations with significant influence on the policies of the United Kingdom';
         $uk->display_name = 'uk';
         $uk->save();
     }
     // Get the MP list
     $raw = $this->getMPs();
     // Add new MPs to the list
     foreach ($raw as $mp) {
         $this->printDebug(sprintf('Processing %s', $mp['name']));
         // Split name
         $entity = PersonTable::parseFlatName($mp['name']);
         $entity->blurb = 'Prospective Parliamentary Candidate for ' . $mp['constituency'];
         $q = TagTable::getByTripleQuery('yournextmp', 'url', $mp['url']);
         $r = $q->count();
         if ($r) {
             $this->printDebug('Already processed, skipping.');
             continue;
         }
         // Get political party
         $q = EntityTable::getByExtensionQuery('PoliticalParty')->addWhere('e.name = ?', $mp['party']);
         if (!($partyEntity = $q->fetchOne())) {
             $partyEntity = new Entity();
             $partyEntity->addExtension('Org');
             $partyEntity->addExtension('PoliticalParty');
             $partyEntity->name = $mp['party'];
             $partyEntity->blurb = 'UK Political Party';
             $partyEntity->save(null, true, array($uk->id));
             $this->printDebug("Created new political party: " . $mp['party']);
         }
         // Save entity to UK Network
         $entity->party_id = $partyEntity->id;
         $entity->save(null, true, array($uk->id));
         // Add party relationship
         $r = new Relationship();
         $r->entity1_id = $entity->id;
         $r->entity2_id = $partyEntity->id;
         $r->setCategory('Membership');
         $r->description1 = 'Prospective parliamentary candidate';
         $r->is_current = true;
         // $r->start_date = // Don't know where we can get this, and "now" seems kind of wrong
         $r->save();
         // Add YourNextMP triple
         $entity->addTagByTriple('yournextmp', 'url', $mp['url']);
         // Add references
         $ref = new Reference();
         $ref->addFields(array('name_first', 'name_last', 'name_middle'));
         // Don't need this
         $ref->source = $mp['url'];
         $ref->name = 'YourNextMP.com - ' . $entity['name'];
         $ref->object_model = 'Entity';
         $ref->object_id = $entity->getId();
         $ref->save();
         unset($ref);
         $ref = new Reference();
         $ref->addFields(array('name'));
         $ref->source = $mp['party_url'];
         $ref->name = 'YourNextMP.com - ' . $partyEntity['name'];
         $ref->object_model = 'Entity';
         $ref->object_id = $partyEntity->getId();
         $ref->save();
         unset($ref);
         $ref = new Reference();
         $ref->addFields(array('name'));
         $ref->source = $mp['url'];
         $ref->name = 'YourNextMP.com - ' . $entity['name'];
         $ref->object_model = 'Relationship';
         $ref->object_id = $r->getId();
         $ref->save();
         unset($ref);
         $r->free(true);
         unset($r);
         // Add image?
         if ($mp['image']) {
             if ($fileName = ImageTable::createFiles($mp['image'])) {
                 //insert image record
                 $image = new Image();
                 $image->filename = $fileName;
                 $image->title = $entity['name'];
                 $image->caption = 'From YourNextMP under CC-BY-SA license.';
                 $image->is_featured = true;
                 $image->is_free = true;
                 $image->url = $mp['image'];
                 $this->printDebug("Imported image: " . $image->filename);
             }
             $image->Entity = $entity;
             $image->save();
             if ($mp['image']) {
                 //save image source
                 $image->addReference($mp['image']);
                 $this->printDebug("Saved image reference");
             }
             unset($image);
         }
         // Add party image?
         if ($mp['party_image']) {
             if ($fileName = ImageTable::createFiles($mp['party_image'])) {
                 //insert image record
                 $partyImage = new Image();
                 $partyImage->filename = $fileName;
                 $partyImage->title = $partyEntity['name'];
                 $partyImage->caption = 'From YourNextMP under CC-BY-SA license.';
                 $partyImage->is_featured = true;
                 $partyImage->is_free = true;
                 $partyImage->url = $mp['party_image'];
                 $this->printDebug("Imported image: " . $partyImage->filename);
             }
             $partyImage->Entity = $partyEntity;
             $partyImage->save();
             if ($mp['party_image']) {
                 //save image source
                 $partyImage->addReference($mp['party_image']);
                 $this->printDebug("Saved image reference");
             }
             unset($partyImage);
         }
         unset($entity);
         unset($partyEntity);
     }
 }