euromark 11 years ago
parent
commit
cdd2e8636b
3 changed files with 17 additions and 15 deletions
  1. 1 6
      Controller/QloginController.php
  2. 8 5
      Lib/GeocodeLib.php
  3. 8 4
      Test/Case/Lib/GeocodeLibTest.php

+ 1 - 6
Controller/QloginController.php

@@ -76,12 +76,7 @@ class QloginController extends ToolsAppController {
 				$this->request->data = array();
 			}
 		} else {
-			if (!empty($this->request->params['named']['user_id'])) {
-				$this->request->data['Qlogin']['user_id'] = $this->request->params['named']['user_id'];
-			}
-			if (!empty($this->request->params['named']['url'])) {
-				$this->request->data['Qlogin']['url'] = base64_decode($this->request->params['named']['url']);
-			}
+			$this->request->data['Qlogin'] = $this->request->query;
 		}
 
 		$this->User = ClassRegistry::init(CLASS_USER);

+ 8 - 5
Lib/GeocodeLib.php

@@ -567,7 +567,6 @@ class GeocodeLib {
 		// handle and organize address_components
 		$components = array();
 		foreach ($record['address_components'] as $c) {
-			$types = array();
 			$type = $c['types'][0];
 			$types = $c['types'];
 
@@ -717,14 +716,18 @@ class GeocodeLib {
 	 *
 	 * @param array pointX
 	 * @param array pointY
-	 * @param float $unit (M=miles, K=kilometers, N=nautical miles, I=inches, F=feet)
+	 * @param string $unit Unit char or constant (M=miles, K=kilometers, N=nautical miles, I=inches, F=feet)
 	 * @return int Distance in km
 	 */
 	public function distance(array $pointX, array $pointY, $unit = null) {
-		if (empty($unit) || !array_key_exists(($unit = strtoupper($unit)), $this->units)) {
+		if (empty($unit)) {
 			$unit = array_keys($this->units);
 			$unit = $unit[0];
 		}
+		$unit = strtoupper($unit);
+		if (!isset($this->units[$unit])) {
+			throw new CakeException(__('Invalid Unit: %s', $unit));
+		}
 
 		$res = $this->calculateDistance($pointX, $pointY);
 		if (isset($this->units[$unit])) {
@@ -760,8 +763,8 @@ class GeocodeLib {
 	 * Convert between units
 	 *
 	 * @param float $value
-	 * @param char $fromUnit (using class constants)
-	 * @param char $toUnit (using class constants)
+	 * @param string $fromUnit (using class constants)
+	 * @param string $toUnit (using class constants)
 	 * @return float convertedValue
 	 * @throws CakeException
 	 */

+ 8 - 4
Test/Case/Lib/GeocodeLibTest.php

@@ -116,6 +116,7 @@ class GeocodeLibTest extends MyCakeTestCase {
 		$is = $this->Geocode->geocode($address);
 		$this->assertTrue($is);
 		$res = $this->Geocode->getResult();
+		$this->assertNotEmpty($res);
 
 		$is = $this->Geocode->isInconclusive();
 		$this->assertFalse($is);
@@ -185,10 +186,15 @@ class GeocodeLibTest extends MyCakeTestCase {
 
 		foreach ($coords as $coord) {
 			$is = $this->Geocode->distance($coord['x'], $coord['y']);
-			//echo $coord['name'].':';
-			//pr('is: '.$is.' - expected: '.$coord['d']);
 			$this->assertEquals($coord['d'], $is);
 		}
+
+		$is = $this->Geocode->distance($coords[0]['x'], $coords[0]['y'], GeocodeLib::UNIT_MILES);
+		$this->assertEquals(142, $is);
+
+		// String directly
+		$is = $this->Geocode->distance($coords[0]['x'], $coords[0]['y'], 'F');
+		$this->assertEquals(747236, $is);
 	}
 
 	/**
@@ -222,8 +228,6 @@ class GeocodeLibTest extends MyCakeTestCase {
 		);
 		foreach ($values as $value) {
 			$is = $this->Geocode->convert($value[0], $value[1], $value[2]);
-			//echo $value[0].$value[1].' in '.$value[2].':';
-			//pr('is: '.returns($is).' - expected: '.$value[3]);
 			$this->assertEquals($value[3], round($is, 8));
 		}
 	}