diff --git a/common/components/Helper.php b/common/components/Helper.php index 26ba546..81d8ff6 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -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'); + } + } diff --git a/common/models/Card.php b/common/models/Card.php index 332545a..b1bd9bd 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -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 diff --git a/common/models/DoorCardPass.php b/common/models/DoorCardPass.php new file mode 100644 index 0000000..36ecf7c --- /dev/null +++ b/common/models/DoorCardPass.php @@ -0,0 +1,50 @@ + $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 [ + ]; + } +} diff --git a/console/controllers/DoorCardPassController.php b/console/controllers/DoorCardPassController.php new file mode 100644 index 0000000..800d983 --- /dev/null +++ b/console/controllers/DoorCardPassController.php @@ -0,0 +1,29 @@ +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(); + } + +} diff --git a/console/migrations/m230126_202055_create_table_door_card_pass.php b/console/migrations/m230126_202055_create_table_door_card_pass.php new file mode 100755 index 0000000..d0b03f1 --- /dev/null +++ b/console/migrations/m230126_202055_create_table_door_card_pass.php @@ -0,0 +1,58 @@ +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; + } + */ +} diff --git a/frontend/controllers/DoorCardPassController.php b/frontend/controllers/DoorCardPassController.php new file mode 100644 index 0000000..55479af --- /dev/null +++ b/frontend/controllers/DoorCardPassController.php @@ -0,0 +1,76 @@ + [ + '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.'); + } + } + +} diff --git a/frontend/views/common/_reception_menu.php b/frontend/views/common/_reception_menu.php index 1824bd4..4cecceb 100644 --- a/frontend/views/common/_reception_menu.php +++ b/frontend/views/common/_reception_menu.php @@ -61,25 +61,25 @@ $card = $model->card;   - - ['key/toggle', 'number' => $model->getCardNumber()], - 'method' => 'post', - ]); ?> -
-
- getCardNumber())?> - "form-control", 'placeholder' =>'Kulcs']) ?> - -
-
-
-
- 'btn btn-primary btn-block']) ?> -
- -
- + + render( + '//common/door_entry_strategy/_strategy_door_pass', + [ + 'model' => $model + ]); + }else { + echo $this->render( + '//common/door_entry_strategy/_strategy_key', + [ + 'model' => $model + ]); + } + + ?> + customer) ) { ?> + ['door-card-pass/allow', 'number' => $model->getCardNumber()], + 'method' => 'post', +]); ?> +
+
+ 'btn btn-primary btn-block']) ?> +
+ +
+ diff --git a/frontend/views/common/door_entry_strategy/_strategy_key.php b/frontend/views/common/door_entry_strategy/_strategy_key.php new file mode 100644 index 0000000..d6b9c2e --- /dev/null +++ b/frontend/views/common/door_entry_strategy/_strategy_key.php @@ -0,0 +1,30 @@ + + ['key/toggle', 'number' => $model->getCardNumber()], + 'method' => 'post', +]); ?> +
+
+ getCardNumber())?> + "form-control", 'placeholder' =>'Kulcs']) ?> + +
+
+
+
+ 'btn btn-primary btn-block']) ?> +
+ +
+