Test Setup Failed
Push — master ( a9d37e...195d70 )
by Davide
01:16 queued 11s
created

SitemapController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Post;
6
use DavideCasiraghi\LaravelEventsCalendar\Models\Event;
7
use DavideCasiraghi\LaravelEventsCalendar\Models\Teacher;
8
use DavideCasiraghi\LaravelQuickMenus\Models\MenuItem;
9
use Illuminate\Support\Facades\DB;
10
11
/**
12
 *    Created using this tutorial: https://laravel-news.com/laravel-sitemap.
13
 **/
14
class SitemapController extends Controller
15
{
16
    /***************************************************************************/
17
18
    /**
19
     * Display a listing of the resource.
20
     *
21
     * @return \Illuminate\Http\Response
22
     */
23
    public function index()
24
    {
25
        /*$post = Post::orderBy('updated_at', 'desc')->first();
26
        $event = Event::orderBy('updated_at', 'desc')->first();
27
        $teacher = Teacher::orderBy('updated_at', 'desc')->first();*/
28
29
        $menuItems = MenuItem::where('access', 1)->get();
30
31
        return response()->view('sitemap.index', [
32
            'menuItems' => $menuItems,
33
        ])->header('Content-Type', 'text/xml');
34
    }
35
36
    /***************************************************************************/
37
38
    /**
39
     * Generate the posts XML sitemap.
40
     *
41
     * @return \Illuminate\Http\Response
42
     */
43
    public function posts()
44
    {
45
        //$posts = Post::where('category_id', 6)->get();
46
47
        $posts = DB::table('posts')
48
                       ->join('post_translations', 'posts.id', '=', 'post_translations.post_id')
49
                       ->select('posts.*', 'post_translations.locale', 'post_translations.slug')->get();
50
51
        //dd($posts);
52
        return response()->view('sitemap.posts', [
53
            'posts' => $posts,
54
        ])->header('Content-Type', 'text/xml');
55
    }
56
57
    /***************************************************************************/
58
59
    /**
60
     * Generate the events XML sitemap
61
     * every event show the link to the closest repetition related to today.
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function events()
66
    {
67
        // Retrieve all the active events
68
        $filters = [];
69
        $filters['keywords'] = $filters['category'] = $filters['country'] = $filters['region'] = $filters['city'] = $filters['continent'] = $filters['teacher'] = $filters['venue'] = $filters['startDate'] = $filters['endDate'] = null;
70
        $activeEvents = Event::getEvents($filters, 10000);
71
72
        return response()->view('sitemap.events', [
73
            'events' => $activeEvents,
74
        ])->header('Content-Type', 'text/xml');
75
    }
76
77
    /***************************************************************************/
78
79
    /**
80
     * Generate the teachers XML sitemap.
81
     *
82
     * @return \Illuminate\Http\Response
83
     */
84
    public function teachers()
85
    {
86
        $teachers = Teacher::orderBy('updated_at', 'desc')->get();
87
88
        return response()->view('sitemap.teachers', [
89
            'teachers' => $teachers,
90
        ])->header('Content-Type', 'text/xml');
91
    }
92
93
    /***************************************************************************/
94
95
    /**
96
     * Display the specified resource.
97
     *
98
     * @return \Illuminate\View\View
99
     */
100
    public function show()
101
    {
102
        $sitemap = $this->generateSitemapXML();
0 ignored issues
show
Bug introduced by
The method generateSitemapXML() does not exist on App\Http\Controllers\SitemapController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
        /** @scrutinizer ignore-call */ 
103
        $sitemap = $this->generateSitemapXML();
Loading history...
103
104
        return view('sitemap.show', ['sitemap' => $sitemap]);
105
    }
106
107
    /***************************************************************************/
108
}
109