improve integration tests
This commit is contained in:
@@ -31,8 +31,8 @@ class KeyToggleForm extends Model
|
||||
public $action;
|
||||
|
||||
public $keyCard;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
@@ -52,20 +52,24 @@ class KeyToggleForm extends Model
|
||||
];
|
||||
}
|
||||
|
||||
public function readKey($keyNumber){
|
||||
$query= Key::find();
|
||||
$fixedKeyNumber = Helper::fixAsciiChars($keyNumber);
|
||||
// add condition rfid key or number
|
||||
$query->andWhere(['or',
|
||||
['and',[ 'in','key.number' , [$fixedKeyNumber]],"trim(coalesce(key.number, '')) <>'' " ],
|
||||
['and', ['in','key.rfid_key' ,[ $fixedKeyNumber ] ],"trim(coalesce(key.rfid_key, '')) <>'' "],
|
||||
|
||||
]);
|
||||
return $query->one();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function toggleKey(){
|
||||
$query= Key::find();
|
||||
$this->key = Helper::fixAsciiChars($this->key);
|
||||
// add condition rfid key or number
|
||||
$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();
|
||||
$this->keyModel = $this->readKey($this->key);
|
||||
//ha van ilyen kulcs
|
||||
if ( isset($this->keyModel) ){
|
||||
//find card - key assignments
|
||||
@@ -74,27 +78,7 @@ class KeyToggleForm extends Model
|
||||
$assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
|
||||
//if assignment found - we will unassign it
|
||||
if ( count($assignments) > 0){
|
||||
if ( isset( $this->keyCard ) ){
|
||||
|
||||
CardKeyAssignment::deleteAll(['id_key' => $this->keyModel->id_key]);
|
||||
$this->keyCard->setFlagsHasKey(false);
|
||||
$this->keyCard->save(false);
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kulcs visszaadva!' );
|
||||
$this->action = 'unassign';
|
||||
Log::log([
|
||||
'type' =>Log::$TYPE_KEY_ASSIGN,
|
||||
'message' => 'Kulcs visszaadás - Kártya/Kulcs/Vendég:' .$this->keyCard->number ."/" .$this->keyModel->number . "/".$this->keyCard->customer->name,
|
||||
'id_key' => $this->keyModel->id_key,
|
||||
'id_customer' => $this->keyCard->customer->id_customer
|
||||
]);
|
||||
DoorLog::mkDoorLog(-1,$this->keyCard,$this->keyCard->customer,$this->keyModel );
|
||||
}else{
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
\Yii::error("Key for assignment not found");
|
||||
/** @noinspection PhpUndefinedClassInspection */
|
||||
\Yii::$app->session->setFlash ( 'danger', 'Kulcs visszaadás hiba: kulcs nem található!' );
|
||||
}
|
||||
$this->revoke();
|
||||
}else{
|
||||
// if there is no assignment - assign it to the customer
|
||||
$this->assign();
|
||||
@@ -105,6 +89,27 @@ class KeyToggleForm extends Model
|
||||
}
|
||||
}
|
||||
|
||||
public function revoke(){
|
||||
if ( isset( $this->keyCard ) ){
|
||||
|
||||
CardKeyAssignment::deleteAll(['id_key' => $this->keyModel->id_key]);
|
||||
$this->keyCard->setFlagsHasKey(false);
|
||||
$this->keyCard->save(false);
|
||||
\Yii::$app->session->setFlash ( 'success', 'Kulcs visszaadva!' );
|
||||
$this->action = 'unassign';
|
||||
Log::log([
|
||||
'type' =>Log::$TYPE_KEY_ASSIGN,
|
||||
'message' => 'Kulcs visszaadás - Kártya/Kulcs/Vendég:' .$this->keyCard->number ."/" .$this->keyModel->number . "/".$this->keyCard->customer->name,
|
||||
'id_key' => $this->keyModel->id_key,
|
||||
'id_customer' => $this->keyCard->customer->id_customer
|
||||
]);
|
||||
DoorLog::mkDoorLog(-1,$this->keyCard,$this->keyCard->customer,$this->keyModel );
|
||||
}else{
|
||||
\Yii::error("Key for assignment not found");
|
||||
\Yii::$app->session->setFlash ( 'danger', 'Kulcs visszaadás hiba: kulcs nem található!' );
|
||||
}
|
||||
}
|
||||
|
||||
public function assign(){
|
||||
if ( isset($this->card) && isset($this->customer) ){
|
||||
$assignments = CardKeyAssignment::find()->andWhere(['id_card' => $this->card->id_card])->all();
|
||||
@@ -139,6 +144,6 @@ class KeyToggleForm extends Model
|
||||
\Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user