diff --git a/common/assets/WebcamjsAsset.php b/common/assets/WebcamjsAsset.php new file mode 100644 index 0000000..91d0b3e --- /dev/null +++ b/common/assets/WebcamjsAsset.php @@ -0,0 +1,16 @@ + 'id_user' ] ); } + public function getImage1(){ + return $this->hasOne ( Image::className (), [ + 'id_image' => 'id_image' + ] ); + } public function getCustomerCardNumber(){ $result = null; diff --git a/composer.json b/composer.json index 43d682f..99efb4e 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "bower-asset/moment": "^2.10", "bower-asset/accounting": "^0.3.2", "dmstr/yii2-adminlte-asset": "2.*", - "bassjobsen/bootstrap-3-typeahead": "^4.0" + "bassjobsen/bootstrap-3-typeahead": "^4.0", + "bower-asset/webcamjs": "^1.0" }, "require-dev": { "yiisoft/yii2-codeception": "*", diff --git a/composer.lock b/composer.lock index f0c982d..20dc733 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "acfc873fb659d08adc23d325138a56b2", - "content-hash": "28e2bce30da929c84bd2ac7cffd90f3f", + "hash": "fa82e6ba1233a366a5f044d19a7bd69d", + "content-hash": "ea0b9fcfc8a270415b8f9292af1c17d3", "packages": [ { "name": "almasaeed2010/adminlte", @@ -410,6 +410,42 @@ "remarkable" ] }, + { + "name": "bower-asset/webcamjs", + "version": "v1.0.6", + "source": { + "type": "git", + "url": "https://github.com/jhuckaby/webcamjs.git", + "reference": "1f164b822507977bf746838c66b9e4332764c062" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/jhuckaby/webcamjs/zipball/1f164b822507977bf746838c66b9e4332764c062", + "reference": "1f164b822507977bf746838c66b9e4332764c062", + "shasum": "" + }, + "type": "bower-asset-library", + "extra": { + "bower-asset-main": "webcam.js", + "bower-asset-ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests", + "build.sh", + "demos", + "flash" + ] + }, + "license": [ + "MIT" + ], + "description": "HTML5 Webcam Image Capture Library with Flash Fallback", + "keywords": [ + "webcam" + ] + }, { "name": "bower-asset/yii2-pjax", "version": "v2.0.4", diff --git a/frontend/assets/CustomerAsset.php b/frontend/assets/CustomerAsset.php new file mode 100644 index 0000000..e1b094e --- /dev/null +++ b/frontend/assets/CustomerAsset.php @@ -0,0 +1,31 @@ + + * @since 2.0 + */ +class CustomerAsset extends AssetBundle +{ + public $basePath = '@webroot'; + public $baseUrl = '@web'; + public $css = [ + ]; + public $js = [ + 'js/customer.js', + ]; + public $depends = [ + 'frontend\assets\AppAsset', + 'common\assets\MomentAsset', + 'common\assets\WebcamjsAsset', + 'yii\jui\JuiAsset', + ]; +} diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php index 4024fcf..cb18e55 100644 --- a/frontend/controllers/CustomerController.php +++ b/frontend/controllers/CustomerController.php @@ -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. diff --git a/frontend/models/CustomerCreate.php b/frontend/models/CustomerCreate.php index 6ce1f7b..a6f4357 100644 --- a/frontend/models/CustomerCreate.php +++ b/frontend/models/CustomerCreate.php @@ -100,6 +100,7 @@ class CustomerCreate extends \common\models\Customer [['zip'], 'string', 'max' => 8], [['city'], 'string', 'max' => 30], + [['photo_data'] ,'safe'] // [['email','phone'], 'validateEmailOrPhoneRequired' ], ]; diff --git a/frontend/models/CustomerUpdate.php b/frontend/models/CustomerUpdate.php index dab17eb..ed920a9 100644 --- a/frontend/models/CustomerUpdate.php +++ b/frontend/models/CustomerUpdate.php @@ -100,7 +100,8 @@ class CustomerUpdate extends \common\models\Customer [['zip'], 'string', 'max' => 8], - [['city'], 'string', 'max' => 30] + [['city'], 'string', 'max' => 30], + [['photo_data'] ,'safe'] ]; } diff --git a/frontend/views/common/_reception_customer.php b/frontend/views/common/_reception_customer.php index b79b290..2c2b96d 100644 --- a/frontend/views/common/_reception_customer.php +++ b/frontend/views/common/_reception_customer.php @@ -4,6 +4,8 @@ use frontend\model\ReceptionForm; use yii\helpers\Html; use yii\widgets\DetailView; use yii\base\Widget; +use common\components\Image; +use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model frontend\model\ReceptionForm */ @@ -34,6 +36,12 @@ if ( $model->isCardWithCustomer() ){ 'label' => 'Telefon', 'value' => $model->customer->phone ], + [ + 'label' => 'Fénykép', + 'value' => $model->customer->image1 ? Html::img( Url::base( ) . Image::thumb( $model->customer->image1->path,160,120 )) : 'Nincs kép', + 'format' => 'raw' + + ], ] ]) diff --git a/frontend/views/customer/_camera.php b/frontend/views/customer/_camera.php new file mode 100644 index 0000000..08ab227 --- /dev/null +++ b/frontend/views/customer/_camera.php @@ -0,0 +1,29 @@ +registerJs ( 'new Customer( '. json_encode($options).');' ); +?> + + + +
+
+
+
+
+
+
+
+Fénykép \ No newline at end of file diff --git a/frontend/views/customer/_form_create.php b/frontend/views/customer/_form_create.php index 22c0fc3..16a66c1 100644 --- a/frontend/views/customer/_form_create.php +++ b/frontend/views/customer/_form_create.php @@ -16,7 +16,7 @@ use kartik\widgets\DatePicker;
- +field($model, 'photo_data')->hiddenInput()->label(false) ?>
diff --git a/frontend/views/customer/_form_update.php b/frontend/views/customer/_form_update.php index cebebf1..ea8b541 100644 --- a/frontend/views/customer/_form_update.php +++ b/frontend/views/customer/_form_update.php @@ -18,7 +18,7 @@ use yii\base\Widget; - + field($model, 'photo_data')->hiddenInput()->label(false) ?>
field($model, 'cardNumber')->widget(CardNumberTypeahead::className(),[]) ?> diff --git a/frontend/views/customer/create.php b/frontend/views/customer/create.php index 5708176..499ecf2 100644 --- a/frontend/views/customer/create.php +++ b/frontend/views/customer/create.php @@ -20,7 +20,7 @@ $card = $customer->card;
$receptionForm, 'route' => ['customer/create'] ] )?> - + render('_camera',['model' => $model]); ?>

title) ?>

