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/SBogers110/franciscaansebeweging.nl/app/Komma/Mirrortents/MirrortentService.php
<?php

/**
 * Short description for the file.
 *
 * @author      Komma <support@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace Komma\Mirrortents;

use Carbon\Carbon;
use Komma\Kms\Languages\Language;
use Komma\Mirrortents\Models\Mirrortent;

class MirrortentService
{

    private $today;

    public function __construct()
    {
        $this->today = Carbon::now()->addHour();
        //Detect daylight saving time
        if(Carbon::now()->format('I') == 0) $this->today->addHour();
        $this->today = $this->today->format('Y-m-d H:i:s');
    }

    public function getAllMirrortents($pagination = false, $itemsPerPage = 9, $ids = null, $onlyHighlighted = false)
    {

//        $mirrortents = Mirrortent::where('lft', '!=', 1)
//            ->with('translation')
//            ->with('translation.route')
//            ->with('images')
//            ->where('active', '=', 1)
//            ->where('date', '<=', $this->today);
//
//        $mirrortents->orderBy('date', 'desc');

        // Get pages with translations and routes

        $mirrortents = \DB::table('mirrortents')
            ->leftJoin('mirrortent_translations', function ($join)
            {
                $join->on('mirrortent_translations.mirrortent_id', '=', 'mirrortents.id')
                    ->where('language_id', '=', Language::where('languages.iso_2', '=', \App::getLocale())->first()->id);

            })
            ->where('languages.iso_2', '=', \App::getLocale())
            ->join('languages', 'languages.id', '=', 'mirrortent_translations.language_id')
            ->leftJoin('images', function ($join)
            {
                $join->on('images.imageble_id', '=', 'mirrortents.id')
                    ->where('images.imageble_type', '=', 'Komma\Kms\Mirrortents\Models\Mirrortent')
                    ->where('sort_order', '=', 1)
                    ->where('sort_order', '=', 1);
            })
            ->leftJoin('routes', function ($join)
            {
                $join->on('mirrortent_translations.id', '=', 'routes.routable_id')
                    ->where('routes.routable_type', '=', 'Komma\Kms\Mirrortents\Models\MirrortentTranslation');
            })
            ->select('mirrortents.*', 'mirrortent_translations.*', 'routes.route', 'images.medium_image_url')
            ->where('mirrortents.active', '=', 1);

        if($ids !== null)
        {
            $mirrortents = $mirrortents->whereIn('mirrortents.id', $ids);
        }

        if($onlyHighlighted === true){
            $mirrortents = $mirrortents->where('mirrortents.highlighted', 1);
        }

        if($pagination)
        {
            $mirrortents = $mirrortents->paginate($itemsPerPage);
        }
        else
        {
            $mirrortents = $mirrortents->get();
        }

        return $mirrortents;

    }

    public function getLatestMirrortents($items = 5)
    {

        $mirrortents = Mirrortent::with('translation')
            ->with('translation.route')
            ->where('active', '=', 1);

        $mirrortents->limit($items);
        $mirrortents = $mirrortents->get();

        return $mirrortents;

    }


    public function getMirrortent($id, $nextAndPrev = true)
    {
        if( ! $mirrortent = Mirrortent::where('id', '=', $id)
            ->with('translation')
            ->with('translation.route')
            ->with('images')
            ->where('active', '=', 1)
            ->first()
        ) return \App::abort(404, 'mirrortent not found');

        $this->fillMirrortent($mirrortent);

//        if($nextAndPrev) $nextAndPrev = $this->getNextAndPrevious($mirrortent);

        return $mirrortent;
    }

    public function fillMirrortent(Mirrortent &$mirrortent)
    {
//        $mirrortent->translation->meta_description = str_limit(strip_tags($mirrortent->translation->description, 155));

        //Comment the decode when there aren't dynamic blocks
        $mirrortent->translation->description = json_decode($mirrortent->translation->description);

    }


    public function getNextAndPrevious(&$mirrortent)
    {
        $previous = \DB::table('mirrortents')
            ->leftJoin('mirrortent_translations', function ($join)
            {
                $join->on('mirrortent_translations.mirrortent_id', '=', 'mirrortents.id')
                    ->where('language_id', '=', Language::where('languages.iso_2', '=', \App::getLocale())->first()->id);

            })
            ->where('languages.iso_2', '=', \App::getLocale())
            ->join('languages', 'languages.id', '=', 'mirrortent_translations.language_id')
            ->leftJoin('routes', function ($join)
            {
                $join->on('mirrortent_translations.id', '=', 'routes.routable_id')
                    ->where('routes.routable_type', '=', 'Komma\Kms\Mirrortents\Models\MirrortentTranslation');
            })
            ->leftJoin('images', function ($join)
            {
                $join->on('images.imageble_id', '=', 'mirrortents.id')
                    ->where('images.imageble_type', '=', 'Komma\Kms\Mirrortents\Models\Mirrortent')
                    ->where('sort_order', '=', 1);
            })
            ->select('mirrortents.*', 'mirrortent_translations.*', 'routes.route')
            ->where('mirrortents.active', '=', 1)
            ->where('mirrortents.id', '!=', $mirrortent->id)
            ->first();

        $next = \DB::table('mirrortents')
            ->leftJoin('mirrortent_translations', function ($join)
            {
                $join->on('mirrortent_translations.mirrortent_id', '=', 'mirrortents.id')
                    ->where('language_id', '=', Language::where('languages.iso_2', '=', \App::getLocale())->first()->id);

            })
            ->where('languages.iso_2', '=', \App::getLocale())
            ->join('languages', 'languages.id', '=', 'mirrortent_translations.language_id')
            ->leftJoin('routes', function ($join)
            {
                $join->on('mirrortent_translations.id', '=', 'routes.routable_id')
                    ->where('routes.routable_type', '=', 'Komma\Kms\Mirrortents\Models\MirrortentTranslation');
            })
            ->leftJoin('images', function ($join)
            {
                $join->on('images.imageble_id', '=', 'mirrortents.id')
                    ->where('images.imageble_type', '=', 'Komma\Kms\Mirrortents\Models\Mirrortent')
                    ->where('sort_order', '=', 1);
            })
            ->select('mirrortents.*', 'mirrortent_translations.*', 'routes.route')
            ->where('mirrortents.active', '=', 1)
            ->where('mirrortents.id', '!=', $mirrortent->id)
            ->first();

//        $previous = Mirrortent::where('date', '>', $activitie->date)->orderBy('date', 'asc')
//            ->with('translation')
//            ->with('translation.route')
//            ->with('images')
//            ->where('active', '=', 1)
//            ->where('date', '<=', $this->today)
//            ->where('id', '!=', $activitie->id)
//            ->first();
//        $next = Mirrortent::where('date', '<', $activitie->date)->orderBy('date', 'desc')
//            ->with('translation')
//            ->with('translation.route')
//            ->with('images')
//            ->where('active', '=', 1)
//            ->where('date', '<=', $this->today)
//            ->where('id', '!=', $activitie->id)
//            ->first();

        $mirrortent->next = $next;
        $mirrortent->previous = $previous;
    }

    /**
     * Convert activitie date to carbon
     *
     * @param $mirrortents
     */
    public function makeCarbonDate(&$mirrortents)
    {
        return;
    }

    /**
     * Convert for sorting
     *
     * @param $mirrortents
     */
    public function convertForSorting($mirrortents)
    {

        return $mirrortents;
    }

}