Add new flag / flag_out logick

This commit is contained in:
2016-09-25 13:32:27 +02:00
parent d46e717b53
commit 0ad2dafdeb
19 changed files with 389 additions and 29 deletions

View File

@@ -385,7 +385,13 @@ class Helper {
}
return $flag;
}
public static function isBitOn($flag,$n){
$result = +$flag & (1 << +$n) ;
$result = $result > 0;
return $result ;
}
public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWX' ) {
$charactersLength = strlen($characters);

View File

@@ -15,6 +15,7 @@ use common\components\Helper;
* @property integer $flag
* @property string $created_at
* @property string $updated_at
* @property int flag_out
*/
class Card extends \common\models\BaseFitnessActiveRecord
{
@@ -30,7 +31,23 @@ class Card extends \common\models\BaseFitnessActiveRecord
public static $FLAG_TICKET = 0;
public static $FLAG_STATUS = 1;
public static $FLAG_DOOR = 1;
public static $FLAG_KEY = 2;
public static $FLAG_STATUS = 3;
/**
* This script is used in daily scripts, to clear the flag door log status
*
* @var string
*/
public static $SQL_CLEARS_STATUS_DOOR = "
UPDATE card set flag = ( flag & ~(1 << 1 ) ), flag_out= ( flag_out & ~(1 << 1 ) ) where card.type <> 50
";
public static $SQL_CLEARS_STATUS_DOOR_IN = "
UPDATE card set flag = ( flag & ~(1 << 1 ) ) WHERE card.type <> 50 and card.id_card = :id
";
/**
* @inheritdoc
*/
@@ -175,13 +192,17 @@ class Card extends \common\models\BaseFitnessActiveRecord
return ;
}
$db = \Yii::$app->db;
$command = $db->createCommand(Ticket::$SQL_UPDATE_CARD,[':id' => $id]);
$command->execute();
$command = $db->createCommand(Card::$SQL_CLEARS_STATUS_DOOR_IN,[':id' => $id]);
$command->execute();
}
public function beforeSave($insert) {
if (parent::beforeSave($insert)){
$this->flag = Helper::setBit($this->flag, Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE));
$this->flag = Helper::setBit( $this->flag , Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE ) );
return true;
}
return false;
@@ -189,7 +210,42 @@ class Card extends \common\models\BaseFitnessActiveRecord
public function getFlagText(){
return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->flag, "Ismeretlen");
return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->validity, "Ismeretlen");
}
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);
}
public function isFlagValidity(){
return Helper::isBitOn($this->flag,Card::$FLAG_TICKET);
}
public function isFlagDoor(){
return Helper::isBitOn($this->flag,Card::$FLAG_DOOR);
}
public function isFlagKey(){
return Helper::isBitOn($this->flag,Card::$FLAG_KEY);
}
public function isFlagStatus(){
return Helper::isBitOn($this->flag,Card::$FLAG_STATUS);
}
public function isFlagOutDoor(){
return Helper::isBitOn($this->flag_out,Card::$FLAG_DOOR);
}
public function isFlagOutKey(){
return Helper::isBitOn($this->flag_out,Card::$FLAG_KEY);
}
}

View File

@@ -188,7 +188,7 @@ class DoorLog extends \yii\db\ActiveRecord
$dlog->id_account = Account::readDefault();
if ( $dlog->direction == 0){
$dlog->card_flag = $card->flag;
$dlog->card_flag = $card->validity;
}else{
$dlog->card_flag = -1;
}

View File

@@ -47,7 +47,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
order by id_card desc
) as t
on t.id_card = c1.id_card
SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
, c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
, c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end
WHERE c1.type <> 50";
@@ -63,7 +64,8 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
order by id_card desc
) as t
on t.id_card = c1.id_card
SET c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
SET c1.validity = case when t.id_card is null then ( c1.validity | 1 << 0 ) else ( c1.validity & ~(1 << 0) ) end
,c1.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
, c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end
WHERE c1.type <> 50 and c1.id_card = :id";