File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/workbench/komma/kms/src/Komma/Kms/Core/Kms.php
<?php
/**
* Short description for the file.
*
* @author Jaap Faes <jaap@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Kms\Core;
use Illuminate\Routing\Router;
use Komma\Kms\Shops\ShopsRepository;
class Kms
{
protected $shop;
protected $router;
protected $shopsRepository;
protected $shops;
protected $shopLanguages = [];
protected $shopsIndex = [];
protected $shopLanguageIdIndex;
protected $shopLanguageIndex;
function __construct(Router $router, ShopsRepository $shopsRepository)
{
$this->router = $router;
$this->shopsRepository = $shopsRepository;
$shopSlug = $this->router->current()->getParameter('shop');
$this->shop = $this->shopsRepository->findBySlug($shopSlug);
}
public function getDefaultLanguageId()
{
if($this->shop) {
return $this->shop->default_language_id;
}
return \Config::get('kms::main.defaultLanguageId');
}
public function getShopDefaultLanguageId($shopId)
{
return $this->getShop($shopId)->default_language_id;
}
public function getDefaultLanguage()
{
return $this->getCurrentShopLanguages()->find($this->getDefaultLanguageId());
}
public function getCurrentShopId()
{
if($this->shop) {
return $this->shop->id;
}
return null;
}
public function getCurrentShopSlug()
{
if($this->shop) {
return $this->shop->slug;
}
return null;
}
public function getShops()
{
if(! $this->shops)
$this->shops = $this->shopsRepository->findAll()->keyBy('id');
return $this->shops;
}
public function getShop($shopId)
{
if(! isset($this->shopsIndex[$shopId]))
$this->shopsIndex[$shopId] = $this->shopsRepository->find($shopId);
return $this->shopsIndex[$shopId];
}
public function getCurrentShopLanguages()
{
if(!$this->shop) return false;
return $this->getShopLanguages($this->shop->id);
}
public function getCurrentShopLanguageIds()
{
return $this->getShopLanguageIds($this->shop->id);
}
public function getShopLanguageIds($shopId)
{
if(!isset($this->shopLanguageIdIndex[$shopId])) {
$this->shopLanguageIdIndex[$shopId] = \DB::table('shop_language')->where('shop_id', $shopId)->lists('language_id');
}
return $this->shopLanguageIdIndex[$shopId];
}
public function getShopLanguages($shopId)
{
if(!isset($this->shopLanguageIndex[$shopId])) {
$this->shopLanguageIndex[$shopId] = \DB::table('shop_language')
->join('languages', 'languages.id', '=', 'shop_language.language_id')
->where('shop_language.shop_id', $shopId)
->get();
}
return $this->shopLanguageIndex[$shopId];
}
}