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/topswtwmobile.komma.pro/app/KommaApp/Blocks/BlockService.php
<?php

namespace KommaApp\Blocks;

use KommaApp\Blocks\Models\Block;
use KommaApp\Blocks\Models\BlockTranslation;

/**
 * Short description for the file.
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */
class BlockService
{
    public function getBlocksIn($field, $values, $trans = true)
    {
        $blocks = Block::where('active', '=', 1)
            ->whereIn($field, $values)
            ->with('translations')
            ->get()
            ->keyBy($field);

        if (!$trans) return $blocks;

        foreach ($blocks as $key => $block) {
            $blocks[$key] = $this->prepareBlockTranslation($block);
        }

        return $blocks;
    }

    public function getBlocksByCodeName($code_names)
    {
        return $this->getBlocksIn('code_name', $code_names);
    }

    private function prepareBlockTranslation($block)
    {
        $trans = $block->translations->keyBy('language_id');
        if(!isset($trans[\Shop::getLanguageService()->getCurrentLanguageId()])) return;
        $trans = $trans[\Shop::getLanguageService()->getCurrentLanguageId()];

        foreach ($trans->getAttributes() as $key => $value) {
            $block->{'trans_'.$key} = $value;
        }

        return $block;
    }
}