add webcam to customer create/update

This commit is contained in:
2015-12-30 12:02:26 +01:00
parent 135d64e4c8
commit eb989d5f80
16 changed files with 240 additions and 7 deletions

View File

@@ -0,0 +1,16 @@
<?php
namespace common\assets;
use yii\web\AssetBundle;
class WebcamjsAsset extends AssetBundle
{
public $sourcePath = '@bower';
public $js = [
'webcamjs/webcam.min.js'
];
public $depends = [
];
}

View File

@@ -31,7 +31,21 @@ class Image
return Upload::getLink($fileName);
}
public static function saveBinary($binary_data, $dir = '')
{
$fileName = Upload::getUploadPath($dir) . DIRECTORY_SEPARATOR . Upload::genFileName("jpg");
$uploaded = file_put_contents( $fileName, $binary_data );
if(!$uploaded){
throw new HttpException(500, 'Cannot upload file "'.$fileName.'". Please check write permissions.');
}
return Upload::getLink($fileName);
}
/**
*
* @param unknown $filename

View File

@@ -47,4 +47,17 @@ class Upload
return $fileName;
}
static function genFileName($extension, $namePostfix = true)
{
$baseName = "image";
$fileName = StringHelper::truncate(Inflector::slug($baseName), 32, '');
if($namePostfix || !$fileName) {
$fileName .= ($fileName ? '-' : '') . substr(uniqid(md5(rand()), true), 0, 10);
}
$fileName .= '.' . $extension;
return $fileName;
}
}

View File

@@ -39,6 +39,9 @@ class Customer extends \yii\db\ActiveRecord
const SEX_MAN = 10;
const SEX_WOMAN = 20;
public $photo_data;
/**
* @inheritdoc
*/
@@ -146,6 +149,11 @@ class Customer extends \yii\db\ActiveRecord
'id' => 'id_user'
] );
}
public function getImage1(){
return $this->hasOne ( Image::className (), [
'id_image' => 'id_image'
] );
}
public function getCustomerCardNumber(){
$result = null;