summaryrefslogtreecommitdiff
path: root/protected/components
diff options
context:
space:
mode:
Diffstat (limited to 'protected/components')
-rw-r--r--protected/components/DateCompareValidator.php13
-rw-r--r--protected/components/DateRangeValidator.php4
-rw-r--r--protected/components/Format.php6
-rw-r--r--protected/components/Html.php20
-rw-r--r--protected/components/VereinImageFunctions.php45
5 files changed, 81 insertions, 7 deletions
diff --git a/protected/components/DateCompareValidator.php b/protected/components/DateCompareValidator.php
index c013382..13a4126 100644
--- a/protected/components/DateCompareValidator.php
+++ b/protected/components/DateCompareValidator.php
@@ -40,15 +40,24 @@ class DateCompareValidator extends CValidator {
return;
}
- $start = CDateTimeParser::parse($object->$attribute, $this->format);
+ $start = $object->$attribute;
+ $end = $this->compareValue;
- $end = CDateTimeParser::parse($this->compareValue, $this->format);
+ $pattern = '/[0-9]{2}\.[0-9]{2}\.[0-9]{4}\s[0-9]{2}:[0-9]{2}/';
+ if (preg_match($pattern, $start)) {
+ $start = CDateTimeParser::parse($start, "dd.MM.yyyy HH:mm");
+ }
+ if (preg_match($pattern, $end)) {
+ $end = CDateTimeParser::parse($end, "dd.MM.yyyy HH:mm");
+ }
//a little php trick - safe than eval and easier than a big switch statement
if (version_compare($start, $end, $this->operator)) {
+ Yii::trace('Input value: '.$start.' - compare value: '.$end.' - operator: '.$this->operator.' - result: OK', 'ccwn.astaf.date.validate');
return;
} else {
+ Yii::trace('Input value: '.$start.' - compare value: '.$end.' - operator: '.$this->operator.' - result: FAIL', 'ccwn.astaf.date.validate');
$message = $this->message !== null ? $this->message : Yii::t('astaf', 'The value of {attribute} ({value}) is not {operator} {compareAttribute} ({compareValue}).');
$this->addError($object, $attribute, $message, array('{operator}'=>$this->operator, '{compareValue}'=>$this->compareValue, '{value}'=>$object->$attribute, '{compareAttribute}'=>($object->getAttributeLabel($this->compareAttribute))));
}
diff --git a/protected/components/DateRangeValidator.php b/protected/components/DateRangeValidator.php
index 8b963a8..529f185 100644
--- a/protected/components/DateRangeValidator.php
+++ b/protected/components/DateRangeValidator.php
@@ -10,10 +10,10 @@ class DateRangeValidator extends DateCompareValidator {
$object->clearErrors($attribute);
}
$this->compareValue = $this->minDate;
- $this->operator = '>';
+ $this->operator = '>=';
parent::validateAttribute($object, $attribute);
$this->compareValue = $this->maxDate;
- $this->operator = '<';
+ $this->operator = '<=';
parent::validateAttribute($object, $attribute);
$addRangeError = false;
diff --git a/protected/components/Format.php b/protected/components/Format.php
index 1be259f..a4802e2 100644
--- a/protected/components/Format.php
+++ b/protected/components/Format.php
@@ -8,8 +8,12 @@ class Format {
return Yii::app()->locale->numberFormatter->formatDecimal($value).' '.$einheit;
}
- public static function decimal($value) {
+ public static function decimal($value, $pattern = null) {
+ if ($pattern !== null) {
return Yii::app()->locale->numberFormatter->formatDecimal($value);
+ } else {
+ return Yii::app()->locale->numberFormatter->format($pattern, $value);
+ }
}
public static function percentage($value) {
diff --git a/protected/components/Html.php b/protected/components/Html.php
index 6c7df3c..5d1e3e5 100644
--- a/protected/components/Html.php
+++ b/protected/components/Html.php
@@ -15,8 +15,12 @@ class Html extends CHtml {
/**
* Makes the given URL relative to the /js directory
*/
- public static function jsUrl($url) {
- return Yii::app()->baseUrl.'/js/'.$url;
+ public static function jsUrl($filename) {
+ return Yii::app()->baseUrl.'/js/'.$filename;
+ }
+
+ public static function registerJavascript($filename) {
+ Yii::app()->getClientScript()->registerScriptFile(self::jsUrl($filename));
}
public static function enumItem($model, $attribute) {
@@ -34,5 +38,17 @@ class Html extends CHtml {
public static function enumDropDownList($model, $attribute, $htmlOptions = array()) {
return CHtml::activeDropDownList($model, $attribute, Html::enumItem($model, $attribute), $htmlOptions);
}
+
+ public static function einheitenDropDownList($model, $attribute, $values, $htmlOptions = array()) {
+ $tmpEinheiten = preg_split('/,/', $values);
+ $einheiten = array();
+ foreach ($tmpEinheiten as $einheit) {
+ $einheit = trim($einheit);
+ $einheiten[$einheit] = $einheit;
+ }
+ self::resolveNameID($model, $attribute, $htmlOptions);
+ $selectedValue = self::resolveValue($model, $attribute);
+ return CHtml::dropDownList($htmlOptions['name'], $selectedValue, $einheiten);
+ }
}
?> \ No newline at end of file
diff --git a/protected/components/VereinImageFunctions.php b/protected/components/VereinImageFunctions.php
new file mode 100644
index 0000000..477e767
--- /dev/null
+++ b/protected/components/VereinImageFunctions.php
@@ -0,0 +1,45 @@
+<?php
+class VereinImageFunctions {
+ const BASE_PATH = 'images/uploaded/';
+
+ public static function resizeAndSave(CUploadedFile $uploadedImage, $vereinSlug) {
+ $filename = VereinImageFunctions::save($uploadedImage, $vereinSlug);
+ if (null !== $filename) {
+ VereinImageFunctions::resize($filename);
+ }
+
+ return $filename;
+ }
+
+ public static function save(CUploadedFile $uploadedImage, $vereinSlug) {
+ $filename = VereinImageFunctions::createFilename($uploadedImage->getName(), $vereinSlug);
+ if ($uploadedImage->saveAs($filename)) {
+ return $filename;
+ } else {
+ return null;
+ }
+ }
+
+ public static function resize($filename) {
+ $image = Yii::app()->simpleImage->load($filename);
+
+ if ($image->getWidth() > Yii::app()->params['logo_width']) {
+ $image->resizeToWidth(Yii::app()->params['logo_width']);
+ }
+
+ if ($image->getHeight() > Yii::app()->params['logo_height']) {
+ $image->resizeToHeight(Yii::app()->params['logo_height']);
+ }
+ $image->save($filename);
+ }
+
+ private static function createFilename($uploadedName, $vereinSlug) {
+ $suffix = VereinImageFunctions::getSuffix($uploadedName);
+ return VereinImageFunctions::BASE_PATH.time()."-".$vereinSlug.$suffix;
+ }
+
+ private static function getSuffix($name) {
+ return (null !== $name) ? substr($name, strrpos($name, '.')) : '';
+ }
+}
+?> \ No newline at end of file