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/OneSky/OneSkyExporterService.php
<?php

namespace App\Komma\OneSky;

use App\Komma\Base\Service;
use App\Komma\Components\ComponentService;
use Illuminate\Database\Eloquent\Model;

class OneSkyExporterService extends Service
{
    /*
     * Export language id
     */
    private $exportLanguageId = 40;

    public function generateModelJson(Model $model, array $translatableAttributes)
    {
        $json = [];

        foreach ($translatableAttributes as $translatableAttribute) {
            if (empty($model->translation->{$translatableAttribute})) {
                continue;
            }
            $json[$translatableAttribute] = $model->translation->{$translatableAttribute};
        }

        return $json;
    }

    public function generateComponentJson($translation)
    {
        $componentService = \App::make(ComponentService::class);
        $components = $componentService->getViewComponents($translation);

        // Return empty array if there are no components
        if ($components->count() == 0) {
            return [];
        }

        $componentsJson = [];

        foreach ($components as $component) {
            if (! $translatableAttributes = $componentService->getTranslatableAttributes($component->type_id)) {
                continue;
            }

            $json = [];

            foreach ($translatableAttributes as $translatableAttribute) {
                if (empty($component->{$translatableAttribute})) {
                    continue;
                }
                $json[$translatableAttribute] = $component->{$translatableAttribute};
            }

            if (count($json) == 0) {
                continue;
            }

            $componentsJson[$component->type.'_'.$component->id] = $json;
        }

        return $componentsJson;
    }
}