From 9c25312cf1540931c0526f6206ff1e39de7113bf Mon Sep 17 00:00:00 2001 From: Roland Schneider Date: Fri, 11 Mar 2016 07:41:51 +0100 Subject: [PATCH] status flag --- backend/controllers/CardController.php | 1 - backend/models/CardSearch.php | 5 +++++ backend/views/card/index.php | 9 +++++++++ common/components/Helper.php | 11 +++++++++++ common/models/Card.php | 17 +++++++++++++++++ common/models/DoorLog.php | 4 +++- common/models/Ticket.php | 5 +++-- cutler_daily.sh | 2 +- 8 files changed, 49 insertions(+), 5 deletions(-) diff --git a/backend/controllers/CardController.php b/backend/controllers/CardController.php index 401c718..ca844b7 100644 --- a/backend/controllers/CardController.php +++ b/backend/controllers/CardController.php @@ -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' diff --git a/backend/models/CardSearch.php b/backend/models/CardSearch.php index f71af90..19e8035 100644 --- a/backend/models/CardSearch.php +++ b/backend/models/CardSearch.php @@ -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], + ], ] ] ]); diff --git a/backend/views/card/index.php b/backend/views/card/index.php index b088d21..3c9f955 100644 --- a/backend/views/card/index.php +++ b/backend/views/card/index.php @@ -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"); + } + ], [ diff --git a/common/components/Helper.php b/common/components/Helper.php index ac79953..47f669b 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -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 = ''; diff --git a/common/models/Card.php b/common/models/Card.php index 6aa549b..eda0f6a 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -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"); + } + } diff --git a/common/models/DoorLog.php b/common/models/DoorLog.php index 63f1fd2..1c334b2 100644 --- a/common/models/DoorLog.php +++ b/common/models/DoorLog.php @@ -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", ]; } diff --git a/common/models/Ticket.php b/common/models/Ticket.php index 913f5e0..f3c4cc0 100644 --- a/common/models/Ticket.php +++ b/common/models/Ticket.php @@ -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"; /** diff --git a/cutler_daily.sh b/cutler_daily.sh index e5f5bfe..a65f641 100644 --- a/cutler_daily.sh +++ b/cutler_daily.sh @@ -1,2 +1,2 @@ -php yii ticket/index \ No newline at end of file +php /var/www/virtual/fitnessadmin.hu/htdocs/cutler/yii ticket/index \ No newline at end of file