Sfoglia il codice sorgente

archivio calendari

FabioFratini 1 anno fa
parent
commit
7cd8a5c98c

+ 6 - 1
app/Season.php

@@ -12,4 +12,9 @@ class Season extends Model
         'default'
     ];
 
-}
+    public function calendars()
+    {
+        return $this->hasMany(Calendar::class);
+    }
+
+}

+ 234 - 0
resources/views/calendar_archive.blade.php

@@ -0,0 +1,234 @@
+@extends('layouts.frontend')
+
+@section('content')
+<div class="container" style="min-height: 450px;">
+    <div class="row archivio-news">
+        <br>
+        <div class="title-section col-sm-12">
+            <h1 style="width: 90%"><span>Archivio Calendari</span></h1>
+        </div>
+
+        <div class="col-sm-12">
+            <form id="archiveFilterForm">
+                <div class="row">
+                    <div class="col-md-12">
+                        <div class="form-group">
+                            <label for="season">Stagione:</label>
+                            <select id="season" name="season_id" class="form-control">
+                                <option value="">Seleziona Stagione</option>
+                                @foreach($seasons as $season)
+                                    <option value="{{ $season->id }}">{{ $season->name }}</option>
+                                @endforeach
+                            </select>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="row mt-3" id="typeSection" style="display: none;">
+                    <div class="col-md-12">
+                        <div class="form-group">
+                            <label for="type">Tipo:</label>
+                            <select id="type" name="type" class="form-control">
+                                <option value="">Seleziona Tipo</option>
+                                @foreach($categories->pluck('type')->unique() as $type)
+                                    <option value="{{ $type }}">
+                                        @if($type == 'nation')
+                                            NAZIONALE
+                                        @elseif($type == 'region')
+                                            REGIONALE
+                                        @else
+                                            {{ strtoupper($type) }}
+                                        @endif
+                                    </option>
+                                @endforeach
+                            </select>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="row mt-3" id="categorySection" style="display: none;">
+                    <div class="col-md-12">
+                        <div class="form-group">
+                            <label for="category">Categoria:</label>
+                            <select id="category" name="category_id" class="form-control">
+                                <option value="">Seleziona Categoria</option>
+                            </select>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="row mt-3" id="groupSection" style="display: none;">
+                    <div class="col-md-12">
+                        <div class="form-group">
+                            <label for="group">Gruppo:</label>
+                            <select id="group" name="group_id" class="form-control">
+                                <option value="">Seleziona Gruppo</option>
+                            </select>
+                        </div>
+                    </div>
+                </div>
+
+                <div class="row mt-4" id="resultSection" style="display: none;">
+                    <div class="col-md-12 text-center">
+                        <div id="searchButtonSection">
+                            <button type="button" id="searchButton" class="btn btn-primary">
+                                Vai al Calendario
+                            </button>
+                        </div>
+                        <div id="noResultsSection" style="display: none;">
+                            <p class="text-danger">Nessun calendario in archivio per i dati inseriti</p>
+                        </div>
+                    </div>
+                </div>
+            </form>
+        </div>
+    </div>
+</div>
+
+@stop
+@section('extra_js')
+<script>
+$(document).ready(function() {
+    const categories = @json($categories);
+    const groups = @json($groups);
+    const archivedCalendars = @json($archivedCalendars);
+
+    function findCalendarsForSeason(seasonId) {
+        return archivedCalendars.filter(cal => cal.season_id === parseInt(seasonId));
+    }
+
+    function findCalendarsForType(seasonId, type) {
+        return archivedCalendars.filter(cal =>
+            cal.season_id === parseInt(seasonId) &&
+            cal.category?.type === type
+        );
+    }
+
+    function findCalendarsForCategory(seasonId, categoryId) {
+        return archivedCalendars.filter(cal =>
+            cal.season_id === parseInt(seasonId) &&
+            cal.category_id === parseInt(categoryId)
+        );
+    }
+
+    $('#season').on('change', function() {
+        const seasonId = $(this).val();
+        if (seasonId) {
+            const seasonCalendars = findCalendarsForSeason(seasonId);
+            if (seasonCalendars.length > 0) {
+                $('#typeSection').show();
+                $('#resultSection, #noResultsSection').hide();
+            } else {
+                $('#typeSection, #categorySection, #groupSection').hide();
+                $('#resultSection').show();
+                $('#searchButtonSection').hide();
+                $('#noResultsSection').show();
+            }
+        } else {
+            $('#typeSection, #categorySection, #groupSection, #resultSection').hide();
+            $('#type, #category, #group').val('');
+        }
+    });
+
+    $('#type').on('change', function() {
+        const selectedType = $(this).val();
+        const seasonId = $('#season').val();
+
+        if (selectedType && seasonId) {
+            const typeCalendars = findCalendarsForType(seasonId, selectedType);
+
+            if (typeCalendars.length > 0) {
+                const filteredCategories = categories.filter(cat =>
+                    cat.type === selectedType &&
+                    typeCalendars.some(cal => cal.category_id === cat.id)
+                );
+
+                const categorySelect = $('#category');
+                categorySelect.empty().append('<option value="">Seleziona Categoria</option>');
+                filteredCategories.forEach(category => {
+                    categorySelect.append(`<option value="${category.id}">${category.name}</option>`);
+                });
+
+                $('#categorySection').show();
+                $('#groupSection').hide();
+                $('#group').val('');
+                $('#resultSection, #noResultsSection').hide();
+            } else {
+                $('#categorySection, #groupSection').hide();
+                $('#resultSection').show();
+                $('#searchButtonSection').hide();
+                $('#noResultsSection').show();
+            }
+        } else {
+            $('#categorySection, #groupSection, #resultSection').hide();
+            $('#category, #group').val('');
+        }
+    });
+
+    $('#category').on('change', function() {
+        const selectedCategoryId = $(this).val();
+        const seasonId = $('#season').val();
+
+        if (selectedCategoryId && seasonId) {
+            const categoryCalendars = findCalendarsForCategory(seasonId, selectedCategoryId);
+
+            if (categoryCalendars.length > 0) {
+                const filteredGroups = groups.filter(group =>
+                    group.category_id === parseInt(selectedCategoryId) &&
+                    categoryCalendars.some(cal => cal.group_id === group.id)
+                );
+
+                if (filteredGroups.length > 0) {
+                    const groupSelect = $('#group');
+                    groupSelect.empty().append('<option value="">Seleziona Gruppo</option>');
+                    filteredGroups.forEach(group => {
+                        groupSelect.append(`<option value="${group.id}">${group.name}</option>`);
+                    });
+                    $('#groupSection').show();
+                } else {
+                    $('#searchButtonSection').show();
+                    $('#noResultsSection').hide();
+                }
+                $('#resultSection').show();
+            } else {
+                $('#groupSection').hide();
+                $('#resultSection').show();
+                $('#searchButtonSection').hide();
+                $('#noResultsSection').show();
+            }
+        } else {
+            $('#groupSection, #searchButtonSection').hide();
+            $('#group').val('');
+        }
+    });
+
+    $('#group').on('change', function() {
+        const groupId = $(this).val();
+        if (groupId) {
+            $('#searchButtonSection').show();
+            $('#noResultsSection').hide();
+        }
+    });
+
+    $('#searchButton').on('click', function() {
+        const seasonId = $('#season').val();
+        const categoryId = $('#category').val();
+        const groupId = $('#group').val();
+
+        const selectedCategory = categories.find(c => c.id === parseInt(categoryId));
+        if (selectedCategory) {
+            const selectedGroup = groupId ? groups.find(g => g.id === parseInt(groupId)) : null;
+
+            let urlName = selectedCategory.name;
+            if (selectedGroup) {
+                urlName += `-${selectedGroup.name}`;
+            }
+
+            const calendarId = groupId || categoryId;
+            const url = `/calendario/${urlName}/${calendarId}`;
+            window.location.href = url;
+        }
+    });
+});
+</script>
+@stop

