add log key assign

This commit is contained in:
2016-08-25 19:18:13 +02:00
parent 2a59952b2d
commit 9d0d0199c7
3 changed files with 59 additions and 3 deletions

View File

@@ -2,6 +2,8 @@
namespace frontend\models;
use common\models\DoorLog;
use common\models\Log;
use Yii;
use yii\base\Model;
use common\models\CardKeyAssignment;
@@ -12,6 +14,7 @@ use common\models\Card;
/**
* ContactForm is the model behind the contact form.
*
*/
class KeyToggleForm extends Model
{
@@ -20,6 +23,7 @@ class KeyToggleForm extends Model
public $customer;
public $keyModel;
public $action;
public $keyCard;
@@ -59,8 +63,19 @@ class KeyToggleForm extends Model
$this->keyCard = Card::find()->innerJoin('card_key_assignment','card.id_card = card_key_assignment.id_card')->andWhere('card_key_assignment.id_key = ' .$this->keyModel->id_key)->one();
$assignments = CardKeyAssignment::find()->andWhere(['id_key' => $this->keyModel->id_key])->all();
if ( count($assignments) > 0){
$this->unassign();
$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->card->id_card,
'id_customer' => $this->keyCard->customer->id_customer
]);
DoorLog::mkDoorLog(-1,$this->keyCard,$this->keyCard->customer,$this->keyModel );
}else{
$this->assign();
}
@@ -81,6 +96,15 @@ class KeyToggleForm extends Model
$assignment->id_user = \Yii::$app->user->id;
$assignment->save(false);
\Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' );
Log::log([
'type' =>Log::$TYPE_KEY_ASSIGN,
'message' => 'Kulcs kiadás - Kártya/Kulcs/Vendég:' .$this->card->number ."/" .$this->keyModel->number . "/".$this->customer->name,
'id_key' => $this->card->id_card,
'id_customer' => $this->customer->id_customer
]);
DoorLog::mkDoorLog(-2,$this->card,$this->customer,$this->keyModel );
}
}else{
\Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' );