Commit 8e0e5b01 authored by Nicolas Widart's avatar Nicolas Widart

Showing the basic module settings form

parent 55fba3d6
......@@ -46,9 +46,11 @@ class SettingController extends AdminBaseController
public function getModuleSettings($module)
{
$moduleWithSettings = $this->setting->moduleSettings($module);
$moduleSettings = $this->setting->moduleSettings($module);
return View::make('setting::admin.module-settings', compact('module'));
$settings = $this->setting->savedModuleSettings($module);
return View::make('setting::admin.module-settings', compact('module', 'moduleSettings', 'settings'));
}
public function postModuleSettings($module)
......
......@@ -3,7 +3,6 @@
use Illuminate\Support\Facades\Config;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Setting\Repositories\SettingRepository;
use Pingpong\Modules\Module;
class EloquentSettingRepository extends EloquentBaseRepository implements SettingRepository
{
......@@ -53,7 +52,8 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
foreach ($settings as $settingName => $settingValues) {
// Check if setting exists
if ($setting = $this->findByName($settingName)) {
$this->updateSetting($setting, $settingValues); continue;
$this->updateSetting($setting, $settingValues);
continue;
}
$this->createForName($settingName, $settingValues);
}
......@@ -75,10 +75,12 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
*/
public function findByName($settingName)
{
return $this->model->whereHas('translations', function($q) use($settingName)
{
return $this->model->whereHas(
'translations',
function ($q) use ($settingName) {
$q->where('name', $settingName);
})->first();
}
)->first();
}
/**
......@@ -126,6 +128,10 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
*/
public function moduleSettings($modules)
{
if (is_string($modules)) {
return Config::get(strtolower($modules) . "::settings");
}
$modulesWithSettings = [];
foreach ($modules as $module) {
if ($moduleSettings = Config::get(strtolower($module) . "::settings")) {
......@@ -135,4 +141,24 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
return $modulesWithSettings;
}
/**
* Return the saved module settings
* @param $module
* @return mixed
*/
public function savedModuleSettings($module)
{
return $this->findByModule($module);
}
/**
* Find settings by module name
* @param string $module Module name
* @return mixed
*/
private function findByModule($module)
{
return $this->model->where('name', "$module%")->get();
}
}
......@@ -25,4 +25,11 @@ interface SettingRepository extends BaseRepository
* @return array
*/
public function moduleSettings($modules);
/**
* Return the saved module settings
* @param $module
* @return mixed
*/
public function savedModuleSettings($module);
}
......@@ -25,10 +25,10 @@
</ul>
<div class="tab-content">
<div class="tab-pane {{ App::getLocale() == 'en' ? 'active' : '' }}" id="tab_1-1">
@include('setting::admin.partials.fields', ['lang' => 'en'])
@include('setting::admin.partials.module-fields', ['lang' => 'en', 'moduleSettings' => $moduleSettings, 'settings' => $settings])
</div>
<div class="tab-pane {{ App::getLocale() == 'fr' ? 'active' : '' }}" id="tab_2-2">
@include('setting::admin.partials.fields', ['lang' => 'fr'])
@include('setting::admin.partials.module-fields', ['lang' => 'fr', 'moduleSettings' => $moduleSettings, 'settings' => $settings])
</div>
</div>
</div>
......
<?php foreach($moduleSettings as $setting => $description): ?>
<div class='form-group'>
{!! Form::label($setting . "[$lang]", $description) !!}
<?php if (count($settings) >= 1): ?>
{!! Form::text($setting . "[$lang]", Input::old($setting . "[$lang]", $settings[$setting]->translate($lang)->value), ['class' => 'form-control', 'placeholder' => $description]) !!}
<?php else: ?>
{!! Form::text($setting . "[$lang]", Input::old($setting . "[$lang]"), ['class' => 'form-control', 'placeholder' => $description]) !!}
<?php endif; ?>
</div>
<?php endforeach; ?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment