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/Shop/Pages/PageRepository.php
<?php


namespace KommaApp\Shop\Pages;

use Komma\Kms\Pages\Models\PageTranslation;
use KommaApp\Shop\Tree\Tree;

class PageRepository
{
    /**
     * @var PageTranslation
     */
    private $pageTranslation;
    /**
     * @var Tree
     */
    private $tree;

    /**
     * @param PageTranslation $pageTranslation
     */
    public function __construct(Tree $tree, PageTranslation $pageTranslation)
    {

        $this->pageTranslation = $pageTranslation;
        $this->tree = $tree;
    }

    /**
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function getCodeNameRoutes()
    {
        // Bind Languages and Routes
        return \DB::table('page_translations')
            ->join('pages', 'pages.id', '=', 'page_translations.page_id')
            ->join('routes', 'page_translations.id', '=', 'routes.routable_id')
            ->where('routes.routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation')
            ->where('page_translations.language_id', '=', \Shop::getLanguageService()->getCurrentLanguageId())
            ->where('pages.shop_id', '=', \Shop::getId())
            ->where('pages.active', 1)
            ->select(
                'pages.code_name as codeName',

                'page_translations.name',
                'page_translations.slug',
                'page_translations.page_id as id',

                'page_translations.meta_title as meta_title',
                'page_translations.meta_description as meta_description',

                'routes.route',
                'routes.routable_id'
            )
            ->get();
    }

    public function getPagesByIds(array $ids)
    {
        //If the id array is empty, we are not going to execute the query
        if(empty($ids)) return false;

        return \DB::table('page_translations')
            ->join('pages', 'pages.id', '=', 'page_translations.page_id')
            ->join('routes', 'page_translations.id', '=', 'routes.routable_id')
            ->where('routes.routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation')
            ->where('page_translations.language_id', '=', \Shop::getLanguageService()->getCurrentLanguageId())
            ->where('pages.shop_id', '=', \Shop::getId())
            ->whereIn('pages.id', $ids)
            ->where('pages.active', 1)
            ->select(
                'pages.code_name as codeName',

                'page_translations.name',
                'page_translations.slug',
                'page_translations.page_id as id',
                'page_translations.description',

                'page_translations.meta_title as meta_title',
                'page_translations.meta_description as meta_description',

                'routes.route',
                'routes.routable_id'
            )
            //This will put the fields in the order of the $ids array, these are sorted by rankink
            ->orderByRaw("FIELD(pages.id,".implode(',',$ids).")")
            ->get();
    }


    public function getPagesByIdsCompact(array $ids, $limit = -1)
    {
        //If the id array is empty, we are not going to execute the query
        if(empty($ids)) return false;

        return \DB::table('page_translations')
            ->join('pages', 'pages.id', '=', 'page_translations.page_id')
            ->join('routes', 'page_translations.id', '=', 'routes.routable_id')
            ->where('routes.routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation')
            ->where('page_translations.language_id', '=', \Shop::getLanguageService()->getCurrentLanguageId())
            ->where('pages.shop_id', '=', \Shop::getId())
            ->whereIn('pages.id', $ids)
            ->where('pages.active', 1)
            ->select(
                'page_translations.name',
                'routes.route'
                   )
            //This will put the fields in the order of the $ids array, these are sorted by rankink
            ->orderByRaw("FIELD(pages.id,".implode(',',$ids).")")
            ->take($limit)
            ->get();
    }

    public function getTreeNodes($abc = false)
    {
        $shopId = \Shop::getId();

        $root = \DB::table('pages')
            ->select('pages.lft', 'pages.rgt')
            ->where('pages.shop_id', '=', $shopId)
            ->where('pages.lft', '=', '1')
            ->first();

        // Bind Languages and Routes
        $pages = \DB::table('page_translations')
            ->join('pages', 'pages.id', '=', 'page_translations.page_id')
            ->join('routes', 'page_translations.id', '=', 'routes.routable_id')
            ->where('routes.routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation')
            ->where('page_translations.language_id', '=', \Shop::getLanguageService()->getCurrentLanguageId())
            ->where('pages.shop_id', '=', $shopId)
            ->orderBy('pages.lft', 'asc')
            ->select(
                'pages.lft',
                'pages.rgt',
                'pages.call_to_action',
                'pages.code_name',

                'page_translations.name',
                'page_translations.slug',
                'page_translations.page_id as id',
                'page_translations.id as page_translation_id',
                'page_translations.description',
                'page_translations.description_two',

                'page_translations.meta_title as meta_title',
                'page_translations.meta_description as meta_description',

                'routes.route',
                'routes.routable_id'
            )
            ->get();

        $tree = $this->tree->make($root, $pages);
        if ($abc) $tree = $this->tree->alphabetize($tree);

        return $tree;
    }

    public function getImagesByPageId($pageId)
    {
        return \DB::table('images')
            ->where('images.imageble_id', $pageId)
            ->where('images.imageble_type', 'Komma\Kms\Pages\Models\Page')
            ->select(
                'images.large_image_url',
                'images.small_image_url'
            )
            ->get();
    }

    public function search($searchWords)
    {
        $currentLanguageId = \Shop::getLanguageService()->getCurrentLanguageId();
        $currentShopId = \Shop::getId();

        $words = [];
        foreach ($searchWords as $word) {
            $words[] = '*' . $word . '*';
        }
        $searchQuery = implode(' ', $words);

        $result = \DB::table('pages')
            ->join('page_translations', function ($join) use ($currentLanguageId) {
                $join->on('pages.id', '=', 'page_translations.page_id')
                    ->where('page_translations.language_id', '=', $currentLanguageId);
            })
            ->join('routes', function ($join) {
                $join->on('page_translations.id', '=', 'routes.routable_id')
                    ->where('routes.routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation');
            })
            ->where('pages.shop_id', '=', $currentShopId)
            ->where('pages.active', 1)
            ->whereRaw('MATCH(page_translations.name, page_translations.description, page_translations.description_two) AGAINST(? IN BOOLEAN MODE)', [$searchQuery])
            ->select(
                'page_translations.name',
                'page_translations.slug',
                'page_translations.page_id as id',
                'page_translations.id as page_translation_id',
                'page_translations.description',
                'routes.route'
            );

        return $result->get();
    }
}