File: D:/HostingSpaces/SBogers84/zuiderbos.nl/app/Komma/Brochures/Models/Brochure.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Brochures\Models;
class Brochure extends \Komma\Kms\Brochures\Models\Brochure
{
public $kmsClass = 'Komma\\Kms\\Brochures\\Models\\Brochure';
/**
* Get the translation for the current language
*
* @return Collection
*/
public function translation()
{
/**
* On the translation model is an BelongsTo relation.
* We want to collect the current translation.
* Therefore we create a hasOne relation
* Where we will select the page_translation,
* Join on the languages table
* And set the current Locale as the languages.iso_2
*
*/
return $this->hasOne('Komma\Brochures\Models\BrochureTranslation')
//We only need the translation
->select('brochure_translations.*')
//Join the languages
->join('languages', 'languages.id', '=', 'brochure_translations.language_id')
//Get only the language with the correct lang
->where('languages.iso_2', '=', \App::getLocale());
}
/**
* Get all translations
*
* @return Collection
*/
public function allTranslations(){
return $this->hasMany('Komma\Brochures\Models\BrochureTranslation')
//Join the languages
->join('languages', 'languages.id', '=', 'brochure_translations.language_id')
->whereIn('languages.iso_2', \Config::get('app.availableLanguages'))
//We only need the translation and language iso
->select('brochure_translations.*', 'languages.iso_2')
->orderBy('languages.id');
}
public function files()
{
return $this->hasMany('Komma\Kms\Files\Model\File', 'fileable_id')
->where('fileable_type', '=', $this->kmsClass);
}
}