summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Seeger <pseeger@ccwn.org>2013-06-25 15:14:49 +0200
committerPatrick Seeger <pseeger@ccwn.org>2013-06-25 15:16:55 +0200
commit9fd4565719ba3f099d2ffa081bb594a35b694ca9 (patch)
tree358ea5f65d3496be78f5d03f822e52cb553fb369
parent9d7cce38ef2c157ca44df2bd8f43a27bbd09fcec (diff)
Upload von Hintergrundbildern
-rw-r--r--.gitignore1
-rw-r--r--protected/components/VereinImageFunctions.php28
-rw-r--r--protected/config/maincfg.php2
-rw-r--r--protected/controllers/VereinController.php11
-rw-r--r--protected/data/20130625_add_background_vereine.sql1
-rw-r--r--protected/extensions/SimpleImage/SimpleImage.php10
-rw-r--r--protected/models/Verein.php8
-rw-r--r--protected/views/verein/_form.php7
8 files changed, 59 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index e85b464..055990e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/assets/*
/images/uploaded/*
+/protected/runtime/application.log \ No newline at end of file
diff --git a/protected/components/VereinImageFunctions.php b/protected/components/VereinImageFunctions.php
index 477e767..5f7bd4e 100644
--- a/protected/components/VereinImageFunctions.php
+++ b/protected/components/VereinImageFunctions.php
@@ -5,7 +5,19 @@ class VereinImageFunctions {
public static function resizeAndSave(CUploadedFile $uploadedImage, $vereinSlug) {
$filename = VereinImageFunctions::save($uploadedImage, $vereinSlug);
if (null !== $filename) {
- VereinImageFunctions::resize($filename);
+ VereinImageFunctions::resizeLogo($filename);
+ }
+
+ return $filename;
+ }
+
+ public static function resizeAndSaveBG(CUploadedFile $uploadedImage, $vereinSlug) {
+ $filename = VereinImageFunctions::save($uploadedImage, $vereinSlug.".BG");
+ if (null !== $filename) {
+ //VereinImageFunctions::resize($filename,Yii::app()->params['verein_background_width'], Yii::app()->params['verein_background_height']);
+ $image = Yii::app()->simpleImage->load($filename);
+ $image->blend(Yii::app()->params['verein_background_width'], Yii::app()->params['verein_background_height']);
+ $image->save($filename);
}
return $filename;
@@ -19,16 +31,20 @@ class VereinImageFunctions {
return null;
}
}
+ public static function resizeLogo($filename) {
+ VereinImageFunctions::resize($filename,Yii::app()->params['logo_width'], Yii::app()->params['logo_height']);
+
+ }
- public static function resize($filename) {
+ public static function resize($filename, $width, $height) {
$image = Yii::app()->simpleImage->load($filename);
- if ($image->getWidth() > Yii::app()->params['logo_width']) {
- $image->resizeToWidth(Yii::app()->params['logo_width']);
+ if ($image->getWidth() > $width) {
+ $image->resizeToWidth($width);
}
- if ($image->getHeight() > Yii::app()->params['logo_height']) {
- $image->resizeToHeight(Yii::app()->params['logo_height']);
+ if ($image->getHeight() > $height) {
+ $image->resizeToHeight($width);
}
$image->save($filename);
}
diff --git a/protected/config/maincfg.php b/protected/config/maincfg.php
index b9cfd08..2327468 100644
--- a/protected/config/maincfg.php
+++ b/protected/config/maincfg.php
@@ -124,5 +124,7 @@ return array(
'end_time'=>'23:00',
'logo_width'=>150,
'logo_height'=>150,
+ 'verein_background_width'=>850,
+ 'verein_background_height'=>200,
),
);
diff --git a/protected/controllers/VereinController.php b/protected/controllers/VereinController.php
index aad8776..7d2da81 100644
--- a/protected/controllers/VereinController.php
+++ b/protected/controllers/VereinController.php
@@ -62,9 +62,11 @@ class VereinController extends Controller
{
$model->attributes=$_POST['Verein'];
$model->uploadedImage = CUploadedFile::getInstance($model, 'uploadedImage');
+ $model->uploadedHintergrund = CUploadedFile::getInstance($model, 'uploadedHintergrund');
if($model->save()) {
Yii::trace("Verein gespeichert", "admin.astaf.verein");
Yii::trace("Bild: ".$model->uploadedImage, "admin.astaf.verein");
+ Yii::trace("Hintergrund: ".$model->uploadedHintergrund, "admin.astaf.verein");
$this->saveImage($model);
$this->redirect(array('view','id'=>$model->id));
}
@@ -95,6 +97,7 @@ class VereinController extends Controller
{
$model->attributes=$_POST['Verein'];
$model->uploadedImage = CUploadedFile::getInstance($model, 'uploadedImage');
+ $model->uploadedHintergrund = CUploadedFile::getInstance($model, 'uploadedHintergrund');
if($model->save()) {
$this->saveImage($model);
$this->redirect(array('view','id'=>$model->id));
@@ -119,6 +122,14 @@ class VereinController extends Controller
$model->bild = "/".$filename;
$model->save();
}
+ if (null !== $model->uploadedHintergrund) {
+ $filename = VereinImageFunctions::resizeAndSaveBG($model->uploadedHintergrund, $model->slug);
+ if (null === $filename) {
+ throw new CHttpException(500, 'Error while saving image.');
+ }
+ $model->hintergrund = "/".$filename;
+ $model->save();
+ }
}
/**
diff --git a/protected/data/20130625_add_background_vereine.sql b/protected/data/20130625_add_background_vereine.sql
new file mode 100644
index 0000000..b8f51ba
--- /dev/null
+++ b/protected/data/20130625_add_background_vereine.sql
@@ -0,0 +1 @@
+alter table vereine add column hintergrund varchar(100); \ No newline at end of file
diff --git a/protected/extensions/SimpleImage/SimpleImage.php b/protected/extensions/SimpleImage/SimpleImage.php
index bbccfa0..54c4ef8 100644
--- a/protected/extensions/SimpleImage/SimpleImage.php
+++ b/protected/extensions/SimpleImage/SimpleImage.php
@@ -147,5 +147,15 @@ class SimpleImage {
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
+
+ function blend($width, $height) {
+ $this->resizeToWidth($width);
+ $new_image = imagecreatetruecolor($width, $height);
+ imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $width, $height);
+ imagealphablending($new_image,true);
+ imagefilledrectangle($new_image, 0, 0, $width, $height, imagecolorallocatealpha($new_image, 255, 255, 255, 30));
+ $this->image = $new_image;
+
+ }
}
?> \ No newline at end of file
diff --git a/protected/models/Verein.php b/protected/models/Verein.php
index 8556f48..9274111 100644
--- a/protected/models/Verein.php
+++ b/protected/models/Verein.php
@@ -14,10 +14,12 @@
* @property string $beschreibung
* @property integer $standort_id
* @property integer $published
+ * @property string $hintergrund
*/
class Verein extends CActiveRecord
{
public $uploadedImage;
+ public $uploadedHintergrund;
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
@@ -47,14 +49,14 @@ class Verein extends CActiveRecord
array("email, name", "required"),
array('standort_id, published', 'numerical', 'integerOnly'=>true),
array('name, url', 'length', 'max'=>255),
- array('bild, email, slug', 'length', 'max'=>100),
+ array('bild, email, slug, hintergrund', 'length', 'max'=>100),
array("url", "url", "allowEmpty"=>true, "message"=>"Die eingebene URL ist ungültig."),
array("email", "email", "message"=>"Die eingebene eMail-Adresse ist ungültig."),
array("uploadedImage", "file", "types"=>"jpg, gif, png", "allowEmpty"=>true, "wrongType"=>'Die Datei "{file}" konnte nicht hochgeladen werden. Es sind nur Dateien mit den folgenden Endungen erlaubt: {extensions}.'),
array('kontaktdaten, beschreibung', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
- array('id, name, url, bild, email, slug, kontaktdaten, beschreibung, standort_id, published', 'safe', 'on'=>'search'),
+ array('id, name, url, email, slug, kontaktdaten, beschreibung, standort_id, published', 'safe', 'on'=>'search'),
);
}
@@ -86,6 +88,7 @@ class Verein extends CActiveRecord
'beschreibung' => 'Beschreibung',
'standort_id' => 'Standort',
'standort' => 'Standort',
+ 'hintergrund' => 'Hintergrundbild',
'published' => 'Öffentlich',
);
}
@@ -105,6 +108,7 @@ class Verein extends CActiveRecord
$criteria->compare('name',$this->name,true);
$criteria->compare('url',$this->url,true);
$criteria->compare('bild',$this->bild,true);
+ $criteria->compare('hintergrund',$this->hintergrund,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('slug',$this->slug);
$criteria->compare('kontaktdaten',$this->kontaktdaten,true);
diff --git a/protected/views/verein/_form.php b/protected/views/verein/_form.php
index 5b6bf46..6de5d5c 100644
--- a/protected/views/verein/_form.php
+++ b/protected/views/verein/_form.php
@@ -104,7 +104,12 @@
?>
<?php echo $form->error($model,'standort_id'); ?>
</div>
-
+ <div class="row">
+ <?php echo $form->labelEx($model,'hintergrund'); ?>
+ <?php echo CHtml::image($model->hintergrund,'height="80"'); ?><br/>
+ <?php echo $form->fileField($model,'uploadedHintergrund', array('size'=>60)); ?>
+ <?php echo $form->error($model,'hintergrund'); ?>
+ </div>
<div class="row">
<?php echo $form->labelEx($model,'published'); ?>
<?php