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/ijzerenman.komma.pro/app/Custom/Routes/RouteService.php
<?php

/**
 * Short description for the file.
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace Komma\Routes;

use Komma\Routes\Routes;
use Komma\Language;

class RouteService
{
    public function getSitemapRoutes($groups = ['pages'], $weight_from = 0.1)
    {


        $routes = \DB::table('routes')
            ->select('routes.*',
                'page_translations.page_id as page_id', 'page_translations.name as page_name',
                'news_item_translations.news_item_id as news_id', 'news_item_translations.name as news_name'
            )
            //Join to the coupling id
            //Pages
            ->leftJoin('page_translations', 'page_translations.id', '=', 'routes.routable_id')
            ->where(function ($query) {
                $query->where('routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation')
                    ->orWhereNull('page_translations.id');
            })
            //news items
            ->leftJoin('news_item_translations', 'news_item_translations.id', '=', 'routes.routable_id')
            ->where(function ($query) {
                $query->where('routable_type', '=', 'Komma\Kms\News\Models\NewsItemTranslation')
                    ->orWhereNull('news_item_translations.id');
            })
            ->where('sitemap_weight', '>=', $weight_from)
            ->orderBy('route', 'asc')
            ->groupBy('route')
            ->get();


        $cleaned_routes = [];
        foreach ($routes as $route) {
            if (in_array('pages', $groups ) && $route->routable_type == 'Komma\Kms\Pages\Models\PageTranslation') {
                $cleaned_routes['page-'.$route->page_id] = [
                    'route' => $route->route,
                    'weight' => $route->sitemap_weight,
                    'name' => $route->page_name
                ];

            }
            if (in_array('news', $groups ) && $route->routable_type == 'Komma\Kms\News\Models\NewsItemTranslation') {
                $cleaned_routes['news-'.$route->news_id] = [
                    'route' => $route->route,
                    'weight' => $route->sitemap_weight,
                    'name' => $route->news_name
                ];
            }
        }
        return $cleaned_routes;

    }
}