Add new flag / flag_out logick
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user