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/rentman2019.komma.pro/app/Komma/Base/Service.php
<?php

namespace App\Komma\Base;

use App\Komma\Pages\Models\Page;
use App\Komma\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;
use Illuminate\Support\Str;

abstract class Service
{
    /** @var SiteServiceInterface */
    private $siteService;

    /** @var Site */
    protected $site;

    public function __construct()
    {
        if (\App::runningInConsole()) {
            return;
        }
        $this->siteService = \App::make(SiteServiceInterface::class);
        $this->site = $this->siteService->getCurrentSite();
    }

    /**
     * Append the models belonging to the index page of $modelIndexPage
     * Models are grouped by product or solution group models
     *
     * @param $links
     * @param $models
     * @param string $prefix
     * @param object $parentModel
     * @param bool $withFallbackTranslation
     */
    protected function appendModelsToLinks(&$links, $models, string $prefix, object $parentModel, bool $withFallbackTranslation = false)
    {
        $subNav = [];

        // To save an additional request,
        // we manually append the (current language) translation to the model
        // and remove the inactive / not working pages.
        foreach ($models as $model) {
            if ($withFallbackTranslation && app()->getLocale() != 'en' && isset($model->translation) && $model->translation->language_id == 40) {
                $links->{$prefix.'_'.$model->id} = (object) [
                    'name' => $model->translation->name,
                    'route' => $parentModel->node->translation->route->alias.'/'.$model->translation->slug,
                    'node' => $model,
                ];

                continue;
            }

            // Through the query builder we know it has translations
            foreach ($model->translations as $translationCollectionKey => $translation) {
                // Check that a translation is active and has a slug
                if (! $translation->active || empty($translation->slug)) {
                    // Remove translation from collection
                    $model->translations->forget($translationCollectionKey);
                    continue;
                }

                // When it matches the app language (id) append it as it's translation
                if (\App::getLanguage()->id == $translation->language_id) {
                    $model->translation = $translation;
                }
            }

            // Only append page to links if it has a translation
            if (empty($model->translation) || ! $model->translation->active) {
                continue;
            }
            $modelRoute = (object) [
                'name' => $model->translation->name,
                'route' => $parentModel->node->translation->route->alias.'/'.$model->translation->slug,
                'node' => $model,
            ];

            $links->{$prefix.'_'.$model->id} = $modelRoute;
            $subNav[] = $modelRoute;
        }

        $links->subnav->{Str::plural($prefix)} = collect($subNav);
    }

    /**
     * Append the models belonging to the index page of $modelIndexPage
     * Models are grouped by product or solution group models
     *
     * @param $links
     */
    protected function appendModelsToLinksForModelIndexPage(&$links, $collection, Page $modelIndexPage, bool $withFallbackTranslation = false)
    {
        // Create empty object
        $subnav = [];

        foreach ($collection as $groupKey => $models) {
            $groupCollection = collect();

            // To save an additional request,
            // we manually append the (current language) translation to the model
            // and remove the inactive / not working pages.
            foreach ($models as $key => $model) {
                if ($withFallbackTranslation && app()->getLocale() != 'en' && isset($model->translation) && $model->translation->language_id == 40) {
                    $groupCollection->push((object) [
                        'name' => $model->translation->name,
                        'route' => $model->translation->slug,
                        'node' => $model,
                    ]);
                    continue;
                }

                // Through the query builder we know it has translations
                foreach ($model->translations as $translationCollectionKey => $translation) {
                    // Check that a translation is active and has a slug
                    if (! $translation->active || empty($translation->slug)) {
                        // Remove translation from collection
                        $model->translations->forget($translationCollectionKey);
                        continue;
                    }

                    // When it matches the app language (id) append it as it's translation
                    if (\App::getLanguage()->id == $translation->language_id) {
                        $model->translation = $translation;
                    }
                }

                // Only append page to links if it has a translation
                if (empty($model->translation) || ! $model->translation->active) {
                    continue;
                }

                $groupCollection->push((object) [
                    'name' => $model->translation->name,
                    'route' => $model->translation->slug,
                    'node' => $model,
                ]);
            }

            // Only append the group if it has an item in it
            if ($groupCollection->count() != 0) {
                $subnav[$modelIndexPage->code_name.'_group_'.$groupKey] = $groupCollection;
            }
        }

        $links->subnav->{$modelIndexPage->code_name} = collect($subnav);
    }
}