浏览代码

documentation and cleanup

euromark 12 年之前
父节点
当前提交
e4cdadf389
共有 4 个文件被更改,包括 48 次插入39 次删除
  1. 24 8
      Lib/GeocodeLib.php
  2. 18 3
      Lib/Utility/FileLib.php
  3. 1 23
      Model/Behavior/GeocoderBehavior.php
  4. 5 5
      Model/MyModel.php

+ 24 - 8
Lib/GeocodeLib.php

@@ -187,7 +187,8 @@ class GeocodeLib {
 	 * @return string $url (full)
 	 * 2010-06-29 ms
 	 */
-	public function url() {		$params = array(
+	public function url() {
+		$params = array(
 			'host' => $this->options['host'],
 			'output' => $this->options['output']
 		);
@@ -351,16 +352,16 @@ class GeocodeLib {
 	}
 
 	/**
+	 * Actual querying
+	 *
 	 * @param string $address
-	 * @param array $settings
-	 * - allow_inconclusive
-	 * - min_accuracy
-	 * @return boolean $success
+	 * @param array $params
+	 * @return boolean Success
 	 * 2010-06-25 ms
 	 */
-	public function geocode($address, $settings = array()) {
+	public function geocode($address, $params = array()) {
 		$this->reset(false);
-		$this->setParams(array_merge($settings, array('address'=>$address)));
+		$this->setParams(array_merge($params, array('address'=>$address)));
 		if ($this->options['allow_inconclusive']) {
 			# only host working with this setting?
 			//$this->options['host'] = self::DEFAULT_HOST;
@@ -402,7 +403,6 @@ class GeocodeLib {
 					$xmlArray['result'] = $xmlArray['results'];
 				}
 				unset($xmlArray['results']);
-				//die(debug($xmlArray));
 
 			} else {
 				try {
@@ -499,6 +499,22 @@ class GeocodeLib {
 	}
 
 	/**
+	 * GeocodeLib::accuracyTypes()
+	 *
+	 * @param mixed $value
+	 * @return mixed Type or types
+	 */
+	public function accuracyTypes($value = null) {
+		if ($value !== null) {
+			if (isset($this->accuracyTypes[$value])) {
+				return $this->accuracyTypes[$value];
+			}
+			return null;
+		}
+		return $this->accuracyTypes;
+	}
+
+	/**
 	 * @return bool $success
 	 */
 	protected function _isNotAccurateEnough($accuracy = null) {

+ 18 - 3
Lib/Utility/FileLib.php

@@ -43,6 +43,13 @@ class FileLib extends File {
 	/**
 	 * A better csv reader which handles encoding as well as removes completely empty lines
 	 *
+	 * @param int $length (0 = no limit)
+	 * @param string $delimiter (null defaults to ,)
+	 * @param string $enclosure (null defaults to " - do not pass empty string)
+	 * @param string $mode
+	 * @param string $force Force open/read the file
+	 * @param boolean $removeEmpty Remove empty lines (simple newline characters without meaning)
+	 * @return array Content or false on failure
 	 * 2009-06-15 ms
 	 */
 	public function readCsv($length = 0, $delimiter = null, $enclosure = null, $mode = 'rb', $force = false, $removeEmpty = false) {
@@ -115,7 +122,9 @@ class FileLib extends File {
 	 * Write an array to a csv file
 	 *
 	 * @param array $data
-	 * @return bool $success
+	 * @param string $delimiter (null defaults to ,)
+	 * @param string $enclosure (null defaults to " - do not pass empty string)
+	 * @return bool Success
 	 * 2012-07-06 ms
 	 */
 	public function writeCsv($data, $delimiter = null, $enclosure = null) {
@@ -141,6 +150,12 @@ class FileLib extends File {
 	}
 
 	/**
+	 * Read files with fscanf() and pattern
+	 *
+	 * @param string $format (e.g. "%s\t%s\t%s\n")
+	 * @param string $mode
+	 * @param string $force Force open/read the file
+	 * @return array Content or false on failure
 	 * 2009-06-15 ms
 	 */
 	public function readWithPattern($format = null, $mode = 'rb', $force = false) {
@@ -244,8 +259,8 @@ class FileLib extends File {
 	/**
 	 * Assert proper encoding
 	 *
-	 * @param array
-	 * @return array
+	 * @param array Input
+	 * @return array Output
 	 */
 	protected function _encode(array $array) {
 		$convertedArray = array();

+ 1 - 23
Model/Behavior/GeocoderBehavior.php

@@ -44,7 +44,7 @@ class GeocoderBehavior extends ModelBehavior {
 			'require' => false, 'allowEmpty' => true, 'invalidate' => array(), 'expect' => array(),
 			'lat' => 'lat', 'lng' => 'lng', 'formatted_address' => 'formatted_address', 'host' => null, 'language' => 'de', 'region' => '', 'bounds' => '',
 			'overwrite' => false, 'update' => array(), 'before' => 'save',
-			'min_accuracy' => 0, 'allow_inconclusive' => true, 'unit' => GeocodeLib::UNIT_KM,
+			'min_accuracy' => GeocodeLib::ACC_COUNTRY, 'allow_inconclusive' => true, 'unit' => GeocodeLib::UNIT_KM,
 			'log' => true, // log successfull results to geocode.log (errors will be logged to error.log in either case)
 		);
 
@@ -133,14 +133,6 @@ class GeocoderBehavior extends ModelBehavior {
 			}
 			*/
 
-			//pr($geocode);
-			//pr($this->Geocode->getResult());
-			// Now set the geocode as part of the model data to be saved, making sure that
-			// we are on the white list of fields to be saved
-			//pr ($Model->whitelist); die();
-
-			//pr($geocode); die();
-
 			# if both are 0, thats not valid, otherwise continue
 			if (!empty($geocode['lat']) || !empty($geocode['lng'])) { /** HACK to prevent 0 inserts of incorrect runs - 2009-04-07 ms */
 				$Model->data[$Model->alias][$this->settings[$Model->alias]['lat']] = $geocode['lat'];
@@ -184,20 +176,6 @@ class GeocoderBehavior extends ModelBehavior {
 					}
 				}
 			}
-
-			# correct country id if necessary
-			/*
-			if (in_array('country_name', $this->settings[$Model->alias]['address'])) {
-				App::uses('Country', 'Tools.Model');
-
-				if (!empty($geocode['country']) && in_array($geocode['country'], ($countries = Country::addressList()))) {
-					$countries = array_shift(array_keys($countries, $geocode['country']));
-					$Model->data[$Model->alias]['country'] = $countries;
-				} else {
-					$Model->data[$Model->alias]['country'] = 0;
-				}
-			}
-			*/
 		}
 
 		return $return;

+ 5 - 5
Model/MyModel.php

@@ -315,7 +315,6 @@ class MyModel extends Model {
 		return $this->save($data, false);
 	}
 
-
 	/**
 	 * improve paginate count for "normal queries"
 	 * @deprecated?
@@ -332,7 +331,6 @@ class MyModel extends Model {
 		return $this->find('count', array_merge($conditions, $extra));
 	}
 
-
 	/**
 	 * return the next auto increment id from the current table
 	 * UUIDs will return false
@@ -1360,7 +1358,7 @@ class MyModel extends Model {
 	 * @deprecated
 	 */
 	public function umlautsOrderFix($var) {
-		return "REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(".$var.", 'Ä', 'Ae'), 'Ö', 'Oe'), 'Ü', 'Ue'), 'ä', 'ae'), 'ö', 'oe'), 'ü','ue'), 'ß', 'ss')";
+		return "REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(".$var.", 'Ä', 'Ae'), 'Ö', 'Oe'), 'Ü', 'Ue'), 'ä', 'ae'), 'ö', 'oe'), 'ü','ue'), 'ß', 'ss')";
 	}
 
 
@@ -1592,9 +1590,10 @@ class MyModel extends Model {
 
 
 	/**
-	 * automagic increasing of a field with e.g.:
+	 * Automagic increasing of a field with e.g.:
 	 * $this->id = ID; $this->inc('weight',3);
-	 * @deprecated use updateAll() instead!
+	 *
+	 * @deprecated use atomic updateAll() instead!
 	 * @param string fieldname
 	 * @param int factor: defaults to 1 (could be negative as well - if field is signed and can be < 0)
 	 */
@@ -1657,6 +1656,7 @@ class MyModel extends Model {
 	 * from http://othy.wordpress.com/2006/06/03/generatenestedlist/
 	 * NEEDS parent_id
 	 * //TODO refactor for 1.2
+	 *
 	 * @deprecated use generateTreeList instead
 	 * 2009-08-12 ms
 	 */