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/rentman.komma.pro/app/Komma/Updates/UpdateController.php
<?php

namespace Komma\Updates;

use Carbon\Carbon;
use Komma\Blocks\BlockService;
use Komma\Images\ImageService;
use Komma\LanguageService;
use Komma\Pages\PageService;

class UpdateController extends \BaseController
{
    public $data;
    protected $pageService;
    protected $imageService;
    protected $blockService;
    protected $updateService;
    public $languageService;

    public function __construct(PageService $pageService, ImageService $imageService, LanguageService $languageService, BlockService $blockService, UpdateService $updateService)
    {
        parent::__construct();

        $this->pageService = $pageService;
        $this->imageService = $imageService;
        $this->languageService = $languageService;
        $this->blockService = $blockService;
        $this->updateService = $updateService;
        $this->data = (object)[];
    }

    public function show($id = 2)
    {
        $this->data = $this->updateService->getUpdate($id, $this->languageService->getCurrentLanguageId());
        $this->languageService->checkRouteWithSetLanguage();
        $this->data->parent = $this->pageService->getPageByCodeName('timeline');
        $this->data->links = $this->pageService->getAllRoutes();

        if(!$this->data->active && !$this->data->preview) \App::abort(404);

//        var_dump($this->data->translation->active);

        $this->data->content = (object)['code_name' => $this->data->code_name];

        $otherLanguages = $this->updateService->getOtherLanguageRoutes($this->data->rentmanUpdate->id);

        $updates = $this->updateService->getLatestUpdates(1000, $this->languageService->getCurrentLanguageId());

        return \View::make('layouts.pages.timeline.show')
            ->with('data', $this->data)
            ->with('updates', $updates)
            ->with('otherLanguages', $otherLanguages->allTranslations);
    }

    public function index()
    {
        $page = $this->pageService->getPageByCodeName('timeline');
        $otherLanguages = $this->pageService->getOtherLanguageRoutes($page->id);
        $this->data->content = $page;
        $this->data->id = $this->data->content->id;
        $this->data->links = $this->pageService->getAllRoutes();

        // Use the home block for generating the features row
        $page->blocks = $this->blockService->getBlocksWhere('type', 'home');
        $page->blocks = $page->blocks->keyBy('code_name');

        $updates = $this->updateService->getLatestUpdates(10, $this->languageService->getCurrentLanguageId());

        $year = Carbon::now()->year;


        return \View::make('layouts.pages.timeline.index')
            ->with('data', $this->data)
            ->with('blocks', $page->blocks)
            ->with('updates', $updates)
            ->with('year', $year)
            ->with('otherLanguages', $otherLanguages->allTranslations);


    }

    public function getMoreUpdates($start){
        $amount = 5;
        $updatesCount = $this->updateService->getUpdatesCount($this->languageService->getCurrentLanguageId());
        $updatesLeft = $updatesCount-$start-$amount;
        $updates = $this->updateService->getMoreUpdates($start, $amount, $this->languageService->getCurrentLanguageId());
        $updates = $updates->map(function ($update) {

            $date = Carbon::parse($update->date);
            $update['year'] = $date->year;
            $update['route'] = $update->route->route;
            $update['fancyDate'] = $date->day . ' ' . $date->format('F');

            if(isset($update->rentmanUpdate->images) && $update->rentmanUpdate->images->count() != 0) {
                $update['large_image_url'] = $update->rentmanUpdate->images->first()->large_image_url;
                $update['medium_image_url'] = $update->rentmanUpdate->images->first()->medium_image_url;
            }

            return $update;
        });
        return \Response::json(array('updates' => $updates, 'updatesLeft' => $updatesLeft));
    }
}