door card pass: create table and create model and console controller

This commit is contained in:
Schneider Roland 2023-02-08 19:42:42 +01:00
parent 3daa39a0b6
commit 4d44b1c2af
9 changed files with 307 additions and 19 deletions

View File

@ -543,4 +543,9 @@ class Helper {
public static function isRestAllowVerifyOnly() { public static function isRestAllowVerifyOnly() {
return \Yii::$app->params ['rest_allow_verify_only'] == true; return \Yii::$app->params ['rest_allow_verify_only'] == true;
} }
public static function getDoorEntryStrategy(){
return Helper::getArrayValue(\Yii::$app->params ,'door_entry_strategy','strategy_key');
}
} }

View File

@ -42,6 +42,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
public static $FLAG_KEY = 2; //key status public static $FLAG_KEY = 2; //key status
public static $FLAG_STATUS = 3; //allowed/disabled public static $FLAG_STATUS = 3; //allowed/disabled
public static $FLAG_DOOR_ALLOWED = 4; //ticket type allows door public static $FLAG_DOOR_ALLOWED = 4; //ticket type allows door
public static $FLAG_DOOR_PASS_ALLOWED = 5; // door pass
/** /**
* This script is used in daily scripts, to clear the flag door log status * This script is used in daily scripts, to clear the flag door log status
@ -77,6 +78,22 @@ class Card extends \common\models\BaseFitnessActiveRecord
return Card::SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG() . " and card.id_card = :id "; return Card::SQL_CLEAR_STATUS_DOOR_ALLOWED_FLAG() . " and card.id_card = :id ";
} }
public static function SQL_DENY_DOOR_CARD_PASS() {
return "update card set flag = flag | (1 << " . Card::$FLAG_DOOR_PASS_ALLOWED . ") ";
}
public static function SQL_ALLOW_DOOR_CARD_PASS() {
return "update card set flag = flag | (1 << " . Card::$FLAG_DOOR_PASS_ALLOWED . ") ";
}
public static function SQL_DENY_DOOR_CARD_PASS_EXPIRED( ){
return "update card ca "
. "inner join door_card_pass dcp on ca.id_card = dcp.id_card "
. "set ca.flag = ca.flag | (1 << " . Card::$FLAG_DOOR_PASS_ALLOWED . ") , dcp.updated_at = now()"
. " WHERE "
. " dcp.updated_at <> dcp.created_at and dcp.created_at <= :datetime ";
}
public static $SQL_UPDATE_FLAG_STATUS_ACTIVE = ' public static $SQL_UPDATE_FLAG_STATUS_ACTIVE = '
update card set flag = CASE WHEN status = 20 then (flag | 1 << 3) else ( flag & ~(1 << 3 ) ) end update card set flag = CASE WHEN status = 20 then (flag | 1 << 3) else ( flag & ~(1 << 3 ) ) end

View File

@ -0,0 +1,50 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "door_card_pass".
*
*
* 'id_door_card_pass'=> $this->primaryKey(),
'id_card' => $this->integer(11),
'id_user' => $this->integer(11),
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $
* @property integer $id_door_card_pass
* @property integer $id_card
* @property integer $id_user
* @property integer $created_at
* @property integer $updated_at
*
*/
class DoorCardPass extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'door_card_pass';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
];
}
}

View File

@ -0,0 +1,29 @@
<?php
namespace console\controllers;
use common\models\Card;
use /** @noinspection PhpUnusedAliasInspection */
Yii;
use yii\console\Controller;
class DoorCardPassController extends Controller{
public function actionDenyAllCard( )
{
\Yii::$app->db->createCommand(Card::SQL_DENY_DOOR_CARD_PASS())->execute();
}
public function actionAllowAllCard( )
{
\Yii::$app->db->createCommand(Card::SQL_ALLOW_DOOR_CARD_PASS())->execute();
}
public function actionDenyExpiredCard( )
{
$now = date('Y-m-d H:i:s' );
$now = time();
\Yii::$app->db->createCommand(Card::SQL_DENY_DOOR_CARD_PASS_EXPIRED() ,['datetime'=> $now] )
->execute();
}
}

View File

