From 4d7c2bd3734924676f7427262b2c8e2b7e070eed Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 9 Aug 2024 19:28:17 +0700 Subject: [PATCH] if has keyword, then add to user recharge --- system/autoload/Package.php | 13 +++++-------- system/autoload/Validator.php | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 96e1c75b..8d042812 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -276,11 +276,9 @@ class Package } } //} - // if started with voucher, don't insert into tbl_user_recharges - // this is not necessary, but in case a bug come - if (strlen($p['device']) > 7 && substr($p['device'], 0, 7) == 'Voucher') { - // maybe something need in here for buy Voucher - }else{ + + // if contains 'mikrotik', 'hotspot', 'pppoe', 'radius' then recharge it + if (Validator::containsKeyword($p['device'])) { $b->customer_id = $id_customer; $b->username = $c['username']; $b->plan_id = $plan_id; @@ -392,10 +390,9 @@ class Package ); } } - // if started with voucher, don't insert into tbl_user_recharges - if (strlen($p['device']) > 7 && substr($p['device'], 0, 7) == 'Voucher') { - }else{ + // if contains 'mikrotik', 'hotspot', 'pppoe', 'radius' then recharge it + if (Validator::containsKeyword($p['device'])) { $d = ORM::for_table('tbl_user_recharges')->create(); $d->customer_id = $id_customer; $d->username = $c['username']; diff --git a/system/autoload/Validator.php b/system/autoload/Validator.php index c200a2bf..c435fe95 100644 --- a/system/autoload/Validator.php +++ b/system/autoload/Validator.php @@ -301,23 +301,30 @@ class Validator return (bool)in_array($format, $formats); } - public static function countRouterPlan($plans, $router){ + public static function countRouterPlan($plans, $router) + { $n = 0; - foreach ($plans as $plan){ - if($plan['routers'] == $router){ + foreach ($plans as $plan) { + if ($plan['routers'] == $router) { $n++; } } return $n; } - public static function isRouterHasPlan($plans, $router){ - foreach ($plans as $plan){ - if($plan['routers'] == $router){ + public static function isRouterHasPlan($plans, $router) + { + foreach ($plans as $plan) { + if ($plan['routers'] == $router) { return true; } } return false; } + public static function containsKeyword($string, $keywords = ['mikrotik', 'hotspot', 'pppoe', 'radius', 'dummy']) + { + $regex = '/' . implode('|', $keywords) . '/i'; + return preg_match($regex, $string); + } }