/** * Finds objects by a set of criteria. * * Optionally sorting and limiting details can be passed. An implementation may throw * an UnexpectedValueException if certain values of the sorting or limiting details are * not supported. * * @param array $criteria * @param array|null $orderBy * @param int|null $limit * @param int|null $offset * @return mixed The objects. */ public function findBy(array $criteria, array $orderBy = array(), $limit = null, $offset = null) { $results = array(); foreach ($this->getOrientClasses() as $mappedClass) { $query = new Query(array($mappedClass)); foreach ($criteria as $key => $value) { $query->where("$key = ?", $value); } foreach ($orderBy as $key => $order) { $query->orderBy("$key $order"); } if ($limit) { $query->limit($limit); } $collection = $this->getManager()->execute($query); if (!is_array($collection)) { $message = <<<EOT Problems executing the query "{$query->getRaw()}". The server returned $collection, while it should be an Array. EOT; throw new Exception($message); } $results = array_merge($results, $collection); } return $results; }