public function findOrCreate($edge, $vIn, $vOut) { if (!$edge || !$vIn || !$vOut) { throw new \Exception('Invalid arguments'); } $vertex = new Vertex(); // findOrCreate origin vertex $vertex->setSufix('in'); $query = $vertex->findOrCreate($vIn->label, $vIn->properties, false); $vertex->prepareQuery($vIn->label, $vIn->properties); // findOrCreate target vertex $vertex->setSufix('out'); $query .= $vertex->findOrCreate($vOut->label, $vOut->properties, false); $vertex->prepareQuery($vOut->label, $vOut->properties); //create edge betweeen vertices $edgeProperties = ParserProperties::parsePropertiesToInsert(false, $edge->properties); $query .= "vin.addEdge('{$edge->label}', vout"; if (strlen($edgeProperties)) { $query .= ",{$edgeProperties});"; $this->prepareQuery(false, $edge->properties); } else { $query .= ');'; } //die($query); return $this->executeQuery($query); }
public function insert($label = false, $properties, $sendCommand = false) { $query = 'g.addV('; $sufix = $this->getSufix(); if ($label) { $query .= "T.label,BIND_LABEL{$sufix}"; } $parserProperties = ParserProperties::parsePropertiesToInsert($label, $properties, $this->getSufix()); $query .= "{$parserProperties})"; if ($sendCommand) { $this->prepareQuery($label, $properties); return $this->executeQuery($query); } return $query; }