finale 2.0.0
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Tag;
|
||||
use App\Models\Individuo;
|
||||
use App\Models\Gruppo;
|
||||
use App\Models\Evento;
|
||||
use App\Models\Documento;
|
||||
use App\Models\MailingList;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RicercaController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorizeRead('individui');
|
||||
|
||||
$allTags = Tag::orderBy('name')->get();
|
||||
|
||||
$tagSlugs = (array) $request->input('tag', []);
|
||||
|
||||
if (empty($tagSlugs)) {
|
||||
return view('ricerca.index', compact('allTags'));
|
||||
}
|
||||
|
||||
$tagSlugs = array_filter($tagSlugs);
|
||||
$selectedTags = Tag::whereIn('slug', $tagSlugs)->get();
|
||||
|
||||
$results = [];
|
||||
$totals = [];
|
||||
|
||||
if (count($tagSlugs) === 1) {
|
||||
$tag = $selectedTags->first();
|
||||
$results['individui'] = $tag->individui()->orderBy('cognome')->orderBy('nome')->get();
|
||||
$results['gruppi'] = $tag->gruppi()->orderBy('nome')->get();
|
||||
$results['eventi'] = $tag->eventi()->orderBy('data_specifica')->orderBy('nome_evento')->get();
|
||||
$results['documenti'] = $tag->documenti()->orderBy('nome_file')->get();
|
||||
$results['mailingLists'] = $tag->mailingLists()->orderBy('nome')->get();
|
||||
} else {
|
||||
$results['individui'] = Individuo::withAllTags($tagSlugs)->orderBy('cognome')->orderBy('nome')->get();
|
||||
$results['gruppi'] = Gruppo::withAllTags($tagSlugs)->orderBy('nome')->get();
|
||||
$results['eventi'] = Evento::withAllTags($tagSlugs)->orderBy('data_specifica')->orderBy('nome_evento')->get();
|
||||
$results['documenti'] = Documento::withAllTags($tagSlugs)->orderBy('nome_file')->get();
|
||||
$results['mailingLists'] = MailingList::withAllTags($tagSlugs)->orderBy('nome')->get();
|
||||
}
|
||||
|
||||
$totals = [
|
||||
'individui' => $results['individui']->count(),
|
||||
'gruppi' => $results['gruppi']->count(),
|
||||
'eventi' => $results['eventi']->count(),
|
||||
'documenti' => $results['documenti']->count(),
|
||||
'mailingLists' => $results['mailingLists']->count(),
|
||||
];
|
||||
|
||||
return view('ricerca.index', compact('selectedTags', 'tagSlugs', 'results', 'totals', 'allTags'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user