akaunting/app/Http/ViewComposers/Suggestions.php

56 lines
1.3 KiB
PHP
Raw Normal View History

2018-05-25 16:57:58 +03:00
<?php
namespace App\Http\ViewComposers;
use Illuminate\View\View;
use App\Traits\Modules as RemoteModules;
2018-05-25 16:57:58 +03:00
use Route;
2018-05-25 17:45:41 +03:00
use App\Models\Module\Module;
2018-05-25 16:57:58 +03:00
class Suggestions
{
use RemoteModules;
2018-05-25 16:57:58 +03:00
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
// No need to add suggestions in console
2018-06-25 17:59:27 +03:00
if (app()->runningInConsole() || !env('APP_INSTALLED')) {
return;
}
$modules = false;
2018-05-25 16:57:58 +03:00
$path = Route::current()->uri();
if ($path) {
$suggestions = $this->getSuggestions($path);
if ($suggestions) {
$suggestion_modules = $suggestions->modules;
foreach ($suggestion_modules as $key => $module) {
2018-05-25 17:45:41 +03:00
$installed = Module::where('company_id', '=', session('company_id'))->where('alias', '=', $module->alias)->first();
if ($installed) {
2018-05-25 16:57:58 +03:00
unset($suggestion_modules[$key]);
}
}
if ($suggestion_modules) {
shuffle($suggestion_modules);
$modules[] = $suggestion_modules[0];
2018-05-25 16:57:58 +03:00
}
}
}
$view->with(['suggestion_modules' => $modules]);
2018-05-25 16:57:58 +03:00
}
}