add webcam to customer create/update
This commit is contained in:
@@ -13,6 +13,7 @@ use yii\base\Object;
|
||||
use common\models\Card;
|
||||
use frontend\models\CustomerUpdate;
|
||||
use frontend\models\CustomerCreate;
|
||||
use common\models\Image;
|
||||
|
||||
/**
|
||||
* CustomerController implements the CRUD actions for Customer model.
|
||||
@@ -119,6 +120,7 @@ class CustomerController extends Controller
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
$this->saveBinaryImage($model);
|
||||
\Yii::$app->session->setFlash( 'success','Vendég létrehozva!' );
|
||||
return $this->redirect(['update', 'number' => $model->cardNumber]);
|
||||
} else {
|
||||
@@ -160,6 +162,9 @@ class CustomerController extends Controller
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
|
||||
$this->saveBinaryImage($model);
|
||||
|
||||
|
||||
\Yii::$app->session->setFlash( 'success','Vendég módosításai elmentve' );
|
||||
|
||||
return $this->redirect(['update', 'number' => $card->number]);
|
||||
@@ -175,6 +180,24 @@ class CustomerController extends Controller
|
||||
}
|
||||
|
||||
|
||||
protected function saveBinaryImage($model){
|
||||
if ( !empty($model->photo_data)){
|
||||
$encoded_data = $model->photo_data;
|
||||
$binary_data = base64_decode( $encoded_data );
|
||||
// save to server (beware of permissions)
|
||||
$path = \common\components\Image::saveBinary($binary_data,'profile');
|
||||
|
||||
$image = new Image();
|
||||
$image->path = $path;
|
||||
$image->save();
|
||||
|
||||
//todo delete old image
|
||||
|
||||
$model->id_image = $image->id_image;
|
||||
$model->save(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Customer model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
|
||||
Reference in New Issue
Block a user