render('_form_create', [ diff --git a/frontend/views/customer/update.php b/frontend/views/customer/update.php index 5a7175a..a39db12 100644 --- a/frontend/views/customer/update.php +++ b/frontend/views/customer/update.php @@ -4,10 +4,16 @@ use yii\helpers\Html; use frontend\components\ReceptionMenuWidget; use frontend\components\ReceptionCardNumberWidget; use frontend\components\ReceptionWidget; +use common\assets\WebcamjsAsset; +use frontend\assets\CustomerAsset; +use common\components\Image; +use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model common\models\Customer */ + + $this->title = Yii::t('common/customer', 'Update customer:' ) . ' ' . $model->name; $this->params['breadcrumbs'][] = ['label' => Yii::t('common/customer', 'Customers'), 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id_customer]]; @@ -16,6 +22,8 @@ $this->params['breadcrumbs'][] = Yii::t('common/customer', 'Update'); $customer = $model; $card = $customer->card; + + ?>
@@ -23,9 +31,18 @@ $card = $customer->card; $receptionForm, 'route' => ['customer/reception'] ] )?> + render('_camera',['model' => $model]); ?> +

title) ?>

+ + image1 ){ + echo Html::img( Url::base( ) . Image::thumb( $model->image1->path,160,120 )); + } + + ?> render('_form_update', [ 'model' => $model, ]) ?>
+ diff --git a/frontend/web/js/customer.js b/frontend/web/js/customer.js new file mode 100644 index 0000000..bcb170e --- /dev/null +++ b/frontend/web/js/customer.js @@ -0,0 +1,43 @@ +function Customer(o){ + + var defaults = { + 'image_data' : 'customerupdate-photo_data' + + }; + + init(); + + function init(){ + + defaults = $.extend(defaults,o); + + Webcam.set({ + width: 160, + height: 120, + dest_width: 320, + dest_height: 240, + image_format: 'jpeg', + jpeg_quality: 90, +// force_flash: false, +// flip_horiz: true, +// fps: 45 + }); + + Webcam.attach( '#my_camera' ); + + $("#snap").click(snap); + + } + + function snap(){ + Webcam.snap( function(data_uri) { + document.getElementById('my_result').innerHTML = ''; + + var raw_image_data = data_uri.replace(/^data\:image\/\w+\;base64\,/, ''); + + document.getElementById(defaults.image_data ).value = raw_image_data; + + } ); + } + +} \ No newline at end of file