Commit 499751b0 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/Setting/' changes from 0f32e1e..20d1cdb

20d1cdb Fixing setting button
efdb7b1 Adding code climate badge
d92e54b Removing unused commented code
48ffe70 Typehinting the router
eca1944 Adding sensiolab config file
abf120c Using new escaping tags
8625dd4 Remove flash msg partial
9837f5c Adding travis config
5851df9 Caching the settings getter
0f5bd46 Removing duplication
417c966 Sending the fieldname

git-subtree-dir: Modules/Setting
git-subtree-split: 20d1cdb3d658f785e17d51836fc26757c4078b32
parent 3d625a2e
rules:
php.interface_has_no_interface_suffix:
enabled: false
language: php
php:
- 5.6
- 5.5
- 5.4
- hhvm
...@@ -3,18 +3,17 @@ ...@@ -3,18 +3,17 @@
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class SettingDatabaseSeeder extends Seeder { class SettingDatabaseSeeder extends Seeder
{
/** /**
* Run the database seeds. * Run the database seeds.
* *
* @return void * @return void
*/ */
public function run() public function run()
{ {
Model::unguard(); Model::unguard();
}
// $this->call("OthersTableSeeder");
}
} }
<?php <?php
$router->group(['prefix' => LaravelLocalization::setLocale(), 'before' => 'LaravelLocalizationRedirectFilter|auth.admin'], function($router) { use Illuminate\Routing\Router;
$router->group(['prefix' => Config::get('core::core.admin-prefix'), 'namespace' => 'Modules\Setting\Http\Controllers'], function($router)
$router->group(['prefix' => LaravelLocalization::setLocale(), 'before' => 'LaravelLocalizationRedirectFilter|auth.admin'], function(Router $router) {
$router->group(['prefix' => Config::get('core::core.admin-prefix'), 'namespace' => 'Modules\Setting\Http\Controllers'], function(Router $router)
{ {
$router->get('settings/{module}', ['as' => 'dashboard.module.settings', 'uses' => 'Admin\SettingController@getModuleSettings']); $router->get('settings/{module}', ['as' => 'dashboard.module.settings', 'uses' => 'Admin\SettingController@getModuleSettings']);
$router->resource('settings', 'Admin\SettingController', ['except' => ['show', 'edit', 'update', 'destroy', 'create'], 'names' => [ $router->resource('settings', 'Admin\SettingController', ['except' => ['show', 'edit', 'update', 'destroy', 'create'], 'names' => [
......
...@@ -28,7 +28,7 @@ class SettingServiceProvider extends ServiceProvider { ...@@ -28,7 +28,7 @@ class SettingServiceProvider extends ServiceProvider {
$this->app['setting.settings'] = $this->app->share(function($app) $this->app['setting.settings'] = $this->app->share(function($app)
{ {
return new Settings($app['Modules\Setting\Repositories\SettingRepository']); return new Settings($app['Modules\Setting\Repositories\SettingRepository'], $app['cache']);
}); });
$this->app->booting(function() $this->app->booting(function()
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class="checkbox"> <div class="checkbox">
<label for="{{ $settingName }}"> <label for="{{ $settingName }}">
<input id="{{ $settingName }}" <input id="{{ $settingName }}"
name="{{ $settingName }}" name="{{ $settingName }}"
type="checkbox" type="checkbox"
class="flat-blue" class="flat-blue"
{{ isset($dbSettings[$settingName]) && (bool)$dbSettings[$settingName]->value == true ? 'checked' : '' }} {{ isset($dbSettings[$settingName]) && (bool)$dbSettings[$settingName]->plainValue == true ? 'checked' : '' }}
value="1" /> value="1" />
{{ $moduleInfo['description'] }} {{ $moduleInfo['description'] }}
</label> </label>
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class='form-group'> <div class='form-group'>
{!! Form::label($settingName, $moduleInfo['description']) !!} {!! Form::label($settingName, $moduleInfo['description']) !!}
<?php if (isset($dbSettings[$settingName])): ?> <?php if (isset($dbSettings[$settingName])): ?>
{!! Form::input('number', $settingName, Input::old($settingName, $dbSettings[$settingName]->translate($lang)->value), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!} {!! Form::input('number', $settingName, Input::old($settingName, $dbSettings[$settingName]->plainValue), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!}
<?php else: ?> <?php else: ?>
{!! Form::input('number', $settingName, Input::old($settingName), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!} {!! Form::input('number', $settingName, Input::old($settingName), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!}
<?php endif; ?> <?php endif; ?>
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class="checkbox"> <div class="checkbox">
<?php foreach($moduleInfo['options'] as $value => $optionName): ?> <?php foreach($moduleInfo['options'] as $value => $optionName): ?>
<label for="{{ $optionName }}"> <label for="{{ $optionName }}">
...@@ -6,7 +5,7 @@ ...@@ -6,7 +5,7 @@
name="{{ $settingName }}" name="{{ $settingName }}"
type="radio" type="radio"
class="flat-blue" class="flat-blue"
{{ isset($dbSettings[$settingName]) && (bool)$dbSettings[$settingName]->value == $value ? 'checked' : '' }} {{ isset($dbSettings[$settingName]) && (bool)$dbSettings[$settingName]->plainValue == $value ? 'checked' : '' }}
value="{{ $value }}" /> value="{{ $value }}" />
{{ $optionName }} {{ $optionName }}
</label> </label>
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class='form-group'> <div class='form-group'>
{!! Form::label($settingName, $moduleInfo['description']) !!} {!! Form::label($settingName, $moduleInfo['description']) !!}
<?php if (isset($dbSettings[$settingName])): ?> <?php if (isset($dbSettings[$settingName])): ?>
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class='form-group'> <div class='form-group'>
{!! Form::label($settingName", $moduleInfo['description']) !!} {!! Form::label($settingName, $moduleInfo['description']) !!}
<?php if (isset($dbSettings[$settingName])): ?> <?php if (isset($dbSettings[$settingName])): ?>
{!! Form::textarea($settingName", Input::old($settingName", $dbSettings[$settingName]->translate($lang)->value), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!} {!! Form::textarea($settingName, Input::old($settingName, $dbSettings[$settingName]->plainValue), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!}
<?php else: ?> <?php else: ?>
{!! Form::textarea($settingName", Input::old($settingName"), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!} {!! Form::textarea($settingName, Input::old($settingName), ['class' => 'form-control', 'placeholder' => $moduleInfo['description']]) !!}
<?php endif; ?> <?php endif; ?>
</div> </div>
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class="checkbox"> <div class="checkbox">
<label for="{{ $settingName . "[$lang]" }}"> <label for="{{ $settingName . "[$lang]" }}">
<input id="{{ $settingName . "[$lang]" }}" <input id="{{ $settingName . "[$lang]" }}"
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class='form-group'> <div class='form-group'>
{!! Form::label($settingName . "[$lang]", $moduleInfo['description']) !!} {!! Form::label($settingName . "[$lang]", $moduleInfo['description']) !!}
<?php if (isset($dbSettings[$settingName])): ?> <?php if (isset($dbSettings[$settingName])): ?>
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class="checkbox"> <div class="checkbox">
<?php foreach($moduleInfo['options'] as $value => $optionName): ?> <?php foreach($moduleInfo['options'] as $value => $optionName): ?>
<label for="{{ $optionName . "[$lang]" }}"> <label for="{{ $optionName . "[$lang]" }}">
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class='form-group'> <div class='form-group'>
{!! Form::label($settingName . "[$lang]", $moduleInfo['description']) !!} {!! Form::label($settingName . "[$lang]", $moduleInfo['description']) !!}
<?php if (isset($dbSettings[$settingName])): ?> <?php if (isset($dbSettings[$settingName])): ?>
......
<?php $settingName = strtolower($currentModule) . '::' . $setting; ?>
<div class='form-group'> <div class='form-group'>
{!! Form::label($settingName . "[$lang]", $moduleInfo['description']) !!} {!! Form::label($settingName . "[$lang]", $moduleInfo['description']) !!}
<?php if (isset($dbSettings[$settingName])): ?> <?php if (isset($dbSettings[$settingName])): ?>
......
...@@ -12,11 +12,10 @@ ...@@ -12,11 +12,10 @@
@stop @stop
@section('styles') @section('styles')
<link href="{{{ Module::asset('core', 'css/vendor/iCheck/flat/blue.css') }}}" rel="stylesheet" type="text/css" /> <link href="{!! Module::asset('core', 'css/vendor/iCheck/flat/blue.css') !!}" rel="stylesheet" type="text/css" />
@stop @stop
@section('content') @section('content')
@include('flash::message')
{!! Form::open(['route' => ['dashboard.setting.store'], 'method' => 'post']) !!} {!! Form::open(['route' => ['dashboard.setting.store'], 'method' => 'post']) !!}
<div class="row"> <div class="row">
<div class="sidebar-nav col-sm-2"> <div class="sidebar-nav col-sm-2">
...@@ -83,7 +82,7 @@ ...@@ -83,7 +82,7 @@
</div> </div>
<?php endif; ?> <?php endif; ?>
<div class="box-footer"> <div class="box-footer">
<button type="submit" class="btn btn-primary btn-flat">{{ trans('core::core.button.create') }}</button> <button type="submit" class="btn btn-primary btn-flat">{{ trans('core::core.button.update') }}</button>
<a class="btn btn-danger pull-right btn-flat" href="{{ URL::route('dashboard.setting.index')}}"><i class="fa fa-times"></i> {{ trans('core::core.button.cancel') }}</a> <a class="btn btn-danger pull-right btn-flat" href="{{ URL::route('dashboard.setting.index')}}"><i class="fa fa-times"></i> {{ trans('core::core.button.cancel') }}</a>
</div> </div>
</div> </div>
......
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
'settings' => $settings, 'settings' => $settings,
'setting' => $settingName, 'setting' => $settingName,
'moduleInfo' => $moduleInfo, 'moduleInfo' => $moduleInfo,
'settingName' => strtolower($currentModule) . '::' . $settingName
]) ])
<?php endforeach; <?php endforeach;
<?php namespace Modules\Setting\Support; <?php namespace Modules\Setting\Support;
use Illuminate\Contracts\Cache\Repository;
use Modules\Core\Contracts\Setting; use Modules\Core\Contracts\Setting;
use Modules\Setting\Repositories\SettingRepository; use Modules\Setting\Repositories\SettingRepository;
...@@ -9,13 +10,19 @@ class Settings implements Setting ...@@ -9,13 +10,19 @@ class Settings implements Setting
* @var SettingRepository * @var SettingRepository
*/ */
private $setting; private $setting;
/**
* @var Repository
*/
private $cache;
/** /**
* @param SettingRepository $setting * @param SettingRepository $setting
* @param Repository $cache
*/ */
public function __construct(SettingRepository $setting) public function __construct(SettingRepository $setting, Repository $cache)
{ {
$this->setting = $setting; $this->setting = $setting;
$this->cache = $cache;
} }
/** /**
...@@ -27,7 +34,11 @@ class Settings implements Setting ...@@ -27,7 +34,11 @@ class Settings implements Setting
*/ */
public function get($name, $locale = null, $default = null) public function get($name, $locale = null, $default = null)
{ {
$setting = $this->setting->get($name); if (!$this->cache->has("setting.$name")) {
$setting = $this->setting->get($name);
$this->cache->put("setting.$name", $setting, '3600');
}
$setting = $this->cache->get("setting.$name");
if ($setting) { if ($setting) {
if ($setting->isTranslatable) { if ($setting->isTranslatable) {
......
...@@ -2,3 +2,4 @@ ...@@ -2,3 +2,4 @@
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/92d544b4-a3ca-4c2a-9ffd-0741c521cb14/mini.png)](https://insight.sensiolabs.com/projects/92d544b4-a3ca-4c2a-9ffd-0741c521cb14) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/92d544b4-a3ca-4c2a-9ffd-0741c521cb14/mini.png)](https://insight.sensiolabs.com/projects/92d544b4-a3ca-4c2a-9ffd-0741c521cb14)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nWidart-Modules/Setting/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nWidart-Modules/Setting/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nWidart-Modules/Setting/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nWidart-Modules/Setting/?branch=master)
[![Code Climate](https://codeclimate.com/github/nWidart-Modules/Setting/badges/gpa.svg)](https://codeclimate.com/github/nWidart-Modules/Setting)
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