+ 4 - 4
resources/views/event.blade.php

@@ -13,12 +13,12 @@
         <div class="row">
             <div class="col-sm-8">
                 @if($event->image != '')
-                        <div class="row">
-                            <img src="/files/news/{{$event->image}}" align="left" style="margin-left: 15px;">
+                        <div class="row" style="margin-right: 15px;">
+                            <img src="/files/news/{{$event->image}}" align="left" style="margin-left: 15px; max-width:60%" class= "img-responsive">
+                            <h1 style="font-size:30px; margin-left:15px;" class="red">{{$event->title}}</h1>
+                            <p>{!!$event->text!!}</p>
                         </div>
                 @endif
-                <h1 class="red">{{$event->title}}</h1>
-                <p>{!!$event->text!!}</p>
 
                 <div class="block-content">
                     <div class="row" style="margin-top: 2em;">

+ 1 - 1
resources/views/news.blade.php

@@ -34,7 +34,7 @@
 @section('content')
 <style>
         .single-news p{
-            margin-left:15px;
+            margin-left:15px!important
         }
 </style>
 

+ 1 - 1
resources/views/page.blade.php

@@ -26,7 +26,7 @@
 @section('content')
 <style>
     .single-page p{
-        margin-left:15px;
+        margin-left:15px!important;
     }
 </style>
 

+ 142 - 1
routes/web.php

@@ -1,6 +1,12 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\URL;
+use Illuminate\Support\Facades\App;
+use Illuminate\Support\Str;
+use Illuminate\Support\Facades\Redirect;
+use Illuminate\Http\Request;
 use App\News;
 use App\BreakingNews;
 use App\Section;
