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/zelfverkopen.komma.pro/app/KommaApp/Properties/PropertyController.php
<?php

namespace App\KommaApp\Properties;

use App\Http\Controllers\Controller;
use App\KommaApp\Properties\Models\Property;

class PropertyController extends Controller
{
    private $pagePrefix = 'pages.properties.';
    private $propertyService;

    public function __construct(PropertyService $propertyService)
    {
        parent::__construct();
        $this->propertyService = $propertyService;
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function index()
    {
        $page = $this->pageService->getPageByCodeName('properties');
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
        $page->translation = $this->decodeDynamicContent($page->translation);

        $filters = $this->getUrlFilters();

        if (sizeof($filters) === 0) {
            $properties = $this->propertyService->getProperties();
            $page->filtered = false;
        }else {
            $properties = $this->propertyService->getPropertiesWithFilters($filters);
            $page->filtered = true;
        }

        $properties->withPath('/' . $this->links->properties->route);

        if (sizeof($filters) !== 0) {

            foreach ($filters as $urlFilter => $urlFilterValue){
                $properties->appends([trans('site/properties.'.$urlFilter.'Key') => $urlFilterValue]);
            }
        }


//        $properties = $this->getMyDummyContent();

        // Return view
        return \View::make($this->baseViewPath . $this->pagePrefix . 'index', [
            'page'           => $page,
            'links'          => $this->links,
            'otherLanguages' => $otherLanguageRoutes,
            'priceOptions'   => $this->propertyService->getPropertyPriceFilters(),
            'properties'     => $properties,
        ]);
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function show($objectId)
    {

        $property = $this->propertyService->getProperty($objectId);
//        dd($this->propertyService->getProperty($objectId));
//        $property = $this->getMyDummyContent()[0];

        $page = $this->pageService->getPageByCodeName('properties');
        $page->translation = $this->decodeDynamicContent($page->translation);

        // Get the route in other languages for menu and meta title
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);

        $page->code_name = 'property-detail';

        // Return view
        return \View::make($this->baseViewPath . $this->pagePrefix . 'show', [
            'page'           => $page,
            'property'       => $property,
            'links'          => $this->links,
            'otherLanguages' => $otherLanguageRoutes,
        ]);
    }

    public function planVisit($objectId) { return $this->showForm($objectId, 'planVisit');}
    public function placeOrder($objectId) { return $this->showForm($objectId, 'placeOrder');}
    public function askQuestion($objectId) { return $this->showForm($objectId, 'askQuestion');}


    protected function showForm($objectId, $formType){
        $property = $this->propertyService->getProperty($objectId);

        $page = $this->pageService->getPageByCodeName('properties');
        $page->translation = $this->decodeDynamicContent($page->translation);

        // Get the route in other languages for menu and meta title
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);

        $page->code_name = 'property-form';

        // Return view
        return \View::make($this->baseViewPath . $this->pagePrefix . 'form', [
            'page'           => $page,
            'property'       => $property,
            'formType'           => $formType,
            'pageName'       => trans('site/properties.pages.'.$formType),
            'links'          => $this->links,
            'otherLanguages' => $otherLanguageRoutes,
        ]);

    }


    /**
     * Get the filter from the url
     *
     * @return array
     */
    private function getUrlFilters()
    {
        // Try to get the available filter from the input
        $availableFilters = [
            'location'     => \Input::get(trans('site/properties.locationKey'), null),
            'minimumPrice' => \Input::get(trans('site/properties.minimumPriceKey'), null),
            'maximumPrice' => \Input::get(trans('site/properties.maximumPriceKey'), null),
        ];

        // Only add filters where the input is not null
        $filters = [];
        foreach ($availableFilters as $filter => $value) {
            if (isset($value)) {
                $filters[$filter] = $value;
            }
        }

        return $filters;
    }

    private function getMyDummyContent()
    {

        return [
            (object)[
                'location'       => 'Amsterdam',
                'street'         => 'Aronskelkstraat 1',
                'price'          => '960000',
                'price_formated' => '€ 960.000',
                'type'           => 'Appartement',
                'sort'           => 'Eengezinswoning',
                'img'            => '/img/test/house2.jpg',
                'images'         => [
                    '/img/test/house5.jpg',
                    '/img/test/house4.jpg',
                    '/img/test/house3.jpg',
                    '/img/test/house6.jpg',
                    '/img/test/house6.jpg',
                    '/img/test/house6.jpg',
                    '/img/test/house6.jpg',
                ],
                'buildYear'      => 1989,
                'rooms'          => 4,
                'space'          => 909,
                'lon'            => 51.2617581,
                'lat'            => 5.5987423,
                'description'    => 'Te koop: 1 garagebox nabij het centrum en winkelcentrum Geesterduin.&#xd;
                &#xd;
                Onder flatgebouw "De Weere" wordt deze garagebox aangeboden.&#xd;
                &#xd;
                De servicekosten bedragen ca. EUR 8,- per maand. &#xd;
                &#xd;
                In de servicekosten is onderhoud en schilderwerk van de garage en garagedeur inbegrepen.'
            ],
            (object)[
                'location' => 'Amsterdam',
                'price'    => '1.200.000',
                'type'     => 'Galerie',
                'img'      => '/img/test/house1.jpg'
            ],
            (object)[
                'location' => 'Amsterdam',
                'price'    => '800.000',
                'type'     => 'Bovenwoning',
                'img'      => '/img/test/house3.jpg'
            ],
            (object)[
                'location' => 'Amsterdam',
                'price'    => '960.000',
                'type'     => 'Appartement',
                'img'      => '/img/test/house4.jpg'
            ],
            (object)[
                'location' => 'Amsterdam',
                'price'    => '1.200.000',
                'type'     => 'Galerie',
                'img'      => '/img/test/house5.jpg'
            ],
            (object)[
                'location' => 'Amsterdam',
                'price'    => '800.000',
                'type'     => 'Bovenwoning',
                'img'      => '/img/test/house6.jpg'
            ]
        ];

    }

}