Paradox/toolbox/GraphManager.php
public function getNeighbours($model, $direction = "any", $labels = null, $aql = "", $params = array(), $placeholder = "doc")
    {
        $id = $this->getVertexId($model);

        if (!$id) {
            return array();
        }

        if (strtolower($direction) == "in") {
            $direction = "inbound";
        }

        if (strtolower($direction) == "out") {
            $direction = "outbound";
        }

        if ($labels && !is_array($labels)) {
            $labels = array($labels);
        }

        $vertexCollection = $this->_toolbox->generateBindingParameter('@vertexCollection', $params);
        $edgeCollection = $this->_toolbox->generateBindingParameter('@edgeCollection', $params);
        $vertexParameter = $this->_toolbox->generateBindingParameter('vertexid', $params);
        $directionParameter = $this->_toolbox->generateBindingParameter('direction', $params);

        if (!$labels) {
            $query = "FOR $placeholder in NEIGHBORS(@$vertexCollection, @$edgeCollection, @$vertexParameter, @$directionParameter) " . $aql . " return $placeholder.vertex";
        } else {
            $count = 0;

            $labelString = '';

            foreach ($labels as $label) {
                $labelParameter = $this->_toolbox->generateBindingParameter('label', $params);

                if ($count > 0) {
                    $labelString .= ", ";
                }

                $labelString .= "{'\$label': @$labelParameter}";

                $params[$labelParameter] = $label;
                $count++;
            }

            $query = "FOR $placeholder in NEIGHBORS(@$vertexCollection, @$edgeCollection, @$vertexParameter, @$directionParameter, [$labelString]) " . $aql . " return $placeholder.vertex";
        }

        $params[$vertexCollection] = $this->_toolbox->getVertexCollectionName();
        $params[$edgeCollection] = $this->_toolbox->getEdgeCollectionName();
        $params[$vertexParameter] = $id;
        $params[$directionParameter] = $direction;

        if ($this->_toolbox->getTransactionManager()->hasTransaction()) {
            $this->_toolbox->getTransactionManager()->addReadCollection($this->_toolbox->getEdgeCollectionName());
            $this->_toolbox->getTransactionManager()->addReadCollection($this->_toolbox->getVertexCollectionName());
            $statement = json_encode(array('query' => $query, 'bindVars' => $params), JSON_FORCE_OBJECT);
            $this->_toolbox->getTransactionManager()->addCommand("db._createStatement($statement).execute().elements();", "GraphManager:getNeighbours", null, true);

        } else {
            try {
                $result = $this->_toolbox->getQuery()->getAll($query, $params);
            } catch (\Exception $e) {
                throw new GraphManagerException($e->getMessage(), $e->getCode());
            }

            if (empty($result)) {
                return array();
            }

            return $this->convertToPods("vertex", $result);
        }
    }
public function getNeighbours($model, $direction = "any", $labels = null, $aql = "", $params = array(), $placeholder = "doc")
    {
        $id = $this->getVertexId($model);

        if (!$id) {
            return array();
        }

        if (strtolower($direction) == "in") {
            $direction = "inbound";
        }

        if (strtolower($direction) == "out") {
            $direction = "outbound";
        }

        if ($labels && !is_array($labels)) {
            $labels = array($labels);
        }

        $vertexCollection = $this->_toolbox->generateBindingParameter('@vertexCollection', $params);
        $edgeCollection = $this->_toolbox->generateBindingParameter('@edgeCollection', $params);
        $vertexParameter = $this->_toolbox->generateBindingParameter('vertexid', $params);
        $directionParameter = $this->_toolbox->generateBindingParameter('direction', $params);

        if (!$labels) {
            $query = "FOR $placeholder in NEIGHBORS(@$vertexCollection, @$edgeCollection, @$vertexParameter, @$directionParameter) " . $aql . " return $placeholder.vertex";
        } else {
            $count = 0;

            $labelString = '';

            foreach ($labels as $label) {
                $labelParameter = $this->_toolbox->generateBindingParameter('label', $params);

                if ($count > 0) {
                    $labelString .= ", ";
                }

                $labelString .= "{'\$label': @$labelParameter}";

                $params[$labelParameter] = $label;
                $count++;
            }

            $query = "FOR $placeholder in NEIGHBORS(@$vertexCollection, @$edgeCollection, @$vertexParameter, @$directionParameter, [$labelString]) " . $aql . " return $placeholder.vertex";
        }

        $params[$vertexCollection] = $this->_toolbox->getVertexCollectionName();
        $params[$edgeCollection] = $this->_toolbox->getEdgeCollectionName();
        $params[$vertexParameter] = $id;
        $params[$directionParameter] = $direction;

        if ($this->_toolbox->getTransactionManager()->hasTransaction()) {
            $this->_toolbox->getTransactionManager()->addReadCollection($this->_toolbox->getEdgeCollectionName());
            $this->_toolbox->getTransactionManager()->addReadCollection($this->_toolbox->getVertexCollectionName());
            $statement = json_encode(array('query' => $query, 'bindVars' => $params), JSON_FORCE_OBJECT);
            $this->_toolbox->getTransactionManager()->addCommand("db._createStatement($statement).execute().elements();", "GraphManager:getNeighbours", null, true);

        } else {
            try {
                $result = $this->_toolbox->getQuery()->getAll($query, $params);
            } catch (\Exception $e) {
                throw new GraphManagerException($e->getMessage(), $e->getCode());
            }

            if (empty($result)) {
                return array();
            }

            return $this->convertToPods("vertex", $result);
        }
    }
Get the neighbour vertices connected to this vertex via some edge. The vertices and their connecting edges can be filtered by AQL.
@param Document|AModel|string A vertex pod, model or string of the vertex id.
@param  string       $direction   "in" for inbound neighbours, "out" for outbound neighbours and "any" for all neighbours.
@param  string|array $labels      A string representing one label or an array of labels we want the inbound edges to have.
@param  string       $aql         An optional AQL fragment if we want to filter the edges or vertices, for example:
FILTER doc.edge.someproperty == "somevalue" && doc.vertex.anotherproperty == "anothervalue"
@param  array        $params      An optional associative array containing parameters to bind to the query.
@param  string       $placeholder Set this to something else if you do not wish to use "doc" to refer to documents in your query.
@return array