Files
wticreatorstudio/Modules/ReferralSystem/Services/AugmentationService.php
T
2024-02-12 22:54:20 -05:00

298 lines
14 KiB
PHP

<?php
namespace Modules\ReferralSystem\Services;
use File;
class AugmentationService
{
public function __construct() {
$this->updateProfileMenu();
$this->updateStaffPortalRegister();
$this->updateClientPortalRegister();
$this->updateRegisterController();
$this->addReferralBonusDisburser();
$this->addCreateChannel();
$this->copyLangFile();
}
public function updateProfileMenu() {
$path = resource_path('views/backEnd/partials/_menu.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/@if \(isModuleActive\('ReferralSystem'\)\)/", $content)) {
$matches = null;
preg_match('/<a href="{{route\(\'user\.candidate\.index\'\)}}">{{__[.\s\S]+?<\/a>/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
<a href=\"{{route('user.candidate.index')}}\">{{__('customer_panel.my_profile')}}<i class=\"ti-user\"></i></a>
@if (isModuleActive('ReferralSystem'))
<a href=\"{{route('referrals.index')}}\">{{__('referralsystem::common.my_referrals')}}<i class=\"fas fa-users\"></i></a>
@endif
";
$code = $snippet;
$content = preg_replace('/<a href="{{route\(\'user\.candidate\.index\'\)}}">{{__[.\s\S]+?<\/a>/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function updateStaffPortalRegister() {
if (isModuleActive('StaffPortal')) {
$path = module_path('StaffPortal', 'Resources/views/components/_staff_register_form.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/session\(\)\-\>get\(\'referral_code\'\)/", $content)) {
$matches = null;
preg_match('/value="{{ old\(\'referral_code\'\) }}"/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "value=\"{{ old('referral_code') ?? session()->get('referral_code') }}\"";
$code = $snippet.$code;
$content = preg_replace('/value="{{ old\(\'referral_code\'\) }}"/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function updateClientPortalRegister() {
if (isModuleActive('StaffPortal')) {
$path = module_path('StaffPortal', 'Resources/views/components/_client_register_form.blade.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/session\(\)\-\>get\(\'referral_code\'\)/", $content)) {
$matches = null;
preg_match('/value="{{ old\(\'referral_code\'\) }}"/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "value=\"{{ old('referral_code') ?? session()->get('referral_code') }}\"";
$code = $snippet.$code;
$content = preg_replace('/value="{{ old\(\'referral_code\'\) }}"/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function updateRegisterController() {
$path = app_path('Http/Controllers/Auth/RegisterController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/function staffRegister[.\s\S]+?Rule\:\:exists\(\'users\'\, \'referral_code\'\)/", $content)) {
$matches = null;
preg_match("/[.\s\S]+function staffRegister[.\s\S]+?Rule\:\:exists\(\'referral_codes\'\, \'referral_code\'\)\-\>where\(\'status\'\, 1\)\]\,/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "Rule::exists('users', 'referral_code')->where('is_active',1)],";
$code = $snippet;
$content = preg_replace('/Rule\:\:exists\(\'referral_codes\'\, \'referral_code\'\)\-\>where\(\'status\'\, 1\)\]\,/', $code, $content);
$update = true;
}
}
if (!preg_match("/function staffRegister[.\s\S]+?\/\/\$this\-\>validator\(\$request\-\>all\(\)\)\-\>validate\(\)\;/", $content)) {
$matches = null;
preg_match('/function staffRegister[.\s\S]+?this\-\>validator\(\$request\-\>all\(\)\)\-\>validate\(\)\;/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = str_replace('$this->validator','//$this->validator',$code);
$code = $snippet;
$content = preg_replace('/function staffRegister[.\s\S]+?this\-\>validator\(\$request\-\>all\(\)\)\-\>validate\(\)\;/', $code, $content);
$update = true;
}
}
if (!preg_match("/function staffRegister[.\s\S]+?\$this\-\>create\(\$request,106\)/", $content)) {
$matches = null;
preg_match('/function staffRegister[.\s\S]+?\$this\-\>create\(\$request\,8\)/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\$this->create(\$request,106)";
$code = $snippet;
$content = preg_replace('/\$this\-\>create\(\$request\,8\)/', $code, $content);
$update = true;
}
}
if (!preg_match("/function staffRegister[.\s\S]+?\$authRepos\-\>getRegister\(\$request\-\>all\(\)\,106\)/", $content)) {
$matches = null;
preg_match('/function staffRegister[.\s\S]+?\$authRepos\-\>getRegister\(\$request\-\>all\(\)\,8\)/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "getRegister(\$request->all(),106)";
$code = $snippet;
$content = preg_replace('/getRegister\(\$request\-\>all\(\)\,8\)/', $code, $content);
$update = true;
}
}
if (!preg_match("/function clientRegister[.\s\S]+?Rule\:\:exists\(\'users\'\, \'referral_code\'\)/", $content)) {
$matches = null;
preg_match("/[.\s\S]+function clientRegister[.\s\S]+?Rule\:\:exists\(\'referral_codes\'\, \'referral_code\'\)\-\>where\(\'status\'\, 1\)\]\,/", $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "Rule::exists('users', 'referral_code')->where('is_active',1)],";
$code = $snippet;
$content = preg_replace('/Rule\:\:exists\(\'referral_codes\'\, \'referral_code\'\)\-\>where\(\'status\'\, 1\)\]\,/', $code, $content);
$update = true;
}
}
if (!preg_match("/function clientRegister[.\s\S]+?\/\/\$this\-\>validator\(\$request\-\>all\(\)\)\-\>validate\(\)\;/", $content)) {
$matches = null;
preg_match('/function clientRegister[.\s\S]+?this\-\>validator\(\$request\-\>all\(\)\)\-\>validate\(\)\;/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = str_replace('$this->validator','//$this->validator',$code);
$code = $snippet;
$content = preg_replace('/function clientRegister[.\s\S]+?this\-\>validator\(\$request\-\>all\(\)\)\-\>validate\(\)\;/', $code, $content);
$update = true;
}
}
// if (!preg_match("/function clientRegister[.\s\S]+?\$this\-\>create\(\$request,105\)/", $content)) {
// $matches = null;
// preg_match('/function clientRegister[.\s\S]+?\$this\-\>create\(\$request\)/', $content, $matches);
// if (count($matches) > 0) {
// $code = $matches[0];
// $snippet = "\$this->create(\$request,105)";
// $code = $snippet;
// $content = preg_replace('/\$this\-\>create\(\$request\)/', $code, $content);
// $update = true;
// }
// }
if (!preg_match("/isModuleActive\(\'ReferralSystem\'\)/", $content)) {
$matches = null;
preg_match('/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?referral_code[.\s\S]+?}[.\s\S]+?}/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\n\n\t\tif(isModuleActive('ReferralSystem') && isset(\$data['referral_code'])){\n\t\t\t\$referrer = User::where('referral_code', \$data['referral_code'])->first();\n\t\t\t\$user->referrer_id = \$referrer ? \$referrer->id : null;\n\t\t\t\$user->save();\n\t\t}\n\n";
$code .= $snippet;
$content = preg_replace("/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?referral_code[.\s\S]+?}[.\s\S]+?}/", $code, $content);
$update = true;
}
}
if (!preg_match("/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?Staff\;/", $content)) {
$matches = null;
preg_match('/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?if\(isModuleActive\(\'WTISignupForms\'\)[.\s\S]+?\$user\-\>save\(\)\;/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\n\n\n\t\t\tif(\$role_id == 106){\n\t\t\t\t\$staff = new \App\Models\Staff;\n\t\t\t\t\$staff->user_id = \$user->id;\n\t\t\t\t\$staff->department_id = 25;\n\t\t\t\t\$staff->phone = \$data['phone'];\n\t\t\t\t\$staff->save();\n\t\t\t}\n\t\t}";
$code .= $snippet;
$content = preg_replace('/[.\s\S]+function create\([.\s\S]+?{[.\s\S]+?if\(isModuleActive\(\'WTISignupForms\'\)[.\s\S]+?}/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function addReferralBonusDisburser() {
if (isModuleActive('StudioPlus')) {
$path = module_path('StudioPlus', 'Http/Controllers/API/StudioPlusVideoController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/isModuleActive\('ReferralSystem'\)/", $content)) {
$matches = null;
preg_match('/\$this->addIncentiveItemToUpline\(\$user, \$studioPlusVideo\);/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "
if (isModuleActive('ReferralSystem')) {
app(\Modules\ReferralSystem\Services\CommonService::class)->disburseReferralBonusIfQualified(\$user, \$studioPlusVideo);
}
";
$code = $snippet.$code;
$content = preg_replace('/\$this->addIncentiveItemToUpline\(\$user, \$studioPlusVideo\);/', $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
}
public function addCreateChannel() {
$path = app_path('Http/Controllers/Auth/RegisterController.php');
if (file_exists($path)) {
$update = false;
$content = file_get_contents($path);
if (!preg_match("/function staffRegister[.\s\S]+?isModuleActive\(\'StudioPlus\'\)/", $content)) {
$matches = null;
preg_match('/[.\s\S]+function staffRegister\([.\s\S]+?Registered[.\s\S]+?guard\(\)\-\>login[.\s\S]+?\;/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\n\t\tif(isModuleActive('StudioPlus')){\n\t\t\t(new \Modules\StudioPlus\Services\HandleCreateChannel)->handle();\n\t\t}";
$code .= $snippet;
$content = preg_replace("/[.\s\S]+function staffRegister\([.\s\S]+?Registered[.\s\S]+?guard\(\)\-\>login[.\s\S]+?\;/", $code, $content);
$update = true;
}
}
if (!preg_match("/function clientRegister[.\s\S]+?isModuleActive\(\'StudioPlus\'\)/", $content)) {
$matches = null;
preg_match('/[.\s\S]+function clientRegister\([.\s\S]+?Registered[.\s\S]+?guard\(\)\-\>login[.\s\S]+?\;/', $content, $matches);
if (count($matches) > 0) {
$code = $matches[0];
$snippet = "\n\t\tif(isModuleActive('StudioPlus')){\n\t\t\t(new \Modules\StudioPlus\Services\HandleCreateChannel)->handle();\n\t\t}";
$code .= $snippet;
$content = preg_replace("/[.\s\S]+function clientRegister\([.\s\S]+?Registered[.\s\S]+?guard\(\)\-\>login[.\s\S]+?\;/", $code, $content);
$update = true;
}
}
if ($update) {
file_put_contents($path, $content);
}
}
}
public function copyLangFile() {
$langFile = module_path('ReferralSystem', 'Resources/lang/default/referral.php');
if (file_exists($langFile)) {
File::copy($langFile, resource_path('lang/default/referral.php'));
}
}
}