132 lines
4.6 KiB
PHP
132 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace Paymenter\Extensions\Others\Onboarding;
|
|
|
|
use App\Classes\Extension\Extension;
|
|
use App\Helpers\ExtensionHelper;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class Onboarding extends Extension
|
|
{
|
|
public function getMetadata()
|
|
{
|
|
return [
|
|
'display_name' => 'Onboarding',
|
|
'version' => '1.0.0',
|
|
'author' => 'Paymenter',
|
|
'website' => 'https://paymenter.org',
|
|
];
|
|
}
|
|
|
|
public function getConfig($values = [])
|
|
{
|
|
return [
|
|
[
|
|
'name' => 'test_mode',
|
|
'type' => 'checkbox',
|
|
'label' => 'Test Mode',
|
|
'description' => 'Enable test mode to always show onboarding modal (bypass session tracking). Useful for testing while setting up slides.',
|
|
'required' => false,
|
|
'default' => false,
|
|
],
|
|
[
|
|
'name' => 'show_backdrop',
|
|
'type' => 'checkbox',
|
|
'label' => 'Show Backdrop',
|
|
'description' => 'Display a dark backdrop behind the onboarding modal.',
|
|
'required' => false,
|
|
'default' => false,
|
|
],
|
|
[
|
|
'name' => 'per_session',
|
|
'type' => 'checkbox',
|
|
'label' => 'Per Session Onboarding',
|
|
'description' => 'Use cookies instead of database session. Onboarding will show again if user clears cookies or uses a different browser/device.',
|
|
'required' => false,
|
|
'default' => false,
|
|
],
|
|
[
|
|
'name' => 'include_homepage',
|
|
'type' => 'checkbox',
|
|
'label' => 'Show on Homepage',
|
|
'description' => 'Also display onboarding on the homepage. By default, onboarding only shows on internal pages like dashboard, services, etc.',
|
|
'required' => false,
|
|
'default' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
public function installed()
|
|
{
|
|
|
|
ExtensionHelper::runMigrations('extensions/Others/Onboarding/database/migrations');
|
|
}
|
|
|
|
public function uninstalled()
|
|
{
|
|
|
|
ExtensionHelper::rollbackMigrations('extensions/Others/Onboarding/database/migrations');
|
|
}
|
|
|
|
public function boot()
|
|
{
|
|
|
|
app('view')->addNamespace('onboarding', __DIR__ . '/resources/views');
|
|
|
|
|
|
\Livewire\Livewire::component('onboarding.modal', \Paymenter\Extensions\Others\Onboarding\Livewire\Onboarding\Modal::class);
|
|
|
|
|
|
\Illuminate\Support\Facades\Gate::policy(
|
|
\Paymenter\Extensions\Others\Onboarding\Models\OnboardingSlide::class,
|
|
\Paymenter\Extensions\Others\Onboarding\Policies\OnboardingSlidePolicy::class
|
|
);
|
|
|
|
|
|
\Illuminate\Support\Facades\Event::listen('permissions', function () {
|
|
return [
|
|
'admin.onboarding.view' => 'View Onboarding Slides',
|
|
'admin.onboarding.create' => 'Create Onboarding Slides',
|
|
'admin.onboarding.update' => 'Update Onboarding Slides',
|
|
'admin.onboarding.delete' => 'Delete Onboarding Slides',
|
|
];
|
|
});
|
|
|
|
\Illuminate\Support\Facades\Event::listen('body', function () {
|
|
// Skip if table doesn't exist
|
|
if (!Schema::hasTable('ext_onboarding_slides')) {
|
|
return null;
|
|
}
|
|
|
|
// Check if homepage should be included
|
|
$extension = ExtensionHelper::getExtension('other', 'Onboarding');
|
|
$includeHomepage = $extension->config('include_homepage', false);
|
|
|
|
// Skip admin and auth pages
|
|
if (request()->is('admin/*') ||
|
|
request()->is('login') ||
|
|
request()->is('register') ||
|
|
request()->is('2fa') ||
|
|
request()->is('forgot-password') ||
|
|
request()->is('reset-password/*') ||
|
|
request()->is('verify-email')) {
|
|
return null;
|
|
}
|
|
|
|
// Skip homepage unless explicitly included
|
|
if (!$includeHomepage && request()->is('/')) {
|
|
return null;
|
|
}
|
|
|
|
// Only show for authenticated users
|
|
if (!\Illuminate\Support\Facades\Auth::check()) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'view' => view('onboarding::widget'),
|
|
];
|
|
});
|
|
}
|
|
}
|