Example #1
1
 /**
  * Determine whether this relation exists.
  *
  * @return boolean
  */
 public function exists()
 {
     if ($this->relation && $this->relation->hasId()) {
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Creates a proxy object for an Everyman relationship.
  *
  * This creates a proxy object for a Everyman relationship, given the meta repository.
  *
  * @param \Everyman\Neo4j\Relationship $relationship The node to create a proxy of.
  * @param \LRezek\Arachnid\Meta\Repository $repository The meta repository.
  * @param callable $loadCallback Callback for start/end node lazy loading.
  * @return mixed The proxy object.
  */
 function fromRelation($relationship, $repository, \Closure $loadCallback)
 {
     //Get the class name from the node, and the meta from that class name
     $class = $relationship->getType();
     //Create the proxy factory
     return $this->fromEntity($relationship, $class, $repository, $loadCallback);
 }
Example #3
0
 /**
  * Approve friend request.
  *
  * @param Relationship $relationship
  */
 public function approveFriendRequest(Relationship $relationship)
 {
     $startNode = $relationship->getStartNode();
     $endNode = $relationship->getEndNode();
     $relationship->delete();
     $startNode->relateTo($endNode, 'FRIENDS')->save();
     $endNode->relateTo($startNode, 'FRIENDS')->save();
 }
Example #4
0
 /**
  * Get the direction of a relationship out of a Relation instance.
  *
  * @param  \Everyman\Neo4j\Relationship $relation
  * @param  \Vinelab\NeoEloquent\Eloquent\Model        $parent
  * @param  \Vinelab\NeoEloquent\Eloquent\Model        $related
  * @return string Either 'in' or 'out'
  */
 public function directionFromRelation(Relationship $relation, Model $parent, Model $related)
 {
     // We will match the ids of the parent model and the start node of the relationship
     // and if they match we know that the direction is outgoing, incoming otherwise.
     $node = $relation->getStartNode();
     // We will start by considering the relationship direction to be 'incoming' until
     // we match and find otherwise.
     $direction = 'in';
     if ($node->getId() === $parent->getKey()) {
         $direction = 'out';
     }
     return $direction;
 }
Example #5
0
 /**
  * Loads a relation using a proxy.
  *
  * Loads a relation using a proxy, and stores it in the appropriate places in the entity manager.
  *
  * @param \Everyman\Neo4J\Relationship $relation The relation to load.
  * @return mixed The entity itself.
  */
 public function loadRelation($relation)
 {
     //If the node isn't already loaded
     if (!isset($this->relationProxyCache[$relation->getId()])) {
         //Create a proxy entity
         $em = $this;
         $entity = $this->proxyFactory->fromRelation($relation, $this->metaRepository, function ($node) use($em) {
             return $em->loadNode($node);
         });
         $this->relationProxyCache[$relation->getId()] = $entity;
         $this->everymanRelationCache[$this->getHash($entity)] = $relation;
     }
     return $this->relationProxyCache[$relation->getId()];
 }
Example #6
0
 public function envelopes(Neo4j\Relationship $client_edge)
 {
     return $client_edge->getType() === $this->getName();
 }