/** * @param $fromUserId * @param $toUserId * @return \Everyman\Neo4j\Relationship * @throws \Everyman\Neo4j\Exception * @throws \Exception */ public function getPendingRelation($fromUserId, $toUserId) { $queryTemplate = "START to=node({$fromUserId}), from=node({$toUserId}) MATCH from-[relation:PENDING]->to RETURN relation"; $resultSet = $this->_neo4j->query($queryTemplate); $currentRow = $resultSet->current(); $relationId = $currentRow['relation']->getId(); return $this->getRelationById($relationId); }
/** * Remove user. * * @param string $id * @return Response * @throws \Everyman\Neo4j\Exception * @throws \Exception */ public function removeUser($id) { $user = $this->_neo4j->getClient()->getNode($id); if (is_null($user)) { return new Response("Unable to delete because the user does not exist.", Response::HTTP_BAD_REQUEST); } try { $user->delete(); return new Response(['id' => $id], Response::HTTP_OK); } catch (\Exception $e) { return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST); } }
/** * Return user list [id -> name] from request. * * @param string $queryTemplate Query template for neo4j request. * @return array */ private function _userListQuery($queryTemplate) { $resultSet = $this->_neo4j->query($queryTemplate); $result = array(); foreach ($resultSet as $node) { $userId = $node['user']->getId(); $userName = $node['user']->getProperty('name'); $result[$userId] = $userName; } return $result; }
/** * Remove all relations and nodes. * * @return \Everyman\Neo4j\Node * @throws \Everyman\Neo4j\Exception * @throws \Exception */ private function _flushDatabase() { $queryTemplate = "MATCH ()-[relation]->() RETURN relation"; $rows = $this->_neo4j->query($queryTemplate); foreach ($rows as $row) { $item = $this->_neo4j->getClient()->getRelationship($row['relation']->getId()); $this->_neo4j->getClient()->deleteRelationship($item); } $queryTemplate = "MATCH (node) RETURN node"; $rows = $this->_neo4j->query($queryTemplate); foreach ($rows as $row) { $node = $this->_neo4j->getClient()->getNode($row['node']->getId()); $this->_neo4j->getClient()->deleteNode($node); } return $node; }