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

37 lines
1.4 KiB
PHP

<?php
namespace Modules\MLMDownline\Services;
class AugmentationService
{
public function __construct()
{
$this->addCodeToStaffIndexBlade();
}
public function addCodeToStaffIndexBlade()
{
$masterPath = resource_path('/views/backEnd/staffs/index.blade.php');
if (file_exists($masterPath)) {
$content = file_get_contents($masterPath);
$elementExists = null;
// Check added code if already exists
preg_match("/\@if\(permissionCheck\('can_have_downline'\)/", $content, $elementExists);
if ($elementExists) return;
preg_match('/\<div class\="dropdown-menu dropdown-menu-right" aria-labelledby\="dropdownMenu2"\>/', $content, $matchedElement);
$codes = "";
if ($matchedElement) {
$codes .= "{$matchedElement[0]}
@if(permissionCheck('can_have_downline') && checkUserPermission(\$staff->user, 'mlm-downline.index'))
<a href=\"{{ route('can_have_downline', \$staff->id) }}\" class=\"dropdown-item\">Downline</a>
@endif
";
$appendContent = preg_replace('/\<div class\="dropdown-menu dropdown-menu-right" aria-labelledby\="dropdownMenu2"\>/', $codes, $content);
file_put_contents($masterPath, $appendContent, LOCK_EX);
}
}
}
}