/** * Get the id of the to node by checking for it in the actual _from property or checking an internal property. * This is used because when documents are retrieved from the server, we will not have a model in the _from property. * This allows us to lazy load any vertices we need later. * @return null|string */ public function getFromId() { if (isset($this->_from)) { return $this->_from->getPod()->getId(); } elseif (isset($this->_data['_from'])) { return $this->_data['_from']; } else { return null; } }
/** * Convience function to turn a AModel or array of coordinates into an acceptable associative array for find*Near() methods. * @param AModel|array $reference The reference point. This can be a model or an associative array containing latitude and longitude keys. * @throws FinderException * @return array */ private function generateReferenceData($reference) { if ($reference instanceof AModel) { $coordinates = $reference->getPod()->getCoordinates(); if (!$coordinates) { throw new FinderException("To use a pod as a reference point, it must have a geo index on its collection and have coordinates assigned."); } $coordinates['podId'] = $reference->getPod()->getId(); } elseif (is_array($reference)) { if (count($reference) == 2 && array_key_exists('latitude', $reference) && array_key_exists('longitude', $reference)) { $coordinates = $reference; $coordinates['podId'] = null; } else { throw new FinderException('$position array passed to findNear() must contain 2 keys: latitude and longitude.'); } } else { throw new FinderException('$position must be either an instance of AModel or an array containing the latitude and longitude.'); } return $coordinates; }
/** * Convinence function that gets the document id (handle) from models, vertex pods and strings. * @param Document|AModel|string $model * @throws GraphManagerException */ protected function getVertexId($model) { if ($model instanceof AModel) { return $model->getPod()->getId(); } elseif ($model instanceof Document) { return $model->getId(); } elseif (is_string($model)) { return $model; } else { throw new GraphManagerException('$model can be either a model, a vertex pod or the id of the vertex.'); } }