浏览代码

make icons work with new plugin

euromark 12 年之前
父节点
当前提交
2257c2be33

+ 3 - 2
Model/Behavior/SortableBehavior.php

@@ -9,7 +9,8 @@ App::uses('ModelBehavior', 'Model');
  * You can also reverse the direction.
  *
  * Natural (default) order:
- * The sort value of new records is 0.
+ * The sort value of new records is 0. This should be used in combination with
+ * a secondary and possibly unique sort value for collisions around 0.
  *
  * Reversed order:
  * The sort value of a new record will be calculated (currently highest + 1).
@@ -22,7 +23,7 @@ class SortableBehavior extends ModelBehavior {
 
 	protected $_defaults = array(
 		'field' => 'sort',
-		'reverse' => false // TO make 0 the highest value
+		'reverse' => false // TO make 0 the "highest" value
 	);
 
 	/**

+ 5 - 0
Test/Case/Model/Behavior/SortableBehaviorTest.php

@@ -159,6 +159,11 @@ class SortableBehaviorTest extends MyCakeTestCase {
 		return $position;
 	}
 
+	/**
+	 * SortableBehaviorTest::_getList()
+	 *
+	 * @return array
+	 */
 	protected function _getList() {
 		$options = array(
 			'order' => array('sort' => 'DESC'),

+ 23 - 5
View/Helper/FormatHelper.php

@@ -186,15 +186,29 @@ class FormatHelper extends TextHelper {
 
 	/**
 	 * //TODO: move to Format?
+	 *
+	 * Custom paths possible:
+	 * 'imagePath' => 'PluginName./img/country_flags/',
+	 *
 	 * @param string $icon iso2 code (e.g. 'de' or 'gb')
+	 * @return string;
 	 */
 	public function countryIcon($icon = null, $returnFalseonFailure = false, $options = array(), $attr = array()) {
 		$ending = 'gif';
 		$image = 'unknown';
 
-		if ($specific = Configure::read('Country.image_path')) {
-			$wwwPath = $specific . '/';
-			$path = PATH_IMAGES . $specific . DS; //.'country_flags'.DS
+		if ($specific = Configure::read('Country.imagePath')) {
+			list ($plugin, $specificPath) = pluginSplit($specific);
+			$wwwPath = $specificPath;
+			if ($plugin) {
+				$wwwPath = '/' . Inflector::underscore($plugin) . '/' . $wwwPath;
+			}
+			if ($plugin) {
+				$path = CakePlugin::path($plugin) . 'webroot' . DS;
+			} else {
+				$path = WWW_ROOT;
+			}
+			$path .= $specificPath . DS;
 		} else {
 			$wwwPath = '/tools/img/country_flags/';
 			$path = App::pluginPath('Tools') . 'webroot' . DS . 'img' . DS . 'country_flags' . DS;
@@ -208,13 +222,17 @@ class FormatHelper extends TextHelper {
 		$icon = mb_strtolower($icon);
 
 		if (empty($icon)) {
-			if ($returnFalseonFailure) { return false; }
+			if ($returnFalseonFailure) {
+				return false;
+			}
 		} elseif (!file_exists($path . $icon . '.' . $ending)) {
 
 			//die($path . $icon . '.' . $ending);
 			trigger_error($path . $icon . '.' . $ending . ' missing', E_USER_NOTICE);
 
-			if ($returnFalseonFailure) { return false; }
+			if ($returnFalseonFailure) {
+				return false;
+			}
 		} else {
 			$image = $icon;
 		}