summaryrefslogtreecommitdiff
path: root/protected/controllers/VereinController.php
diff options
context:
space:
mode:
authorTristan Zur <tzur@ccwn.org>2012-05-18 11:31:14 +0200
committerTristan Zur <tzur@ccwn.org>2012-05-18 11:31:14 +0200
commitbb5de528c46a6acc56c9e856caae5f9999319d62 (patch)
treef9c1772868663342b242a2eaa8fa71baafc2eefc /protected/controllers/VereinController.php
parent3cb7fbfceae978d2b87ae976bf4536c3461bb868 (diff)
- Dateiupload in eigene Klasse ausgelagert -> Upload wird immer gleich
durchgeführt. - Extension SimpleImage hinzugefügt -> Bildgrößen werden nun auf eine konfigurierbare Maximalbreite und Maximalhöhe verkleinert
Diffstat (limited to 'protected/controllers/VereinController.php')
-rw-r--r--protected/controllers/VereinController.php28
1 files changed, 13 insertions, 15 deletions
diff --git a/protected/controllers/VereinController.php b/protected/controllers/VereinController.php
index a0a3828..445488b 100644
--- a/protected/controllers/VereinController.php
+++ b/protected/controllers/VereinController.php
@@ -65,14 +65,7 @@ class VereinController extends Controller
if($model->save()) {
Yii::trace("Verein gespeichert", "admin.astaf.verein");
Yii::trace("Bild: ".$model->uploadedImage, "admin.astaf.verein");
- if (null !== $model->uploadedImage) {
- Yii::trace("Bild vorhanden", "admin.astaf.verein");
- $suffix = substr($model->uploadedImage->getName(), strrpos($model->uploadedImage->getName(), "."));
- $filename = "images/uploaded/".time()."-".$model->slug.$suffix;
- $model->bild = $filename;
- $model->uploadedImage->saveAs($filename);
- $model->save();
- }
+ $this->saveImage($model);
$this->redirect(array('view','id'=>$model->id));
}
}
@@ -103,13 +96,7 @@ class VereinController extends Controller
$model->attributes=$_POST['Verein'];
$model->uploadedImage = CUploadedFile::getInstance($model, 'uploadedImage');
if($model->save()) {
- if (null !== $model->uploadedImage) {
- $suffix = substr($model->uploadedImage->getName(), strrpos($model->uploadedImage->getName(), "."));
- $filename = "images/uploaded/".time()."-".$model->slug.$suffix;
- $model->bild = $filename;
- $model->uploadedImage->saveAs($filename);
- $model->save();
- }
+ $this->saveImage($model);
$this->redirect(array('view','id'=>$model->id));
}
}
@@ -123,6 +110,17 @@ class VereinController extends Controller
));
}
+ private function saveImage($model) {
+ if (null !== $model->uploadedImage) {
+ $filename = VereinImageFunctions::resizeAndSave($model->uploadedImage, $model->slug);
+ if (null === $filename) {
+ throw new CHttpException(500, 'Error while saving image.');
+ }
+ $model->bild = $filename;
+ $model->save();
+ }
+ }
+
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.