door card pass: create table and create model and console controller
This commit is contained in:
parent
3daa39a0b6
commit
4d44b1c2af
@ -543,4 +543,9 @@ class Helper {
|
||||
public static function isRestAllowVerifyOnly() {
|
||||
return \Yii::$app->params ['rest_allow_verify_only'] == true;
|
||||
}
|
||||
|
||||
public static function getDoorEntryStrategy(){
|
||||
return Helper::getArrayValue(\Yii::$app->params ,'door_entry_strategy','strategy_key');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
public static $FLAG_KEY = 2; //key status
|
||||
public static $FLAG_STATUS = 3; //allowed/disabled
|
||||
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
|
||||
@ -77,6 +78,22 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
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 = '
|
||||
update card set flag = CASE WHEN status = 20 then (flag | 1 << 3) else ( flag & ~(1 << 3 ) ) end
|
||||
|
||||
50
common/models/DoorCardPass.php
Normal file
50
common/models/DoorCardPass.php
Normal 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 [
|
||||
];
|
||||
}
|
||||
}
|
||||
29
console/controllers/DoorCardPassController.php
Normal file
29
console/controllers/DoorCardPassController.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
58
console/migrations/m230126_202055_create_table_door_card_pass.php
Executable file
58
console/migrations/m230126_202055_create_table_door_card_pass.php
Executable 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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
76
frontend/controllers/DoorCardPassController.php
Normal file
76
frontend/controllers/DoorCardPassController.php
Normal 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.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -62,24 +62,24 @@ $card = $model->card;
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?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']) ?>
|
||||
<?php
|
||||
$doorEntryStrategy = \common\components\Helper::getDoorEntryStrategy();
|
||||
if ( $doorEntryStrategy === 'door_pass'){
|
||||
echo $this->render(
|
||||
'//common/door_entry_strategy/_strategy_door_pass',
|
||||
[
|
||||
'model' => $model
|
||||
]);
|
||||
}else {
|
||||
echo $this->render(
|
||||
'//common/door_entry_strategy/_strategy_key',
|
||||
[
|
||||
'model' => $model
|
||||
]);
|
||||
}
|
||||
|
||||
</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(); ?>
|
||||
|
||||
<?php if ( isset($model->customer) ) { ?>
|
||||
<?php $form = ActiveForm::begin([
|
||||
|
||||
@ -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(); ?>
|
||||
30
frontend/views/common/door_entry_strategy/_strategy_key.php
Normal file
30
frontend/views/common/door_entry_strategy/_strategy_key.php
Normal 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(); ?>
|
||||
Loading…
Reference in New Issue
Block a user