Beispiel #1
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();
 }
Beispiel #2
0
 /**
  * Set a given relationship on this relation.
  *
  * @param \Everyman\Neo4j\Relationship $relation
  */
 public function setRelation(Relationship $relation, $debug = false)
 {
     // Set the relation object.
     $this->relation = $relation;
     // Replace the attributes with those brought from the given relation.
     $this->attributes = $relation->getProperties();
     $this->setAttribute($this->primaryKey, $relation->getId());
     // Set the start and end nodes.
     $this->start = $relation->getStartNode();
     $this->end = $relation->getEndNode();
     // Instantiate and fill out the related model.
     $relatedNode = $this->isDirectionOut() ? $this->end : $this->start;
     $attributes = array_merge(['id' => $relatedNode->getId()], $relatedNode->getProperties());
     // This is an existing relationship.
     $exists = true;
     $this->related = $this->related->newFromBuilder($attributes, $exists);
     $this->related->setConnection($this->related->getConnection());
 }
Beispiel #3
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;
 }