euromark 11 年 前
コミット
787abb9e48
3 ファイル変更32 行追加24 行削除
  1. 27 8
      Lib/CurrencyLib.php
  2. 0 14
      Model/MyModel.php
  3. 5 2
      Test/Case/Lib/CurrencyLibTest.php

+ 27 - 8
Lib/CurrencyLib.php

@@ -89,6 +89,23 @@ class CurrencyLib {
 	}
 
 	/**
+	 * CurrencyLib::history()
+	 *
+	 * @param string $date Date in Format XXXX-XX-XX
+	 * @return array
+	 */
+	public function history($date = null) {
+		$history = $this->_retrieveHistory();
+		if ($date) {
+			if (!empty($history[$date])) {
+				return $history[$date];
+			}
+			return array();
+		}
+		return $history;
+	}
+
+	/**
 	 * CurrencyComponent::isAvailable()
 	 *
 	 * @param mixed $currency
@@ -147,19 +164,21 @@ class CurrencyLib {
 
 		$currencies = $this->_loadXml(self::URL_HISTORY);
 
-		//Filter down to just the rates
-		$currencies = $currencies['Envelope']['Cube']['Cube']['Cube'];
+		// Filter down to just the rates
+		$dates = $currencies['Envelope']['Cube']['Cube'];
 
 		$historyList = array();
-		//European Central bank gives us everything against Euro so add this manually
-		$historyList[$this->baseCurrency] = 1;
-
-		foreach ($currencies as $currency) {
-			$historyList[$currency['currency']] = $currency['rate'];
+		foreach ($dates as $date) {
+			$time = $date['@time'];
+			foreach ($date['Cube'] as $currency) {
+				$historyList[$time][$currency['@currency']] = $currency['@rate'];
+				// European Central bank gives us everything against Euro so add this manually
+				$historyList[$time][$this->baseCurrency] = 1;
+			}
 		}
 
 		$this->_store($historyList, 'history');
-		return $currencyList;
+		return $historyList;
 	}
 
 	/**

+ 0 - 14
Model/MyModel.php

@@ -1270,20 +1270,6 @@ class MyModel extends Model {
 		return true;
 	}
 
-/** General Model Functions **/
-
-	/**
-	 * CAREFUL: use LIMIT due to Starker Serverlastigkeit! or CACHE it!
-	 *
-	 * e.g.: 'ORDER BY ".$this->umlautsOrderFix('User.nic')." ASC'
-	 *
-	 * @param string variable (to be correctly ordered)
-	 * @deprecated
-	 */
-	public function umlautsOrderFix($var) {
-		return "REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(" . $var . ", 'Ä', 'Ae'), 'Ö', 'Oe'), 'Ü', 'Ue'), 'ä', 'ae'), 'ö', 'oe'), 'ü','ue'), 'ß', 'ss')";
-	}
-
 	/**
 	 * Set + guaranteeFields!
 	 * Extends the core set function (only using data!!!)

+ 5 - 2
Test/Case/Lib/CurrencyLibTest.php

@@ -52,9 +52,7 @@ class CurrencyLibTest extends MyCakeTestCase {
 	 * @return void
 	 */
 	public function testTable() {
-		$this->out('<h2>Currency Table</h2>', true);
 		$is = $this->CurrencyLib->table();
-		$this->debug($is);
 		$this->assertTrue(is_array($is) && !empty($is));
 
 		$is = $this->CurrencyLib->table('XYZ');
@@ -63,6 +61,11 @@ class CurrencyLibTest extends MyCakeTestCase {
 		$this->assertTrue($this->CurrencyLib->cacheFileUsed());
 	}
 
+	public function testHistory() {
+		$is = $this->CurrencyLib->history();
+		$this->assertTrue(is_array($is) && !empty($is));
+	}
+
 	/**
 	 * CurrencyLibTest::testReset()
 	 *