@ -0,0 +1,58 @@
<?php
use yii\db\Migration;
/**
* Class m230126_202055_create_table_door_card_pass
*/
class m230126_202055_create_table_door_card_pass extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
}
$this->createTable('door_card_pass',[
'id_door_card_pass'=> $this->primaryKey(),
'id_card' => $this->integer(11),
'id_user' => $this->integer(11),
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $this->dateTime()->notNull(),
],
$tableOptions
);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m230126_202055_create_table_door_card_pass cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m230126_202055_create_table_door_card_pass cannot be reverted.\n";
return false;
}
*/
}

View File

@ -0,0 +1,76 @@
<?php
namespace frontend\controllers;
use common\models\Card;
use common\models\DoorCardPass;
use Yii;
use common\models\City;
use backend\models\CitySearch;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\base\BaseObject;
use yii\db\Query;
use yii\helpers\Json;
/**
* CityController implements the CRUD actions for City model.
*/
class DoorCardPassController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'allow-card' => ['post'],
],
],
];
}
public function actionAllowCard($idCard)
{
$card = Card::findOne($idCard);
if (!isset($card)){
throw new BadRequestHttpException("card id not found");
}
$model = new DoorCardPass();
$model->id_card = $idCard;
$model->save(false);
$this->redirect('customer/reception');
}
/**
* Displays a single City model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
}
/**
* Finds the City model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return City the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = City::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

View File

@ -61,25 +61,25 @@ $card = $model->card;
&nbsp; &nbsp;
</div> </div>
</div> </div>
<?php $form = ActiveForm::begin([ <?php
'action' => ['key/toggle', 'number' => $model->getCardNumber()], $doorEntryStrategy = \common\components\Helper::getDoorEntryStrategy();
'method' => 'post', if ( $doorEntryStrategy === 'door_pass'){
]); ?> echo $this->render(
<div class="row" style="margin-bottom: 6px;"> '//common/door_entry_strategy/_strategy_door_pass',
<div class='col-md-12'> [
<?php echo Html::hiddenInput('number', $model->getCardNumber())?> 'model' => $model
<?php echo Html::textInput('KeyToggleForm[key]','',['class'=>"form-control", 'placeholder' =>'Kulcs']) ?> ]);
}else {
</div> echo $this->render(
</div> '//common/door_entry_strategy/_strategy_key',
<div class="row"> [
<div class='col-md-12'> 'model' => $model
<?= Html::submitButton(Yii::t('frontend/collection', 'Kulcs Ki/Be'), ['class' => 'btn btn-primary btn-block']) ?> ]);
</div> }
</div> ?>
<?php ActiveForm::end(); ?>
<?php if ( isset($model->customer) ) { ?> <?php if ( isset($model->customer) ) { ?>
<?php $form = ActiveForm::begin([ <?php $form = ActiveForm::begin([

View File

@ -0,0 +1,23 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use frontend\components\HtmlHelper;
/* @var $this yii\web\View */
/* @var $card common\models\Card */
/* @var $customer common\models\Customer */
/* @var $model frontend\models\ReceptionForm */
/* @var $form yii\widgets\ActiveForm */
?>
<?php $form = ActiveForm::begin([
'action' => ['door-card-pass/allow', 'number' => $model->getCardNumber()],
'method' => 'post',
]); ?>
<div class="row">
<div class='col-md-12'>
<?= Html::submitButton( "Kapun beléphet", ['class' => 'btn btn-primary btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>

View File

@ -0,0 +1,30 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
use frontend\components\HtmlHelper;
/* @var $this yii\web\View */
/* @var $card common\models\Card */
/* @var $customer common\models\Customer */
/* @var $model frontend\models\ReceptionForm */
/* @var $form yii\widgets\ActiveForm */
?>
<?php $form = ActiveForm::begin([
'action' => ['key/toggle', 'number' => $model->getCardNumber()],
'method' => 'post',
]); ?>
<div class="row" style="margin-bottom: 6px;">
<div class='col-md-12'>
<?php echo Html::hiddenInput('number', $model->getCardNumber())?>
<?php echo Html::textInput('KeyToggleForm[key]','',['class'=>"form-control", 'placeholder' =>'Kulcs']) ?>
</div>
</div>
<div class="row">
<div class='col-md-12'>
<?= Html::submitButton(Yii::t('frontend/collection', 'Kulcs Ki/Be'), ['class' => 'btn btn-primary btn-block']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>