summaryrefslogtreecommitdiff
path: root/protected/components
diff options
context:
space:
mode:
Diffstat (limited to 'protected/components')
-rw-r--r--protected/components/Format.php18
-rw-r--r--protected/components/Html.php21
2 files changed, 37 insertions, 2 deletions
diff --git a/protected/components/Format.php b/protected/components/Format.php
new file mode 100644
index 0000000..129a292
--- /dev/null
+++ b/protected/components/Format.php
@@ -0,0 +1,18 @@
+<?php
+class Format {
+ public static function currency($value, $currency = 'EUR') {
+ return Yii::app()->locale->numberFormatter->formatCurrency($value, $currency);
+ }
+
+ public static function number($value, $einheit = '') {
+ return Yii::app()->locale->numberFormatter->formatDecimal($value).' '.$einheit;
+ }
+
+ public static function decimal($value) {
+ return Yii::app()->locale->numberFormatter->formatDecimal($value);
+ }
+
+ public static function percentage($value) {
+ return Yii::app()->locale->numberFormatter->formatPercentage($value);
+ }
+} \ No newline at end of file
diff --git a/protected/components/Html.php b/protected/components/Html.php
index c4a246c..08fc6d9 100644
--- a/protected/components/Html.php
+++ b/protected/components/Html.php
@@ -1,6 +1,5 @@
<?php
-class Html extends CHtml
-{
+class Html extends CHtml {
/**
* Makes the given URL relative to the /image directory
*/
@@ -19,5 +18,23 @@ class Html extends CHtml
public static function jsUrl($url) {
return Yii::app()->baseUrl.'/js/'.$url;
}
+
+ public static function enumItem($model, $attribute) {
+ $attr = $attribute;
+ self::resolveName($model, $attr);
+ preg_match('/\((.*)\)/', $model->tableSchema->columns[$attr]->dbType, $matches);
+ foreach (explode(',', $matches[1]) as $value) {
+ $value = str_replace("'", null, $value);
+ $values[$value] = Yii::t('enumItem', $value);
+ }
+
+ return $values;
+ }
+
+ public static function enumDropDownList($model, $attribute, $htmlOptions = array()) {
+ return CHtml::activeDropDownList($model, $attribute, Html::enumItem($model, $attribute), $htmlOptions);
+ }
+
+
}
?> \ No newline at end of file