]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/SitemapXmlController.php
respond to whispers
[alttp.git] / app / Http / Controllers / SitemapXmlController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Models\Episode;
6 use App\Models\Event;
7 use App\Models\SitemapUrl;
8 use App\Models\Technique;
9 use App\Models\TechniqueMap;
10 use App\Models\Tournament;
11 use Illuminate\Http\Request;
12
13 class SitemapXmlController extends Controller
14 {
15
16         public function index() {
17                 $urls = [];
18
19                 foreach (Tournament::all() as $tournament) {
20                         $url = new SitemapUrl();
21                         $url->path = '/tournaments/'.$tournament->id;
22                         $url->lastmod = $tournament->updated_at ? $tournament->updated_at : ($tournament->created_at ? $tournament->created_at : now());
23                         $url->changefreq = $tournament->locked ? 'never' : 'daily';
24                         $url->priority = $tournament->locked ? 0.5 : 1.0;
25                         $urls[] = $url;
26                 }
27
28                 foreach (['lw', 'dw', 'sp', 'uw', 'uw2'] as $map) {
29                         $tech = TechniqueMap::where('map', '=', $map)->latest()->first();
30                         $url = new SitemapUrl();
31                         $url->path = '/map/'.$map;
32                         if ($tech) {
33                                 $url->lastmod = $tech->created_at;
34                         }
35                         $url->changefreq = 'monthly';
36                         $url->priority = 0.9;
37                         $urls[] = $url;
38                 }
39
40                 $url = new SitemapUrl();
41                 $url->path = '/tech';
42                 $url->lastmod = Technique::where('type', '=', 'tech')->where('index', true)->latest()->first()->created_at;
43                 $url->changefreq = 'monthly';
44                 $url->priority = 0.8;
45                 $urls[] = $url;
46
47                 foreach (Technique::where('type', '=', 'tech')->where('index', true)->get() as $tech) {
48                         $url = new SitemapUrl();
49                         $url->path = '/tech/'.rawurlencode($tech->name);
50                         $url->lastmod = $tech->updated_at ? $tech->updated_at : ($tech->created_at ? $tech->created_at : now());
51                         $url->changefreq = 'never';
52                         $url->priority = $tech->priority;
53                         $urls[] = $url;
54                 }
55
56                 $url = new SitemapUrl();
57                 $url->path = '/schedule';
58                 $url->lastmod = Episode::where('confirmed', true)->latest()->first()->created_at;
59                 $url->changefreq = 'daily';
60                 $url->priority = 1;
61                 $urls[] = $url;
62
63                 $url = new SitemapUrl();
64                 $url->path = '/events';
65                 $url->lastmod = Event::where('visible', true)->latest()->first()->created_at;
66                 $url->changefreq = 'monthly';
67                 $url->priority = 0.8;
68                 $urls[] = $url;
69
70                 foreach (Event::where('visible', true)->get() as $event) {
71                         $url = new SitemapUrl();
72                         $url->path = '/events/'.rawurlencode($event->name);
73                         $url->lastmod = $event->updated_at ? $event->updated_at : ($event->created_at ? $event->created_at : now());
74                         $url->changefreq = 'never';
75                         $url->priority = 0.4;
76                         $urls[] = $url;
77                 }
78
79                 return response()->view('sitemap', [
80                         'urls' => $urls,
81                 ])->header('Content-Type', 'text/xml');
82         }
83
84 }