From 6de07dac93b88d66456717d0bf23db7a855bbd1a Mon Sep 17 00:00:00 2001 From: rocho Date: Thu, 29 Dec 2016 19:17:31 +0100 Subject: [PATCH] restore flag_out logic, toggleKey logic --- backend/controllers/CardController.php | 14 ++-- changelog.txt | 3 + common/config/params.php | 2 +- common/models/Card.php | 46 ++++++++----- common/models/Log.php | 2 +- console/controllers/TicketController.php | 8 +-- frontend/models/KeyToggleForm.php | 84 ++++++++++++++---------- trigger_door_log_flag_out.sql | 8 +-- 8 files changed, 100 insertions(+), 67 deletions(-) diff --git a/backend/controllers/CardController.php b/backend/controllers/CardController.php index d3c9ce9..78b57de 100644 --- a/backend/controllers/CardController.php +++ b/backend/controllers/CardController.php @@ -391,13 +391,13 @@ class CardController extends \backend\controllers\BackendController { \Yii::info("Tickets updated: " . $result ); \Yii::$app->session->setFlash('success', 'Módosított bérletek száma: ' . $result); -// $command = $connection->createCommand( Card::$SQL_CLEARS_STATUS_DOOR ); -// $result = $command->execute(); -// \Yii::info("Door flag cleared: " . $result ); -// -// $command = $connection->createCommand( Card::$SQL_FIX_KEY_STATUS ); -// $result = $command->execute(); -// \Yii::info("Key flag fixed: " . $result ); + $command = $connection->createCommand( Card::$SQL_CLEARS_STATUS_DOOR ); + $result = $command->execute(); + \Yii::info("Door flag cleared: " . $result ); + + $command = $connection->createCommand( Card::$SQL_FIX_KEY_STATUS ); + $result = $command->execute(); + \Yii::info("Key flag fixed: " . $result ); diff --git a/changelog.txt b/changelog.txt index 7dfba21..b73b690 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +-0.0.94 + - restore flag_out logic + - add toggleKey changes -0.0.93 - add shebang line to botond_daily script -0.0.92 diff --git a/common/config/params.php b/common/config/params.php index 9d4d6e3..3156041 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -5,7 +5,7 @@ return [ 'supportEmail' => 'rocho02@gmail.com', 'infoEmail' => 'info@rocho-net.hu', 'user.passwordResetTokenExpire' => 3600, - 'version' => 'v0.0.93', + 'version' => 'v0.0.94', 'company' => 'movar',//gyor 'company_name' => "Freimann Kft.", 'product_visiblity' => 'account',// on reception which products to display. account or global diff --git a/common/models/Card.php b/common/models/Card.php index 33c0b49..a484d8a 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -5,6 +5,8 @@ namespace common\models; use Yii; use common\components\Helper; +/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ + /** * This is the model class for table "card". * @@ -17,6 +19,7 @@ use common\components\Helper; * @property string $updated_at * @property int flag_out * @property \common\models\Customer $customer relation + * @property mixed validity */ class Card extends \common\models\BaseFitnessActiveRecord { @@ -86,6 +89,7 @@ class Card extends \common\models\BaseFitnessActiveRecord */ public function attributeLabels() { + /** @noinspection PhpUndefinedClassInspection */ return [ 'id_card' => Yii::t('common/card', 'Id Card'), 'number' => Yii::t('common/card', 'Number'), @@ -98,15 +102,18 @@ class Card extends \common\models\BaseFitnessActiveRecord } - public function validateAscii($attribute,$params){ + public function validateAscii($attribute, /** @noinspection PhpUnusedParameterInspection */ + $params){ if ( !$this->hasErrors($this->$attribute)){ $this->$attribute = Helper::fixAsciiChars($this->$attribute); - Yii::info(" $attribute converted to: " . $this->$attribute); + /** @noinspection PhpUndefinedClassInspection */ + Yii::info(" $attribute converted to: " . $this->$attribute); } } static function statuses() { - return [ + /** @noinspection PhpUndefinedClassInspection */ + return [ self::STATUS_ACTIVE => Yii::t('common/card', 'Active'), self::STATUS_DELETED => Yii::t('common/card', 'Inactive'), ]; @@ -114,7 +121,7 @@ class Card extends \common\models\BaseFitnessActiveRecord public function getStatusHuman(){ $result = null; - $s = self::statuses($this->status); + $s = self::statuses(); if ( array_key_exists($this->status, $s)){ $result = $s[$this->status]; } @@ -128,7 +135,8 @@ class Card extends \common\models\BaseFitnessActiveRecord } static function types() { - return [ + /** @noinspection PhpUndefinedClassInspection */ + return [ self::TYPE_RFID => Yii::t('common/card', 'RFID'), self::TYPE_QRCODE => Yii::t('common/card', 'QRCODE'), self::TYPE_BARCODE => Yii::t('common/card', 'BARCODE'), @@ -139,7 +147,7 @@ class Card extends \common\models\BaseFitnessActiveRecord public function getTypeHuman(){ $result = null; - $s = self::types($this->type); + $s = self::types(); if ( array_key_exists($this->type, $s)){ $result = $s[$this->type]; } @@ -182,18 +190,24 @@ class Card extends \common\models\BaseFitnessActiveRecord public function getCustomerName(){ $name = null; - $customer = $this->customer; if ( $this->customer != null){ $name = $this->customer->name; } return $name; } - - public static function addCardNumberCondition($query,$number, $field_number = "card.number",$field_rfid_key = "card.rfid_key"){ + + /** @noinspection PhpUndefinedClassInspection */ + + /** + * @param \yii\db\Query $query + * @param number $number + * @param string $field_number + * @param string $field_rfid_key + */ + public static function addCardNumberCondition($query, $number, $field_number = "card.number", $field_rfid_key = "card.rfid_key"){ $query->andWhere(['or', ['and',[ 'in',$field_number , [$number]],"trim(coalesce(card.number, '')) <>'' " ], ['and', ['in',$field_rfid_key ,[ $number ] ],"trim(coalesce(card.rfid_key, '')) <>'' "], - ]); } @@ -201,7 +215,8 @@ class Card extends \common\models\BaseFitnessActiveRecord if ( !isset($id)){ return ; } - $db = \Yii::$app->db; + /** @noinspection PhpUndefinedClassInspection */ + $db = \Yii::$app->db; $command = $db->createCommand(Ticket::$SQL_UPDATE_CARD,[':id' => $id]); $command->execute(); @@ -224,11 +239,10 @@ class Card extends \common\models\BaseFitnessActiveRecord } public function setFlagsHasKey($hasKey){ - - $pos = Card::$FLAG_KEY; -// $this->flag = $hasKey ? ( $this->flag & ~(1 << $pos) ) : ( $this->flag | 1 << $pos ); -// $this->flag_out = $hasKey ? ( $this->flag_out | 1 << $pos ) : ( $this->flag_out & ~(1 << $pos) ); -// \Yii::info("flag has key: ".$this->flag .";".$this->flag_out); + $this->flag = $hasKey ? ( $this->flag & ~(1 << Card::$FLAG_KEY) ) : ( $this->flag | 1 << Card::$FLAG_KEY ); + $this->flag_out = $hasKey ? ( $this->flag_out | 1 << Card::$FLAG_KEY ) : ( $this->flag_out & ~(1 << Card::$FLAG_KEY) ); + /** @noinspection PhpUndefinedClassInspection */ + \Yii::info("flag has key: ".$this->flag .";".$this->flag_out); } diff --git a/common/models/Log.php b/common/models/Log.php index e9f0243..32c5877 100644 --- a/common/models/Log.php +++ b/common/models/Log.php @@ -111,7 +111,7 @@ class Log extends BaseFitnessActiveRecord 'type' =>Log::$TYPE_LOGIN, 'message' => $message ]); - * @param unknown $config + * @param array $config */ public static function log( $config ){ $model = new Log($config); diff --git a/console/controllers/TicketController.php b/console/controllers/TicketController.php index 46b4a91..a063c97 100644 --- a/console/controllers/TicketController.php +++ b/console/controllers/TicketController.php @@ -28,10 +28,10 @@ class TicketController extends Controller { $command = $connection->createCommand ( Ticket::$SQL_UPDATE ); $result = $command->execute (); \Yii::info ( "Tickets updated: " . $result ); -// -// -// $command = $connection->createCommand ( Card::$SQL_FIX_KEY_STATUS ); -// $result = $command->execute (); + + + $command = $connection->createCommand ( Card::$SQL_FIX_KEY_STATUS ); + $result = $command->execute (); } /** diff --git a/frontend/models/KeyToggleForm.php b/frontend/models/KeyToggleForm.php index 9e97cf3..e315f24 100644 --- a/frontend/models/KeyToggleForm.php +++ b/frontend/models/KeyToggleForm.php @@ -4,19 +4,22 @@ namespace frontend\models; use common\models\DoorLog; use common\models\Log; -use Yii; -use yii\base\Model; +use /** @noinspection PhpUndefinedClassInspection */ + yii\base\Model; use common\models\CardKeyAssignment; use common\models\Key; -use yii\helpers\ArrayHelper; use common\components\Helper; use common\models\Card; +/** @noinspection PhpUndefinedClassInspection */ + /** * ContactForm is the model behind the contact form. * * @property \common\models\Card $card * @property \common\models\Key $key + * @property \common\models\Key $keyModel + * @property \common\models\Card $keyCard * */ class KeyToggleForm extends Model @@ -48,42 +51,57 @@ class KeyToggleForm extends Model return [ ]; } - + + /** + * + */ 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(); - - if ( isset($this->keyModel) ){ + //ha van ilyen kulcs + if ( isset($this->keyModel) ){ + //find card - key assignments + /** @var /common/models/Card keyCard */ $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 assignment found - we will unassign it if ( count($assignments) > 0){ + if ( isset( $this->keyCard ) ){ - $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 ); - + 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->card->id_card, + '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ó!' ); + } }else{ + // if there is no assignment - assign it to the customer $this->assign(); } }else{ - \Yii::$app->session->setFlash ( 'danger', 'Kulcs nem található!' ); + /** @noinspection PhpUndefinedClassInspection */ + \Yii::$app->session->setFlash ( 'danger', 'Kulcs nem található!' ); } } @@ -91,14 +109,17 @@ class KeyToggleForm extends Model if ( isset($this->card) && isset($this->customer) ){ $assignments = CardKeyAssignment::find()->andWhere(['id_card' => $this->card->id_card])->all(); if ( count($assignments) > 0 ){ - \Yii::$app->session->setFlash ( 'danger', 'A vendégnél egyszerre csak egy kulcs lehet' ); + /** @noinspection PhpUndefinedClassInspection */ + \Yii::$app->session->setFlash ( 'danger', 'A vendégnél egyszerre csak egy kulcs lehet' ); }else{ $assignment = new CardKeyAssignment(); $assignment->id_card = $this->card->id_card; $assignment->id_key = $this->keyModel->id_key; - $assignment->id_user = \Yii::$app->user->id; + /** @noinspection PhpUndefinedClassInspection */ + $assignment->id_user = \Yii::$app->user->id; $assignment->save(false); - \Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' ); + /** @noinspection PhpUndefinedClassInspection */ + \Yii::$app->session->setFlash ( 'success', 'Kulcs kiadva!' ); $this->card->setFlagsHasKey(true); $this->card->save(false); @@ -113,15 +134,10 @@ class KeyToggleForm extends Model 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!' ); + /** @noinspection PhpUndefinedClassInspection */ + \Yii::$app->session->setFlash ( 'danger', 'Nincs vendég kiválasztva vagy érvénytelen kártya!' ); } } - public function unassign(){ - CardKeyAssignment::deleteAll(['id_key' => $this->keyModel->id_key]); - $this->card->setFlagsHasKey(false); - $this->card->save(false); - \Yii::$app->session->setFlash ( 'success', 'Kulcs visszaadva!' ); - } - + } diff --git a/trigger_door_log_flag_out.sql b/trigger_door_log_flag_out.sql index d10ed0b..4a4cbf8 100644 --- a/trigger_door_log_flag_out.sql +++ b/trigger_door_log_flag_out.sql @@ -74,7 +74,7 @@ begin END IF; -- end @p_count_all_2 = 1 END IF; -- @p_count_all > 1 End IF; -- vége bemozgás érvényes bérlettel end type == 7 or 3 ( move in ) - + -- KILÉPÉS -- count_move_out beállítása usage_count-ra IF NEW.direction = 5 or New.direction = 1 -- type move out then @@ -150,8 +150,8 @@ begin END IF; */ - INSERT INTO devlog ( msg) values( concat( 'Kilépés: Aktuális bérlet/belépések száma/többszire belépés on/belépés on: ' - , coalesce(@p_mo_ticket_id,''),'/', coalesce(@p_count_all,'') , '/', coalesce(@p_allow_multiple_enter,''),'/', coalesce(@p_allow_enter,'' ) ) ); + -- INSERT INTO devlog ( msg) values( concat( 'Kilépés: Aktuális bérlet/belépések száma/többszire belépés on/belépés on: ' + -- , coalesce(@p_mo_ticket_id,''),'/', coalesce(@p_count_all,'') , '/', coalesce(@p_allow_multiple_enter,''),'/', coalesce(@p_allow_enter,'' ) ) ); update card set flag_out = ( flag_out | 1 << 1 ) , -- nem léphet ki ( 1. bit beállíátsa 1-re ) @@ -163,7 +163,7 @@ begin -- BELÉPÉS van folyamatban - kilépés flag_out bekapcsolása, belépés flag kikapcsolása IF (NEW.direction = 7 or New.direction = 3 ) and NEW.id_ticket_current is not null THEN - INSERT INTO devlog ( msg) values( 'kilépés flag_out bekapcsolása, belépés flag kikapcsolása' ); + -- INSERT INTO devlog ( msg) values( 'kilépés flag_out bekapcsolása, belépés flag kikapcsolása' ); update card set flag_out = ( flag_out & ~(1 << 1 ) ) , -- kilpés engedélyezése ( 1. bit beállítása 0-ra ) flag = ( flag | 1 << 1 ) -- belépés nem lehetséges ( 1.bit beállítsa 1-re )