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/SBogers95/rentman.io/app/Komma/Integrations/IntegrationService.php
<?php

namespace App\Komma\Integrations;

use App\Komma\Base\Service;
use Illuminate\Support\Collection;

class IntegrationService extends Service
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getAllIntegrations($pagination = false, $itemsPerPage = 9)
    {
        $integrations = $this->site
            ->integrations()
            ->with('translation', 'images', 'fallback_translation')
            ->where('lft', '!=', 1)
            ->orderBy('lft', 'asc')

            // We need to use a join to select the active integrations because that is defined on the translations
            ->join('integration_translations', 'integrations.id', '=', 'integration_translations.integration_id')
            ->select('integrations.*', 'integration_translations.active', 'integration_translations.populate_from_english', 'integration_translations.language_id')
            ->where(function ($query) {
                $query->where('active', '=', 1)
                    ->orWhere('populate_from_english', '=', 1);
            })
            ->where('language_id', \App::getLanguage()->id);

        if ($pagination) {
            $integrations = $integrations->paginate($itemsPerPage);

            // Skip the population if language is already english
            if (app()->getLocale() != 'en') {
                $this->populatedFallbackTranslationOnCollection($integrations->getCollection());
            }
        } else {
            $integrations = $integrations->get();

            // Skip the population if language is already english
            if (app()->getLocale() != 'en') {
                $this->populatedFallbackTranslationOnCollection($integrations);
            }
        }

        return $integrations;
    }

    private function populatedFallbackTranslationOnCollection(Collection $integrations)
    {
        foreach ($integrations as $integration) {
            // Skip if we don't need to populated
            if (! $integration->translation->populate_from_english) {
                continue;
            }
            $integration->translation = $integration->fallback_translation;
            $integration->used_fallback_translation = true;
        }
    }

    public function appendIntegrationsToLinks(&$links)
    {
        // If the products page isn't found, return
        if (! isset($links->integrations)) {
            return;
        }

        // Find all pages
        if (! $integrations = $this->site
            ->integrations()
            ->where('lft', '!=', 1)
            ->orderBy('lft', 'asc')
            ->has('translations')
            ->with('translations')
            ->get()
        ) {
            return;
        }

        // Skip the population if language is already english
        if (app()->getLocale() != 'en') {
            $this->populatedFallbackTranslationOnCollection($integrations);
        }
        $this->appendModelsToLinks($links, $integrations, 'integration', $links->integrations, true);
    }
}