@@ -685,7 +691,142 @@ Route::get('/eventi', function(){
     }
     $videos = array();
 
-    return view('events', compact('news', 'home', 'sections', 'sections_menu', 'regions', 'pages', 'breaking_news', 'videos', 'events', 'calendars', 'aHome'));
+    return view('events', compact('news', 'home', 'sections', 'sections_menu', 'regions', 'pages', 'breaking_news', 'videos', 'events', 'calendari', 'aHome'));
+});
+
+Route::get('/archivio', function() {
+    $news = News::where('id', -1)->get();
+    $home = Home::first();
+
+    if ($home != null) {
+        $home->loadData();
+    }
+
+    $aHome = array();
+    if ($home->image != '')
+    {
+        $aHome[] = ['image' => $home->image, 'url' => $home->url];
+    }
+    if ($home->image_2 != '')
+    {
+        $aHome[] = ['image' => $home->image_2, 'url' => $home->url_2];
+    }
+    if ($home->image_3 != '')
+    {
+        $aHome[] = ['image' => $home->image_3, 'url' => $home->url_3];
+    }
+    if ($home->image_4 != '')
+    {
+        $aHome[] = ['image' => $home->image_4, 'url' => $home->url_4];
+    }
+    if ($home->image_5 != '')
+    {
+        $aHome[] = ['image' => $home->image_5, 'url' => $home->url_5];
+    }
+    if (sizeof($aHome) > 0)
+    {
+        $rnd = rand (0, sizeof($aHome) - 1);
+        $home->image = $aHome[$rnd]["image"];
+        $home->url = $aHome[$rnd]["url"];
+    }
+    $sections_menu = Section::where('type', '=', 'section')->orderBy('position')->get();
+    $pages = Page::where('online', '=', true)->orderBy('title')->get();
+    $breaking_news = BreakingNews::where('online', '=', true)->orderBy('date', "DESC")->get();
+    $season_id = @Season::where('default', '=', true)->first()->id;
+    $cals = Calendar::where('season_id', '=', $season_id)->orderBy('position')->get();
+    $archivedCalendars = Calendar::where('archived', true)
+    ->with(['category', 'group']) // Eager load relationships
+    ->get();
+    $calendars = array();
+    foreach($cals as $c)
+    {
+
+        if ($c->category->grp != '')
+        {
+            $type = $c->type == 'nation' ? 'Nazionale' : 'Regionale';
+            if ($c->group_id > 0)
+                $calendars[$type][$c->category->grp][$c->category->name . " - " . $c->group->name] = $c->id;
+            else
+                $calendars[$type][$c->category->grp][$c->category->name] = $c->id;
+        }
+
+    }
+
+    $seasons = Season::orderBy('name')->get();
+    $sections = Section::where('type', '=', 'section')
+        ->orderBy('position')
+        ->get();
+    $regions = Section::where('type', '=', 'region')
+        ->orderBy('name')
+        ->get();
+    $categories = Category::orderBy('name')->get();
+    $groups = Group::orderBy('name')->get();
+
+    $seasonsForJs = $seasons->map(function($season) {
+        return [
+            'id' => $season->id,
+            'name' => $season->name
+        ];
+    });
+
+    return view('calendar_archive', compact(
+        'news',
+        'home',
+        'sections',
+        'sections_menu',
+        'regions',
+        'pages',
+        'breaking_news',
+        'seasons',
+        'seasonsForJs',
+        'categories',
+        'groups',
+        'archivedCalendars',
+        'aHome',
+        'calendars'
+    ));
+
+});
+
+Route::get('/api/archive/calendars/search', function(Request $request) {
+    $query = Calendar::with(['season', 'category', 'group']) // Eager load relationships
+        ->where('archived', true);
+
+    if ($request->season_id) {
+        $query->where('season_id', $request->season_id);
+    }
+
+    if ($request->type) {
+        $query->whereHas('category', function($q) use ($request) {
+            $q->where('type', $request->type);
+        });
+    }
+
+    if ($request->category_id) {
+        $query->where('category_id', $request->category_id);
+    }
+
+    if ($request->group_id) {
+        $query->where('group_id', $request->group_id);
+    }
+
+    $calendars = $query->orderBy('position')->get()
+        ->map(function($calendar) {
+            return [
+                'id' => $calendar->id,
+                'name' => $calendar->name,
+                'season' => $calendar->season ? $calendar->season->name : '',
+                'category' => $calendar->category ? $calendar->category->name : '',
+                'group' => $calendar->group ? $calendar->group->name : '',
+                'type' => $calendar->category ? $calendar->category->type : '',
+                'position' => $calendar->position
+            ];
+        });
+
+    return response()->json([
+        'success' => true,
+        'data' => $calendars
+    ]);
 });
 
 Route::get('/video/{id}', function ($id) {