Skip to content
Browse files

added support for spherical option in geonear request, updated phpuni…

…t tests
  • Loading branch information...
1 parent 59b9ec3 commit d734f2e3093ad8318da7b7a5a15eb7c8fc2c7687 @t0k4rt t0k4rt committed with jmikola Jul 30, 2012
View
12 lib/Doctrine/MongoDB/Query/Builder.php
@@ -598,6 +598,18 @@ public function maxDistance($maxDistance)
}
/**
+ * Set the "spherical" option for a geoNear command query.
+ *
+ * @param bool $spherical
+ * @return Builder
+ */
+ public function spherical($spherical = true)
+ {
+ $this->query['geoNear']['spherical'] = $spherical;
+ return $this;
+ }
+
+ /**
* Add where $near query.
*
* @param string $x
View
2 lib/Doctrine/MongoDB/Query/Query.php
@@ -217,7 +217,7 @@ public function execute()
$this->options['num'] = $this->query['limit'];
}
- foreach (array('distanceMultiplier', 'maxDistance') as $key) {
+ foreach (array('distanceMultiplier', 'maxDistance', 'spherical') as $key) {
if (isset($this->query['geoNear'][$key]) && $this->query['geoNear'][$key]) {
$this->options[$key] = $this->query['geoNear'][$key];
}
View
2 tests/Doctrine/MongoDB/Tests/Query/BuilderTest.php
@@ -433,6 +433,7 @@ public function testGeoNearQuery()
->geoNear(50, 50)
->distanceMultiplier(2.5)
->maxDistance(5)
+ ->spherical(true)
->field('type')->equals('restaurant')
->limit(10);
@@ -445,6 +446,7 @@ public function testGeoNearQuery()
$this->assertEquals(array(50, 50), $geoNear['near']);
$this->assertEquals(2.5, $geoNear['distanceMultiplier']);
$this->assertEquals(5, $geoNear['maxDistance']);
+ $this->assertEquals(true, $geoNear['spherical']);
$this->assertEquals(10, $qb->debug('limit'));
$this->assertInstanceOf('Doctrine\MongoDB\ArrayIterator', $qb->getQuery()->execute());
}
View
2 tests/Doctrine/MongoDB/Tests/Query/QueryTest.php
@@ -50,6 +50,7 @@ public function testGeoNearOptionsArePassed()
'near' => array(50, 50),
'distanceMultiplier' => 2.5,
'maxDistance' => 5,
+ 'spherical' => true,
),
'limit' => 10,
'query' => array('altitude' => array('$gt' => 1)),
@@ -70,6 +71,7 @@ public function testGeoNearOptionsArePassed()
$this->logicalAnd(
new ArrayHasValueUnderKey('distanceMultiplier', 2.5),
new ArrayHasValueUnderKey('maxDistance', 5),
+ new ArrayHasValueUnderKey('spherical', true),
new ArrayHasValueUnderKey('num', 10)
)
);

0 comments on commit d734f2e

Please sign in to comment.
Something went wrong with that request. Please try again.