HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/zuiderbos.komma.pro/app/Komma/Sitemap/SitemapService.php
<?php

namespace Komma\Sitemap;

use Carbon\Carbon;
use Komma\Pages\Models\Page;
use Komma\PhotoAlbums\Models\PhotoAlbum;
use Komma\Posts\Models\Post;
use Roumen\Sitemap\Sitemap;

class SitemapService
{
    /***
     * This method will generate the sitemap based on the routes table
     * It will collect the routes based on the given groups array.
     * Then it will build the sitemap grouped by the linked id
     *
     * @param array $groups , which routes we want in the sitemap
     * @param float $weight_from / the minimum weight of the sitemap items
     * @return Sitemap object
     */

    public function getSitemap($asXML = false)
    {
        if (! $asXML) {
            return $this->getActiveRoutesOneLanguage();
        }

        //Create the sitemap class
        $sitemap = new Sitemap([]);

        //Loop trough the routes based on the given parameters
        foreach ($this->getActiveRoutesMultiLanguage() as $route) {
            $sitemap->add(
                \URL::to($route['loc']),
                Carbon::now(),
                0.5,
                'monthly',
                [],
                null,
                $route['translation']
            );
        }

        return $sitemap;
    }

    public function getActiveRoutesOneLanguage()
    {
        $urls = [];
        $urls['pages'] = Page::with('translation')
            ->with('translation.route')
            ->where('pages.active', '=', 1)
            ->where('pages.lft', '!=', 1)
            ->orderBy('lft')
            ->get();

        $sitemap = [];
        //dde($urls);
        foreach ($urls as $key => $type) {
            foreach ($type as $link) {
                //check if translation isset else page not available in this language
                if (! $link->translation) {
                    continue;
                }

                //if blog or projects prepend text for visibility
                if ($key == 'blog') {
                    $name = trans('translations.sitemapPosts').': '.$link->translation->name;
                } elseif ($key == 'projects') {
                    $name = trans('translations.sitemapProjects').': '.$link->translation->name;
                } else {
                    $name = $link->translation->name;
                }

                $sitemap[] = [
                    'type'  => $key,
                    'name'  => $name,
                    'route' => $link->translation->route->route,
                ];
            }
        }

        return $sitemap;
    }

    public function getActiveRoutesMultiLanguage()
    {
        $urls = [];
        $urls['pages'] = Page::with('allTranslations')
            ->with('allTranslations.route')
            ->where('pages.active', '=', 1)
            ->where('pages.lft', '!=', 1)
            ->orderBy('lft')
            ->get();
//        $urls['photo_albums'] = PhotoAlbum::with('allTranslations')
//            ->with('allTranslations.route')
//            ->where('photo_albums.active', '=', 1)
//            ->where('photo_albums.lft', '!=', 1)
//            ->orderBy('lft')
//            ->get();
//        $urls['news'] = Post::with('allTranslations')
//            ->with('allTranslations.route')
//            ->where('active', '=', 1)
//            ->where('date', '<=', Carbon::now()->addHour())
//            ->orderBy('date', 'desc')
//            ->get();

        $sitemap = [];

        foreach ($urls as $key => $type) {
            foreach ($type as $link) {
                if (! isset($link->allTranslations)) {
                    continue;
                }

                $allTranslation = [];

                foreach ($link->allTranslations as $translation) {
                    $allTranslation[] = [
                        'url'     => \URL::to($translation->route->route),
                        'language' => $translation->iso_2,
                    ];
                }

                foreach ($link->allTranslations as $translation) {
                    $sitemap[] = [
                        'loc' => $translation->route->route,
                        'translation' => $allTranslation,
                    ];
                }
            }
        }

        return $sitemap;
    }
}