Merge branch 'multilanguage' into dev
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use App\Enumerations\ContentStatuses;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
/**
|
||||
* Class Content
|
||||
@@ -15,6 +16,7 @@ class Content extends Model
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'parent_id',
|
||||
'language',
|
||||
'module_handler',
|
||||
'published_from',
|
||||
'published_to',
|
||||
@@ -53,6 +55,7 @@ class Content extends Model
|
||||
public function getHomepage()
|
||||
{
|
||||
return $this->getPageQuery()
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->where('is_homepage', 1)
|
||||
->first();
|
||||
}
|
||||
@@ -68,6 +71,7 @@ class Content extends Model
|
||||
{
|
||||
return $this->getPageQuery()
|
||||
->where('url', $url)
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->first();
|
||||
}
|
||||
|
||||
@@ -81,6 +85,7 @@ class Content extends Model
|
||||
if (!$this->subpagesInit) {
|
||||
$this->subpages = $this->getPageQuery()
|
||||
->where('parent_id', $this->id)
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->get();
|
||||
|
||||
// convert JSON settings into stdClass
|
||||
@@ -142,6 +147,7 @@ class Content extends Model
|
||||
public function rootPages()
|
||||
{
|
||||
$rootPages = $this->getPageQuery()
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->where('parent_id', null);
|
||||
|
||||
if ($this->id) {
|
||||
@@ -166,6 +172,7 @@ class Content extends Model
|
||||
$query = DB::table('contents')
|
||||
->select('contents.*', 'modules.name AS module_name')
|
||||
->where('contents.status', '<>', self::STATUS_DELETED)
|
||||
->where('contents.language', LaravelLocalization::getCurrentLocale())
|
||||
->join('modules', 'modules.handler', '=', 'contents.module_handler')
|
||||
->orderBy('created_at', 'DESC');
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Language extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
public $primaryKey = 'code';
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'script',
|
||||
'native'
|
||||
];
|
||||
protected $guarded = [];
|
||||
}
|
||||
+41
-6
@@ -3,12 +3,26 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
class Settings extends Model
|
||||
{
|
||||
protected $table = 'settings';
|
||||
public $timestamps = false;
|
||||
protected $fillable = ['key', 'value'];
|
||||
protected $fillable = ['key', 'value', 'language'];
|
||||
|
||||
/**
|
||||
* Prepares common query for selecting settings
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getSettingsQuery()
|
||||
{
|
||||
return Settings::select(['key', 'value', 'language'])
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->orWhere('language', null)
|
||||
->orderBy('language', 'DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all settings
|
||||
@@ -17,12 +31,33 @@ class Settings extends Model
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
$settings = Settings::select(['key', 'value'])
|
||||
->get();
|
||||
$settings = $this->getSettingsQuery()
|
||||
->get();
|
||||
|
||||
return $this->returnPairs($settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all settings with language info
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function getAllWithLanguage()
|
||||
{
|
||||
$settings = $this->getSettingsQuery()
|
||||
->get();
|
||||
|
||||
$data = new \stdClass();
|
||||
foreach ($settings as $conf) {
|
||||
$data->{$conf->key} = [
|
||||
'val' => $conf->value,
|
||||
'lang' => $conf->language
|
||||
];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load only config for views
|
||||
*
|
||||
@@ -30,9 +65,9 @@ class Settings extends Model
|
||||
*/
|
||||
public function getForView()
|
||||
{
|
||||
$settings = Settings::select(['key', 'value'])
|
||||
->where('load_into_views', 1)
|
||||
->get();
|
||||
$settings = $this->getSettingsQuery()
|
||||
->where('load_into_views', 1)
|
||||
->get();
|
||||
|
||||
return $this->returnPairs($settings);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
/**
|
||||
* Class Widget
|
||||
@@ -39,6 +40,7 @@ class Widget extends Model
|
||||
// create new widget
|
||||
$widget = new Widget();
|
||||
$widget->widget_type_handler = $widgetType->handler;
|
||||
$widget->language = LaravelLocalization::getCurrentLocale();
|
||||
$widget->user_id = \Auth::user()->id;
|
||||
$widget->name = $data->name;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
|
||||
/**
|
||||
* Class WidgetArea
|
||||
@@ -25,6 +26,7 @@ class WidgetArea extends Model
|
||||
->where('code', $uniqueCode)
|
||||
->join('widget_in_widget_area', 'widget_in_widget_area.widget_area_id', '=', 'widget_areas.id')
|
||||
->join('widgets', 'widget_in_widget_area.widget_id', '=', 'widgets.id')
|
||||
->where('language', LaravelLocalization::getCurrentLocale())
|
||||
->orderBy('widget_in_widget_area.position');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user