add id_account to door log, add key import to backend with no menu
This commit is contained in:
@@ -10,137 +10,212 @@ use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
use common\models\Customer;
|
||||
use backend\models\KeyCustomerSearch;
|
||||
use backend\models\KeyImportForm;
|
||||
use yii\web\UploadedFile;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* KeyController implements the CRUD actions for Key model.
|
||||
*/
|
||||
class KeyController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['post'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Key models.
|
||||
* @return mixed
|
||||
*/
|
||||
//http://localhost/fitness-web/backend/web/index.php?r=key/index erre ezt hívja meg elsőzör
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new KeySearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
class KeyController extends Controller {
|
||||
public function behaviors() {
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className (),
|
||||
'actions' => [
|
||||
'delete' => [
|
||||
'post'
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Key models.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
// http://localhost/fitness-web/backend/web/index.php?r=key/index erre ezt hívja meg elsőzör
|
||||
public function actionIndex() {
|
||||
$searchModel = new KeySearch ();
|
||||
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
|
||||
// backend/views/kex/index.php
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider, //csomagoló osztály a queryhez
|
||||
]);
|
||||
}
|
||||
/**
|
||||
* Lists all Key models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndexCustomer($id)
|
||||
{
|
||||
return $this->render ( 'index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider
|
||||
] // csomagoló osztály a queryhez
|
||||
);
|
||||
}
|
||||
/**
|
||||
* Lists all Key models.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndexCustomer($id) {
|
||||
$model = Customer::findOne ( $id );
|
||||
|
||||
$model = Customer::findOne($id);
|
||||
|
||||
if ( !isset($model)){
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
|
||||
$searchModel = new KeyCustomerSearch(['customer' => $model]);
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
if (! isset ( $model )) {
|
||||
throw new NotFoundHttpException ( 'The requested page does not exist.' );
|
||||
}
|
||||
|
||||
$searchModel = new KeyCustomerSearch ( [
|
||||
'customer' => $model
|
||||
] );
|
||||
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
|
||||
// backend/views/kex/index.php
|
||||
return $this->render('index-customer', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider, //csomagoló osztály a queryhez
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Key model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Key model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Key();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_key]);
|
||||
} else {
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Key model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id_key]);
|
||||
} else {
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Key model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Key model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return Key the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Key::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
return $this->render ( 'index-customer', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider
|
||||
] // csomagoló osztály a queryhez
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Key model.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionView($id) {
|
||||
return $this->render ( 'view', [
|
||||
'model' => $this->findModel ( $id )
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Key model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate() {
|
||||
$model = new Key ();
|
||||
|
||||
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
|
||||
return $this->redirect ( [
|
||||
'view',
|
||||
'id' => $model->id_key
|
||||
] );
|
||||
} else {
|
||||
return $this->render ( 'create', [
|
||||
'model' => $model
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Key model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionUpdate($id) {
|
||||
$model = $this->findModel ( $id );
|
||||
|
||||
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
|
||||
return $this->redirect ( [
|
||||
'view',
|
||||
'id' => $model->id_key
|
||||
] );
|
||||
} else {
|
||||
return $this->render ( 'update', [
|
||||
'model' => $model
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Key model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionDelete($id) {
|
||||
$this->findModel ( $id )->delete ();
|
||||
|
||||
return $this->redirect ( [
|
||||
'index'
|
||||
] );
|
||||
}
|
||||
|
||||
public function actionImport() {
|
||||
$model = new KeyImportForm();
|
||||
$arr = [ ];
|
||||
|
||||
if (Yii::$app->request->isPost) {
|
||||
$model->file = UploadedFile::getInstance ( $model, 'file' );
|
||||
|
||||
// print_r($model->file);
|
||||
// $model->message = "ok";
|
||||
$file = $model->file->tempName;
|
||||
|
||||
$file = fopen ( $file, "r" );
|
||||
|
||||
$trans = null;
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
while ( ($data = fgetcsv ( $file, 0, "," )) != null ) {
|
||||
// if ($i == 0) {
|
||||
// $i ++;
|
||||
// continue;
|
||||
// }
|
||||
$j ++;
|
||||
$number = $key = false;
|
||||
if (isset ( $data [0] )) {
|
||||
$number = $data [0];
|
||||
}
|
||||
|
||||
if (isset ( $data [1] )) {
|
||||
$key = $data [1];
|
||||
}
|
||||
|
||||
if (isset ( $number ) && isset ( $key ) && ! strpos ( $key, "E+" ) && strlen ( $key ) > 7) {
|
||||
$item = [ ];
|
||||
$item ['number'] = $number;
|
||||
$item ['key'] = Helper::fixAsciiChars ( $key );
|
||||
$arr [] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $arr as $item ) {
|
||||
try {
|
||||
$key = new Key ();
|
||||
$key->number = $item ['number'];
|
||||
$key->rfid_key = $item ['key'];
|
||||
$key->status = Key::STATUS_ACTIVE;
|
||||
$key->type = Key::TYPE_NORMAL;
|
||||
$key->save ( false );
|
||||
} catch ( \Exception $e ) {
|
||||
\Yii::error ( "Failed to save key: " . $key->number );
|
||||
}
|
||||
}
|
||||
|
||||
$this->redirect ( [
|
||||
'import'
|
||||
] );
|
||||
}
|
||||
|
||||
return $this->render ( 'import', [
|
||||
'model' => $model
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Key model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return Key the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id) {
|
||||
if (($model = Key::findOne ( $id )) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException ( 'The requested page does not exist.' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user