FEATURE: move bussiness logic out of models

This commit is contained in:
Michal Kváček
2016-10-17 01:05:20 +02:00
parent 2ded2924a1
commit e26e6fd460
46 changed files with 1069 additions and 1039 deletions
+2 -78
View File
@@ -7,85 +7,9 @@ use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class Settings extends Model
{
use ModelTraits\Settings;
protected $table = 'settings';
public $timestamps = false;
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', 'ASC');
}
/**
* Load all settings
*
* @return \stdClass
*/
public function getAll()
{
$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
*
* @return \stdClass
*/
public function getForView()
{
$settings = $this->getSettingsQuery()
->where('load_into_views', 1)
->get();
return $this->returnPairs($settings);
}
/**
* From pair <key, value> create object key => value
*
* @param $settings
*
* @return \stdClass
*/
private function returnPairs($settings)
{
$data = new \stdClass();
foreach ($settings as $conf) {
$data->{$conf->key} = $conf->value;
}
return $data;
}
}