File: D:/HostingSpaces/SBogers79/artofeinstein.be/app/Komma/Pages/PageRepository.php
<?php
namespace Komma\Pages;
use Illuminate\Support\Facades\DB;
use Komma\Kms\Images\Models\Image;
use Komma\Kms\Locations\Models\Location;
class PageRepository
{
/**
* Return all pages
*
* @param array $in
* @param array $with
* @return mixed
*/
public function pages($in = [])
{
// Get pages with translations and routes
$pages = \DB::table('pages')
->leftJoin(
'page_translations',
'page_translations.page_id', '=', 'pages.id')
->leftJoin('routes', function ($join)
{
$join->on('page_translations.id', '=', 'routes.routable_id')
->where('routes.routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation');
})
->select('page_translations.name', 'routes.route', 'pages.id', 'pages.code_name')
->orderBy('pages.lft', 'asc');
// Get a selection
if( ! empty($in))
{
$pages = $pages->whereIn('pages.code_name', $in);
}
return $pages->get();
}
/**
* Get page content
*
* @param $id
* @return array
*/
public function getPageContent($id)
{
// Get page content
return $page = \DB::table('pages')
->leftJoin(
'page_translations',
'page_translations.page_id', '=', 'pages.id')
->where('pages.id', '=', $id)
->select('page_translations.*', 'pages.code_name')
->first();
}
public function getUrl($code_name)
{
// Get pages with translations and routes
$url = \DB::table('pages')
->leftJoin(
'page_translations',
'page_translations.page_id', '=', 'pages.id')
->leftJoin('routes', function ($join)
{
$join->on('page_translations.id', '=', 'routes.routable_id')
->where('routes.routable_type', '=', 'Komma\Kms\Pages\Models\PageTranslation');
})
->select('routes.route', 'page_translations.name', 'pages.code_name');
if(is_array($code_name))
{
$url = $url->whereIn('pages.code_name', $code_name);
return $url->get();
}
else
{
$url = $url->where('pages.code_name', '=', $code_name);
return $url->first();
}
}
public function getTextBlocks($language = 104)
{
return $text = \DB::table('text')
->leftJoin(
'text_translations',
'text_translations.text_id', '=', 'text.id')
->where('text_translations.language_id', '=', $language)
->select('text.id', 'text.code_name', 'text_translations.name', 'text_translations.description', 'text.lft', 'text.rgt')
->orderBy('text.lft', 'asc')
->get();
}
public function getRoomImages()
{
$images = Image::where('imageble_type', '=', 'Komma\Kms\Text\Models\Text')
->orderBy('sort_order', 'ASC')
->get();
$images = $images->groupBy('imageble_id');
return $images;
}
public function getLocations($language = 104){
$locations = Location::leftJoin('location_translations', 'location_translations.location_id', '=', 'locations.id')
// ->leftJoin('images', function($join)
// {
// $join->on('images.imageble_id', '=', 'locations.id')
// ->where('images.imageble_type', '=', 'Komma\Kms\Locations\Models\Location');
// })
->where('location_translations.language_id', '=', $language)
->where('locations.lft', '!=', 1)
->select('locations.code_name', 'location_translations.*')
->orderBy('locations.lft', 'ASC')
->get();
return $locations;
}
public function getLocationImages($locationId = null) {
$images = Image::where('imageble_type', '=', 'Komma\Kms\Locations\Models\Location')
->where('imageble_id', '=', $locationId)->get();
return $images;
}
}