Exemplo n.º 1
0
 /**
  * @param Node $node
  * @param $relation
  * @return array
  */
 private function getRelationsFrom($node, $relation)
 {
     // Cache sequential calls for the same element
     static $loaded = null, $existing;
     if ($loaded !== $node) {
         $command = new Extension\GetNodeRelationshipsLight($this->client, $node);
         $existing = $command->execute();
         $loaded = $node;
     }
     return array_filter($existing, function ($entry) use($relation) {
         return $entry['type'] == $relation;
     });
 }
Exemplo n.º 2
0
 function addRelation($relation, $a, $b)
 {
     static $loaded = null, $existing;
     $a = $this->nodes[$this->getHash($a)];
     $b = $this->nodes[$this->getHash($b)];
     if ($loaded !== $a) {
         $command = new Extension\GetNodeRelationshipsLight($this->client, $a);
         $existing = $command->execute();
         $loaded = $a;
     }
     foreach ($existing as $r) {
         if ($r['type'] == $relation && basename($r['end']) == $b->getId()) {
             return;
         }
     }
     $a->relateTo($b, $relation)->setProperty('creationDate', $this->getCurrentDate())->save();
     list($relation, $a, $b) = func_get_args();
     $this->triggerEvent(self::RELATION_CREATE, $relation, $a, $b);
 }