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/kemi.komma.pro/app/KommaApp/Machines/MachineService.php
<?php


namespace App\KommaApp\Machines;


use App\KommaApp\Machines\Models\Machine;
use App\KommaApp\Pages\Models\Page;
use Carbon\Carbon;

class MachineService
{

    public function getMachineTypes()
    {
        $productionPage = Page::where('code_name', 'production')->first();
        $productionPages = Page::where('lft', '>', $productionPage->lft)
            ->where('lft', '<', $productionPage->rgt)
            ->with('translation')
            ->where('active', 1)
            ->get();

        $machineTypes = [];
        foreach ($productionPages as $productionPage){
            $machineTypes[] = $productionPage->code_name;
        }

        return $machineTypes;
    }

    public function getFullMachineTypes()
    {
        $machineTypes = $this->getMachineTypes();

        // Manually add measure because it isn't a subpage of production
        $machineTypes[] = 'measure';

        $machines = [];
        foreach ($machineTypes as $machineType){

            $typeMachines = $this->getMachinesByType($machineType);

            if($typeMachines->count() != 0)
                $machines[$machineType] = ['title' => trans('site/machinepark.'.$machineType), 'machines' => $typeMachines];
        }

        return $machines;
    }


    public function getMachinesByType($type){

        $machines = Machine::where('active', '1')
            ->where('type', '=', $type)
            ->with('translation')
            ->has('translation')
            ->get();

        return $machines;
    }


}