/** * Proxy creation to a cypher query that does what we want * * @param Client $client * @param Node $node * @param array $labels * @param boolean $remove */ public function __construct(Client $client, Node $node, $labels, $remove = false) { if (!$client->hasCapability(Client::CapabilityLabel)) { throw new \RuntimeException('The connected Neo4j version does not have label capability'); } $nodeId = $node->getId(); if (!is_numeric($nodeId)) { throw new \InvalidArgumentException("Cannot set labels on an unsaved node"); } if (!$labels) { throw new \InvalidArgumentException("No labels given to set on node"); } $labelSet = implode(':', array_map(function ($label) { if (!$label instanceof Label) { throw new \InvalidArgumentException("Cannot set a non-label"); } $name = str_replace('`', '``', $label->getName()); return "`{$name}`"; }, $labels)); $setCommand = $remove ? 'REMOVE' : 'SET'; $query = "START n=node({nodeId}) {$setCommand} n:{$labelSet} RETURN labels(n) AS labels"; $params = array('nodeId' => $nodeId); $cypher = new Query($client, $query, $params); parent::__construct($client, $cypher); }
public static function fromArray(Node $node) { $tag = new Tag(); $tag->id = $node->getId(); $tag->tagcontent = $node->getProperty('tagcontent'); $tag->node = $node; return $user; }
/** * Gather the properties of a Node including its id. * * @param \Everyman\Neo4j\Node $node * @return array */ public function getNodeAttributes(Node $node) { // Extract the properties of the node $attributes = $node->getProperties(); // Add the node id to the attributes since \Everyman\Neo4j\Node // does not consider it to be a property, it is treated differently // and available through the getId() method. $attributes[$this->model->getKeyName()] = $node->getId(); return $attributes; }
/** * @param Node $node * @return Node */ public function load($node) { if (!isset($this->loadedNodes[$node->getId()])) { $em = $this; $entity = $this->proxyFactory->fromNode($node, $this->metaRepository, function ($node) use($em) { return $em->load($node); }); $this->loadedNodes[$node->getId()] = $entity; $this->nodes[$this->getHash($entity)] = $node; } return $this->loadedNodes[$node->getId()]; }
/** * Loads a node using a proxy. * * Loads a node using a proxy, and stores it in the appropriate places in the entity manager. * * @param \Everyman\Neo4J\Node $node The node to load. * @return mixed The entity itself. */ public function loadNode($node) { //If the node isn't already loaded if (!isset($this->nodeProxyCache[$node->getId()])) { //Get the nodes class name (from label) $labels = $this->client->getLabels($node); $class = $labels[0]->getName(); //Create a proxy entity $entity = $this->proxyFactory->fromNode($node, $this->metaRepository, $class); $this->nodeProxyCache[$node->getId()] = $entity; $this->everymanNodeCache[$this->getHash($entity)] = $node; } return $this->nodeProxyCache[$node->getId()]; }
/** * Hydrate a Collection from an Neo4J Node * * @param \Everyman\Neo4j\Node $row a single row from result set to map. * @return Collection */ protected function nodeToCollection(\EveryMan\Neo4j\Node $row) { // Or we map a single record to a Spider Record $collection = new Collection(); foreach ($row->getProperties() as $key => $value) { $collection->add($key, $value); } //handle labels $labels = $row->getLabels(); if (!empty($labels)) { $collection->add(['meta.label' => $labels[0]->getName(), 'label' => $labels[0]->getName()]); } $collection->add(['meta.id' => $row->getId(), 'id' => $row->getId()]); $collection->protect('meta'); $collection->protect('id'); $collection->protect('label'); return $collection; }
public function wrap(Neo4j\Node $client_node) { return new Node($this, $client_node->getId(), $client_node); }
/** * Create User object from Node * * @param Node $node User node * @return User */ protected static function fromNode(Node $node) { $user = new User(); $user->id = $node->getId(); $user->username = $node->getProperty('username'); $user->firstname = $node->getProperty('firstname'); $user->lastname = $node->getProperty('lastname'); $user->node = $node; return $user; }
/** * Creates Content instance from a content node * * @param Node $node Content node * @param string $username Username for post * @param string $owner Content owner * @return Content */ protected static function createFromNode(Node $node, $username = null, $owner = false) { $content = new Content(); $content->node = $node; $content->nodeId = $node->getId(); $content->contentId = $node->getProperty('contentId'); $content->title = $node->getProperty('title'); $content->url = $node->getProperty('url'); $content->tagstr = $node->getProperty('tagstr'); $content->timestamp = gmdate("F j, Y g:i a", $node->getProperty('timestamp')); $content->owner = $owner; $content->userNameForPost = $username; return $content; }