#1: Log Card Read In Botond

This commit is contained in:
2018-02-07 08:23:26 +01:00
parent acb5b040c5
commit cf08823d3f
13 changed files with 149 additions and 54 deletions

View File

@@ -6,6 +6,7 @@ use frontend\models\TowelForm;
use Yii;
use common\models\Customer;
use frontend\models\ReceptionForm;
use yii\base\InvalidConfigException;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
@@ -54,8 +55,12 @@ class CustomerController extends Controller
$model->number = $number;
$model->readCard();
// $model->mkDoorLog();
if ( $model->defaultAccount && $model->defaultAccount->isLogCardReadInReceptionOn()) {
$model->mkDoorLog();
}
if ( $model->isFreeCard() ){
return $this->redirect([ 'create', 'number' => $model->card->number ]);
}else if ( $model->isCardWithKey()){
@@ -91,7 +96,9 @@ class CustomerController extends Controller
/**
* Creates a new Customer model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @param null $number the card number literal
* @return mixed
* @throws \yii\web\HttpException
*/
public function actionCreate($number = null)
{
@@ -129,18 +136,21 @@ class CustomerController extends Controller
}
}
/**
* Updates an existing Customer model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param null $number
* @return mixed
* @throws NotFoundHttpException
* @internal param int $id
*/
/**
* Updates an existing Customer model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param null $number
* @return mixed
* @throws NotFoundHttpException
* @internal param int $id
* @throws \yii\web\HttpException
*/
public function actionUpdate($number = null)
{
$card = null;
$model = null;
/** @var \backend\models\CustomerUpdate $model */
$model = null;
$receptionForm = new ReceptionForm();
$receptionForm->number = $number;
@@ -158,10 +168,15 @@ class CustomerController extends Controller
if ( $model == null) {
throw new NotFoundHttpException('The requested page does not exist.');
}
$model->birthdate= isset($model->birthdate ) ? Yii::$app->formatter->asDate($model->birthdate) :'';
try {
$model->birthdate = isset($model->birthdate) ? Yii::$app->formatter->asDate($model->birthdate) : '';
} catch (InvalidConfigException $e) {
\Yii::error("Failed to format date: " . $e->getMessage());
$model->birthdate = '';
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->saveBinaryImage($model);
@@ -185,15 +200,20 @@ class CustomerController extends Controller
]);
}
}
protected function saveBinaryImage($model){
/**
* Save images as binary data.
* @param $model \common\models\Customer
* @throws \yii\web\HttpException
*/
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();