status flag

This commit is contained in:
Roland Schneider 2016-03-11 07:41:51 +01:00
parent bc74d92463
commit 9c25312cf1
8 changed files with 49 additions and 5 deletions

View File

@ -113,7 +113,6 @@ class CardController extends \backend\controllers\BackendController {
*/
public function actionUpdate($id) {
$model = $this->findModel ( $id );
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
return $this->redirect ( [
'index'

View File

@ -63,6 +63,7 @@ class CardSearch extends Card
'customer.name as customer_name' ,
'customer.id_customer as customer_id_customer',
'key.number as key_number',
'card.flag as card_flag',
]);
@ -106,6 +107,10 @@ class CardSearch extends Card
'asc' => ['key.number' => SORT_ASC ],
'desc' => ['key.number' => SORT_DESC],
],
'card_flag' => [
'asc' => ['card.flag' => SORT_ASC ],
'desc' => ['card.flag' => SORT_DESC],
],
]
]
]);

View File

@ -4,6 +4,8 @@ use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Card;
use yii\helpers\Url;
use common\components\Helper;
use common\models\DoorLog;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\CardSearch */
@ -66,6 +68,13 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'key_number',
'label' => 'Kulcs száma'
],
[
'attribute' => 'card_flag',
'label' => 'Info',
'value' => function ($model, $key, $index, $column){
return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $model['card_flag'], "Ismeretlen ok");
}
],
[

View File

@ -368,6 +368,17 @@ class Helper {
return $result;
}
public static function setBit($val,$index,$bit_on){
$flag = +$val;
if ( $bit_on ){
$flag |= 1 << $index;
}else{
$flag &= ~ (1 << $index);
}
return $flag;
}
public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWX' ) {
$charactersLength = strlen($characters);
$randomString = '';

View File

@ -12,6 +12,7 @@ use common\components\Helper;
* @property string $number
* @property integer $status
* @property integer $type
* @property integer $flag
* @property string $created_at
* @property string $updated_at
*/
@ -27,6 +28,9 @@ class Card extends \common\models\BaseFitnessActiveRecord
const TYPE_OLD = 40;
const TYPE_EMPLOYEE = 50;
public static $FLAG_TICKET = 0;
public static $FLAG_STATUS = 1;
/**
* @inheritdoc
*/
@ -172,4 +176,17 @@ class Card extends \common\models\BaseFitnessActiveRecord
$command->execute();
}
public function beforeSave($insert) {
if (parent::beforeSave($insert)){
$this->flag = Helper::setBit($this->flag, Card::$FLAG_STATUS, ( $this->status != Card::STATUS_ACTIVE));
return true;
}
return false;
}
public function getFlagText(){
return Helper::getArrayValue(DoorLog::getCardFlagTexts(), $this->flag, "Ismeretlen");
}
}

View File

@ -143,8 +143,10 @@ class DoorLog extends \yii\db\ActiveRecord
public static function getCardFlagTexts( ){
return [
0 => "Kártya ok",
0 => "Kártya érvényes bérlettel",
1 => "Nincs érvényes bérlet",
2 => "Kártya inaktív/Érvényes bérlet",
3 => "Kártya inaktív/Nincs érvényes bérlet",
];
}

View File

@ -40,14 +40,15 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
left JOIN ( select distinct ticket.id_card as id_card from ticket
where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) 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.flag = case when t.id_card is null then ( c1.flag | 1 << 0 ) else ( c1.flag & ~(1 << 0) ) end
WHERE c1.type <> 50";
public static $SQL_UPDATE_CARD = "UPDATE card as c1
left JOIN ( select distinct ticket.id_card as id_card from ticket
where ticket.start <= CURDATE() and ticket.end >= curdate() and ticket.status = 10 ) 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
WHERE c1.id_card = :id";
WHERE c1.type <> 50 and c1.id_card = :id";
/**

View File

@ -1,2 +1,2 @@
php yii ticket/index
php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/index