202 lines
5.5 KiB
PHP
202 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Crm\Providers;
|
|
|
|
use Illuminate\Database\Eloquent\Factory;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Illuminate\Support\Facades\View;
|
|
use App\Utils\ModuleUtil;
|
|
use App\Utils\Util;
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use Illuminate\Routing\Router;
|
|
|
|
class CrmServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* The filters base class name.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $middleware = [
|
|
'Crm' => [
|
|
'ContactSidebarMenu' => 'ContactSidebarMenu',
|
|
'CheckContactLogin' => 'CheckContactLogin'
|
|
],
|
|
];
|
|
|
|
/**
|
|
* Boot the application events.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$this->registerTranslations();
|
|
$this->registerConfig();
|
|
$this->registerViews();
|
|
$this->registerFactories();
|
|
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
|
|
$this->registerScheduleCommands();
|
|
|
|
$this->registerMiddleware($this->app['router']);
|
|
|
|
// Share a default module display name globally to avoid undefined variable notices
|
|
View::share('module_display_name', trans('crm::lang.crm'));
|
|
|
|
View::composer(
|
|
['crm::layouts.nav'],
|
|
function ($view) {
|
|
if (! auth()->check()) {
|
|
return;
|
|
}
|
|
$business_id = request()->session()->get('user.business_id', auth()->user()->business_id);
|
|
$commonUtil = new Util();
|
|
$is_admin = $commonUtil->is_admin(auth()->user(), $business_id);
|
|
$crmUtil = new \Modules\Crm\Utils\CrmUtil();
|
|
$crm_settings = \Modules\Crm\Utils\TelemarketingUtil::mergeSettings(
|
|
$crmUtil->getCrmSettings($business_id)
|
|
);
|
|
$view->with('__is_admin', $is_admin);
|
|
$view->with('__crm_settings', $crm_settings);
|
|
$view->with('__business_id', $business_id);
|
|
}
|
|
);
|
|
|
|
// Ensure admin flag is available in CRM layouts
|
|
}
|
|
|
|
/**
|
|
* Register the filters.
|
|
*
|
|
* @param Router $router
|
|
* @return void
|
|
*/
|
|
public function registerMiddleware(Router $router)
|
|
{
|
|
foreach ($this->middleware as $module => $middlewares) {
|
|
foreach ($middlewares as $name => $middleware) {
|
|
$class = "Modules\\{$module}\\Http\\Middleware\\{$middleware}";
|
|
|
|
$router->aliasMiddleware($name, $class);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register the service provider.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
$this->app->register(RouteServiceProvider::class);
|
|
$this->registerCommands();
|
|
}
|
|
|
|
/**
|
|
* Register config.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerConfig()
|
|
{
|
|
$this->publishes([
|
|
__DIR__ . '/../Config/config.php' => config_path('crm.php'),
|
|
], 'config');
|
|
$this->mergeConfigFrom(
|
|
__DIR__ . '/../Config/config.php',
|
|
'crm'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Register views.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function registerViews()
|
|
{
|
|
$viewPath = resource_path('views/modules/crm');
|
|
|
|
$sourcePath = __DIR__ . '/../Resources/views';
|
|
|
|
$this->publishes([
|
|
$sourcePath => $viewPath,
|
|
], 'views');
|
|
|
|
$this->loadViewsFrom(array_merge(array_map(function ($path) {
|
|
return $path . '/modules/crm';
|
|
}, config('view.paths')), [$sourcePath]), 'crm');
|
|
}
|
|
|
|
/**
|
|
* Register translations.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function registerTranslations()
|
|
{
|
|
$langPath = resource_path('lang/modules/crm');
|
|
|
|
if (is_dir($langPath)) {
|
|
$this->loadTranslationsFrom($langPath, 'crm');
|
|
} else {
|
|
$this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'crm');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register an additional directory of factories.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function registerFactories()
|
|
{
|
|
if (!app()->environment('production') && $this->app->runningInConsole()) {
|
|
app(Factory::class)->load(__DIR__ . '/../Database/factories');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the services provided by the provider.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function provides()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Register commands.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function registerCommands()
|
|
{
|
|
$this->commands([
|
|
\Modules\Crm\Console\SendScheduleNotification::class,
|
|
\Modules\Crm\Console\CreateRecursiveFollowup::class,
|
|
\Modules\Crm\Console\SendPhoneListReminder::class,
|
|
\Modules\Crm\Console\ExpireCallQueueLocks::class,
|
|
]);
|
|
}
|
|
|
|
public function registerScheduleCommands()
|
|
{
|
|
$env = config('app.env');
|
|
$module_util = new ModuleUtil();
|
|
$is_installed = $module_util->isModuleInstalled(config('crm.name'));
|
|
|
|
if ($env === 'live' && $is_installed) {
|
|
$this->app->booted(function () {
|
|
$schedule = $this->app->make(Schedule::class);
|
|
$schedule->command('pos:sendScheduleNotification')->everyMinute();
|
|
$schedule->command('pos:createRecursiveFollowup')->daily();
|
|
$schedule->command('pos:sendPhoneListReminder')->dailyAt('09:00');
|
|
$schedule->command('pos:expireCallQueueLocks')->everyFiveMinutes();
|
|
});
|
|
}
|
|
}
|
|
}
|