Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
added support for spherical option in geonear request, updated phpuni…
Browse files Browse the repository at this point in the history
…t tests
  • Loading branch information
t0k4rt authored and jmikola committed Jul 30, 2012
1 parent 59b9ec3 commit d734f2e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/Doctrine/MongoDB/Query/Builder.php
Expand Up @@ -597,6 +597,18 @@ public function maxDistance($maxDistance)
return $this;
}

/**
* 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.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/MongoDB/Query/Query.php
Expand Up @@ -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];
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Doctrine/MongoDB/Tests/Query/BuilderTest.php
Expand Up @@ -433,6 +433,7 @@ public function testGeoNearQuery()
->geoNear(50, 50)
->distanceMultiplier(2.5)
->maxDistance(5)
->spherical(true)
->field('type')->equals('restaurant')
->limit(10);

Expand All @@ -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());
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Doctrine/MongoDB/Tests/Query/QueryTest.php
Expand Up @@ -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)),
Expand All @@ -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)
)
);
Expand Down

0 comments on commit d734f2e

Please sign in to comment.