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/douven.komma.pro/app/Http/Controllers/Controller.php
<?php

namespace App\Http\Controllers;

use App\KommaApp\Images\ImageService;
use App\KommaApp\Languages\LanguageService;
use App\KommaApp\Pages\PageService;
use App\KommaApp\Shop\Categories\Kms\CategoryService;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

abstract class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    protected $languageService;
    protected $pageService;
    protected $categoryService;
    protected $links;
    protected $categoryTree;

    protected $baseViewPath = 'site.';

    public function __construct()
    {
        $this->languageService = new LanguageService();
        $this->pageService = new PageService();
        $this->categoryService = new CategoryService();
        $this->links = $this->pageService->getAllTranslatedPageRoutes();
        $this->categoryTree = $this->categoryService->getModelTree(\App::getSite()->id)->getTree();
    }

    /*
     * This function should only be temporary until dynamic blocks is rewrite to it's own blocks
     * instead of using json
     */
    protected function decodeDynamicContent($translation)
    {
        $decodedJson = json_decode($translation->description);

        $dynamicBlocks = [];
        $dynamicGroups = [];

        $imageController = new ImageService();

        foreach ($decodedJson as $dynamicElement){

            if(isset($dynamicElement->fileIds)) {
                $images = $imageController->getDynamicBlockImages( $dynamicElement->fileIds );
                $dynamicElement->images = $images;
            }

            // Order dynamic blocks
            if($dynamicElement->code_name != '' ){ // If dynamic block has code name then add it to the translation
                $translation->{$dynamicElement->code_name} = $dynamicElement;
            } elseif($dynamicElement->view != ''){ // If dynamic block has view then add it to dynamic groups
                if( !isset($dynamicGroups[$dynamicElement->view])) $dynamicGroups[$dynamicElement->view] = [];
                $dynamicGroups[$dynamicElement->view][] = $dynamicElement;
            } else{ // Else just add them to the default dynamic content
                $dynamicBlocks[] = $dynamicElement;
            }
        }

        $translation->groups = $dynamicGroups;
        $translation->description = $dynamicBlocks;

        return $translation;
    }
}