Add key controller to add/update keys , add bakcend skin param

This commit is contained in:
Roland Schneider 2016-02-19 21:33:06 +01:00
parent 84e2badd34
commit 4aa17e5210
10 changed files with 83 additions and 19 deletions

View File

@ -32,9 +32,6 @@ return [
'session' => [
'name' => '_backendSessionId', // unique for backend
'savePath' => __DIR__ . '/../runtime', // a temporary folder on backend
'cookieParams' => [
'path' => '/backend/web',
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,

View File

@ -33,7 +33,7 @@ class KeyController extends Controller {
'rules' => [
// allow authenticated users
[
'actions' => ['create','index','view','update'],
'actions' => ['create','index','view','update','import'],
'allow' => true,
'roles' => ['admin','employee','reception'],
],
@ -156,10 +156,18 @@ class KeyController extends Controller {
public function actionImport() {
$model = new KeyImportForm();
$arr = [ ];
$updated = 0;
$inserted = 0;
$failed = 0;
$found = 0;
if (Yii::$app->request->isPost) {
$model->file = UploadedFile::getInstance ( $model, 'file' );
if ( isset($model->file)){
// print_r($model->file);
// $model->message = "ok";
$file = $model->file->tempName;
@ -191,25 +199,48 @@ class KeyController extends Controller {
$arr [] = $item;
}
}
$found = count($arr);
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 );
$key = Key::findOne(['number' => $item ['number']]);
if ( !isset($key)){
$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 );
$inserted++;
}else{
$key->rfid_key = $item['key'];
$key->update(false);
$updated++;
}
} catch ( \Exception $e ) {
\Yii::error ( "Failed to save key: " . $key->number );
$failed++;
}
}
$message = "Fájlnév: " . $model->file->name;
$message .= "<br> Fájlból beolvasva: $found ";
$message .= "<br> Új kulcs sikeresen importálva: $inserted ";
$message .= "<br> Rendszerben lévő kulcs sikeresen módosítva: $updated ";
$message .= "<br> Sikertelen kulcs importálás/módosítás: $failed ";
\Yii::$app->session->setFlash('success',$message);
$this->redirect ( [
$model->message = $message;
\Yii::$app->session->set('mymessage',$model->message);
return $this->redirect ( [
'import'
] );
}
}
$model->message = \Yii::$app->session->get('mymessage');
\Yii::$app->session->remove('mymessage');
return $this->render ( 'import', [
'model' => $model
] );

View File

@ -9,8 +9,24 @@ use yii\helpers\Html;
<button>Submit</button>
<?php
echo ($model->message);
if ( isset($model->message)){
?>
<br>
<div class="panel panel-default" style="margin-top: 24px;">
<!-- Default panel contents -->
<div class="panel-heading">Importálás összegzése</div>
<div class="panel-body">
<?php echo $model->message;?>
</div>
</div>
<?php
}
?>
<?php ActiveForm::end() ?>

View File

@ -1,6 +1,5 @@
<?php
use yii\widgets\Breadcrumbs;
use dmstr\widgets\Alert;
use kartik\widgets\AlertBlock;
?>

View File

@ -1,5 +1,6 @@
<?php
use yii\helpers\Html;
use common\components\Helper;
/* @var $this \yii\web\View */
/* @var $content string */
@ -16,7 +17,7 @@ use yii\helpers\Html;
</a>
<div class="navbar-header">
<a class="navbar-brand" href="#">Adminisztráció</a>
<a class="navbar-brand" href="#"> <?php echo Helper::getCompanyName() ?> Adminisztráció</a>
</div>
<div class="navbar-custom-menu">

View File

@ -1,5 +1,6 @@
<?php
use yii\helpers\Html;
use common\components\Helper;
/* @var $this \yii\web\View */
/* @var $content string */
@ -45,7 +46,7 @@ if (Yii::$app->controller->action->id === 'login') {
}
</style>
</head>
<body class="hold-transition skin-red sidebar-mini">
<body class="hold-transition <?php echo Helper::getBackendSkin()?> sidebar-mini">
<?php $this->beginBody() ?>
<div class="wrapper">

View File

@ -256,9 +256,16 @@ class Helper {
return \Yii::$app->params ['user_cart_item_visibility'] == 'user';
}
public static function getBackendSkin() {
return \Yii::$app->params ['backend_skin'] ;
}
public static function getCompany() {
return \Yii::$app->params ['company'] ;
}
public static function getCompanyName() {
return \Yii::$app->params ['company_name'] ;
}
public static function isCompanyMovar() {
return \Yii::$app->params ['company'] == 'movar';

View File

@ -17,7 +17,7 @@ return [
'login_admin_email' => true, //if admin login should send email
'account_state_close_preload_money' => 'true',//preload money wnen show account state close page
'ugiro_duplom_kod' => 1,
'ugiro_kezdemenyezo_szamlaszam' => '5860025215371128',
'ugiro_kezdemenyezo_szamlaszam' => '000000000000000',//5860025215371128
'ugiro_kezdemenyezo_azonosito' => 'A25366936T244',
//a recepicó kosár csak az aktuális user által kiadott termékeket tartalmazza
//vagy mindent
@ -26,5 +26,6 @@ return [
/**
* Hány napig láthatják visszamenőleg a recepciósok az adatokat
* */
'reception_visibility_days' => 3
'reception_visibility_days' => 3,
'backend_skin' => 'skin-red', //skin-green
];

View File

@ -94,6 +94,8 @@ class Key extends \yii\db\ActiveRecord
return $result;
}
/**
* @param yii\db\Query $query
* */

View File

@ -41,7 +41,16 @@ class KeyToggleForm extends Model
}
public function toggleKey(){
$this->keyModel = Key::find()->andWhere(['rfid_key' => $this->key])->one();
$query= Key::find();
$query->andWhere(['or',
['and',[ 'in','key.number' , [$this->key]],"trim(coalesce(key.number, '')) <>'' " ],
['and', ['in','key.rfid_key' ,[ $this->key ] ],"trim(coalesce(key.rfid_key, '')) <>'' "],
]);
$this->keyModel = $query->one();
if ( isset($this->keyModel) ){
$assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
if ( count($assignments) > 0){