|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Uccello\Core\Http\Controllers\Core; |
|
4
|
|
|
|
|
5
|
|
|
use Spatie\Searchable\Search; |
|
|
|
|
|
|
6
|
|
|
use Uccello\Core\Models\Domain; |
|
7
|
|
|
use Uccello\Core\Models\Module; |
|
8
|
|
|
|
|
9
|
|
|
class SearchController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
protected $viewName = 'search.main'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @var \Uccello\Core\Models\Domain |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $domain; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Search records in all modules where user has retrieve capability. |
|
20
|
|
|
* |
|
21
|
|
|
* @param \Uccello\Core\Models\Domain |
|
22
|
|
|
* @return \Illuminate\Support\Collection |
|
23
|
|
|
*/ |
|
24
|
|
|
public function search(?Domain $domain) |
|
25
|
|
|
{ |
|
26
|
|
|
// Pre-process. We force module to be 'home' |
|
27
|
|
|
$this->preProcess($domain, ucmodule('home'), request()); |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
if (!request('q')) { |
|
30
|
|
|
return collect(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
$searchResults = $this->getSearchResults(); |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
return $this->autoView(compact('searchResults')); |
|
|
|
|
|
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Search records in all autorized modules |
|
41
|
|
|
* |
|
42
|
|
|
* @return \Illuminate\Support\Collection |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function getSearchResults() |
|
45
|
|
|
{ |
|
46
|
|
|
$searchResults = new Search(); |
|
47
|
|
|
|
|
48
|
|
|
// Get all modules in autorized modules |
|
49
|
|
|
$modules = $this->getAutorizedModules(); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($modules as $module) { |
|
52
|
|
|
$modelClass = $module->model_class; |
|
53
|
|
|
|
|
54
|
|
|
if (method_exists($modelClass, 'getSearchResult') && property_exists($modelClass, 'searchableColumns')) { |
|
55
|
|
|
$searchResults->registerModel($modelClass, (array) (new $modelClass)->searchableColumns); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$searchQuery = request('q'); |
|
60
|
|
|
|
|
61
|
|
|
return $searchResults |
|
62
|
|
|
->search($searchQuery) |
|
63
|
|
|
->take(config('uccello.max_results.search', 50)); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Retrieve all modules in witch the user can search. |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Illuminate\Support\Collection |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function getAutorizedModules() |
|
72
|
|
|
{ |
|
73
|
|
|
$autorizedModules = collect(); |
|
74
|
|
|
|
|
75
|
|
|
// Restrct on CRUD modules activated on the domain |
|
76
|
|
|
$query = $this->domain->modules()->whereNotNull('model_class'); |
|
77
|
|
|
|
|
78
|
|
|
// If we want to restrict the search in a module add the condition |
|
79
|
|
|
if (request('module')) { |
|
80
|
|
|
$query = $query->where('name', request('module')); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// Get all module |
|
84
|
|
|
$modules = $query->get(); |
|
85
|
|
|
|
|
86
|
|
|
foreach ($modules as $module) { |
|
87
|
|
|
if (auth()->user()->canRetrieve($this->domain, $module)) { |
|
88
|
|
|
$autorizedModules->push($module); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $autorizedModules; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths